1
0

CPLoader.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //////////////////////////////////////////////////
  2. //////////////////////////////////////////////////
  3. /// Matraka's Checkpoint Streamer ///
  4. /// ///
  5. /// Author: [MPA]matraka_IDG ///
  6. /// Contact: msn_matraka@gtabrasil.net ///
  7. /// ///
  8. /// ---===Infernus Development Group===--- ///
  9. //////////////////////////////////////////////////
  10. //////////////////////////////////////////////////
  11. #include <a_samp>
  12. /*Natives
  13. native CPS_AddCheckpoint(Float:X,Float:Y,Float:Z,Float:size,Float:spawn_dist);
  14. native CPS_IsPlayerInCheckpoint(playerid,cpid);
  15. native CPS_IsPlayerInAnyCheckpoint(playerid,cpid);
  16. native CPS_RemoveCheckpoint(cpid);
  17. native CPS_GetPlayerCheckpoint(playerid);
  18. */
  19. #define MAX_CHECKPOINTS 500
  20. forward CPSERVICE_Handler();
  21. enum cpinfo
  22. {
  23. Float:cpX,
  24. Float:cpY,
  25. Float:cpZ,
  26. Float:cpsz,
  27. cpsd,
  28. };
  29. new CPSERVICE_active;
  30. new Checkpoints[MAX_CHECKPOINTS][cpinfo];
  31. new UsedCPSlot[MAX_CHECKPOINTS];
  32. new CPSERVICE_actualcp[MAX_PLAYERS];
  33. stock CPS_AddCheckpoint(Float:X,Float:Y,Float:Z,Float:size,spawn_dist)
  34. {
  35. new cpid=1;
  36. while(UsedCPSlot[cpid] == 1) cpid++;
  37. if(CPSERVICE_active == 0){
  38. SetTimer("CPSERVICE_Handler",500,true);
  39. CPSERVICE_active=1;
  40. }
  41. UsedCPSlot[cpid]=1;
  42. Checkpoints[cpid][cpX]=X;
  43. Checkpoints[cpid][cpY]=Y;
  44. Checkpoints[cpid][cpZ]=Z;
  45. Checkpoints[cpid][cpsz]=size;
  46. Checkpoints[cpid][cpsd]=spawn_dist;
  47. return cpid;
  48. }
  49. stock CPS_IsPlayerInCheckpoint(playerid,cpid)
  50. {
  51. if(!IsPlayerInCheckpoint(playerid)) return 0;
  52. if(CPSERVICE_actualcp[playerid] == cpid) return 1;
  53. else return 0;
  54. }
  55. stock CPS_IsPlayerInAnyCheckpoint(playerid)
  56. {
  57. if(!IsPlayerInCheckpoint(playerid)) return 0;
  58. if(CPSERVICE_actualcp[playerid] == 0) return 0;
  59. else return 1;
  60. }
  61. stock CPS_GetPlayerCheckpoint(playerid) if(!IsPlayerInCheckpoint(playerid)) return 0; else return CPSERVICE_actualcp[playerid];
  62. stock CPS_RemoveCheckpoint(cpid)
  63. {
  64. if(cpid == 0 || UsedCPSlot[cpid] == 0) return 0;
  65. UsedCPSlot[cpid]=0;
  66. return 1;
  67. }
  68. public CPSERVICE_Handler()
  69. {
  70. for(new i; i<MAX_PLAYERS; i++){
  71. new Float:prevdist = 100000.000;
  72. new prevcp;
  73. for(new cpid=1; cpid < MAX_CHECKPOINTS; cpid++){
  74. if(UsedCPSlot[cpid]) {
  75. new Float:dist;
  76. dist = CPSERVICE_getdist(i,Checkpoints[cpid][cpX],Checkpoints[cpid][cpY],Checkpoints[cpid][cpZ]);
  77. if(dist < prevdist){
  78. prevdist = dist;
  79. prevcp = cpid;
  80. }
  81. }
  82. }
  83. new cpid=prevcp;
  84. if(CPSERVICE_getdist(i,Checkpoints[cpid][cpX],Checkpoints[cpid][cpY],Checkpoints[cpid][cpZ]) < Checkpoints[cpid][cpsd]) {
  85. if(CPSERVICE_actualcp[i] != cpid){
  86. SetPlayerCheckpoint(i,Checkpoints[cpid][cpX],Checkpoints[cpid][cpY],Checkpoints[cpid][cpZ],Checkpoints[cpid][cpsz]);
  87. CPSERVICE_actualcp[i] = cpid;
  88. }
  89. } else {
  90. if(CPSERVICE_actualcp[i] != 0){
  91. CPSERVICE_actualcp[i] = 0;
  92. DisablePlayerCheckpoint(i);
  93. }
  94. }
  95. }
  96. return 1;
  97. }
  98. stock CPSERVICE_getdist(playerid,Float:x2,Float:y2,Float:z2)
  99. {
  100. new Float:x1,Float:y1,Float:z1;
  101. new Float:tmpdis;
  102. GetPlayerPos(playerid,x1,y1,z1);
  103. tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  104. return floatround(tmpdis);
  105. }