cpstream.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Checkpoint Streamer by Emmet_
  2. With this script, you can create checkpoints around San Andreas!
  3. Basically, the nearest checkpoint is shown to you (because you can
  4. only show 1 checkpoint at a time).
  5. You can create checkpoints under OnGameModeInit using CreateCheckpoint.
  6. They are shown automatically. Enjoy!
  7. */
  8. #include <a_samp>
  9. #define MAX_CHECKPOINTS 50
  10. enum CP_DATA
  11. {
  12. Float:CheckpointX,
  13. Float:CheckpointY,
  14. Float:CheckpointZ,
  15. Float:CheckpointSize,
  16. CheckpointExists,
  17. CheckpointTimer
  18. };
  19. new CheckpointData[MAX_CHECKPOINTS + 1][CP_DATA];
  20. new CheckpointStreamed[MAX_PLAYERS];
  21. forward StreamCheckpoint(cpid);
  22. stock CreateCheckpoint(Float:cpx, Float:cpy, Float:cpz, Float:cpsize)
  23. {
  24. new
  25. checkpointid;
  26. for (new i = 1; i <= MAX_CHECKPOINTS; i ++)
  27. {
  28. if (CheckpointData[i][CheckpointExists] == 0)
  29. {
  30. checkpointid = i;
  31. break;
  32. }
  33. }
  34. if (checkpointid != 0)
  35. {
  36. CheckpointData[checkpointid][CheckpointX] = cpx;
  37. CheckpointData[checkpointid][CheckpointY] = cpy;
  38. CheckpointData[checkpointid][CheckpointZ] = cpz;
  39. CheckpointData[checkpointid][CheckpointSize] = cpsize;
  40. CheckpointData[checkpointid][CheckpointExists] = 1;
  41. CheckpointData[checkpointid][CheckpointTimer] = SetTimerEx("StreamCheckpoint", 200, true, "i", checkpointid);
  42. return checkpointid;
  43. }
  44. return 0;
  45. }
  46. stock DestroyCheckpoint(cpid)
  47. {
  48. if (CheckpointData[cpid][CheckpointExists])
  49. {
  50. for (new i = 0; i < MAX_PLAYERS; i ++)
  51. {
  52. if (CheckpointStreamed[i] > 0)
  53. {
  54. CheckpointStreamed[i] = 0;
  55. DisablePlayerCheckpoint(i);
  56. }
  57. }
  58. CheckpointData[cpid][CheckpointX] = 0.0;
  59. CheckpointData[cpid][CheckpointY] = 0.0;
  60. CheckpointData[cpid][CheckpointZ] = 0.0;
  61. CheckpointData[cpid][CheckpointSize] = 0.0;
  62. CheckpointData[cpid][CheckpointExists] = 0;
  63. KillTimer(CheckpointData[cpid][CheckpointTimer]);
  64. return 1;
  65. }
  66. return 0;
  67. }
  68. stock ShowPlayerCheckpoint(playerid, cpid)
  69. {
  70. if (IsPlayerConnected(playerid))
  71. {
  72. if (CheckpointData[cpid][CheckpointExists])
  73. {
  74. CheckpointStreamed[playerid] = cpid;
  75. SetPlayerCheckpoint(playerid, CheckpointData[cpid][CheckpointX], CheckpointData[cpid][CheckpointY], CheckpointData[cpid][CheckpointZ], CheckpointData[cpid][CheckpointSize]);
  76. return 1;
  77. }
  78. }
  79. return 0;
  80. }
  81. public StreamCheckpoint(cpid)
  82. {
  83. for (new i = 0; i < MAX_PLAYERS; i ++)
  84. {
  85. if (CheckpointData[cpid][CheckpointExists])
  86. {
  87. if (CheckpointStreamed[i] != cpid)
  88. {
  89. if (IsPlayerInRangeOfPoint(i, (CheckpointData[cpid][CheckpointSize] + 1.0), CheckpointData[cpid][CheckpointX], CheckpointData[cpid][CheckpointY], CheckpointData[cpid][CheckpointZ]))
  90. {
  91. ShowPlayerCheckpoint(i, cpid);
  92. }
  93. }
  94. }
  95. }
  96. return 1;
  97. }
  98. stock GetPlayerCheckpointID(playerid)
  99. return CheckpointStreamed[playerid];