Advertisement
Guest User

Untitled

a guest
Aug 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.29 KB | None | 0 0
  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.  
  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.  
  20. #define MAX_CHECKPOINTS 500
  21.  
  22. forward CPSERVICE_Handler();
  23. enum cpinfo
  24. {
  25.     Float:cpX,
  26.     Float:cpY,
  27.     Float:cpZ,
  28.     Float:cpsz,
  29.     cpsd,
  30. };
  31. new CPSERVICE_active;
  32. new Checkpoints[MAX_CHECKPOINTS][cpinfo];
  33. new UsedCPSlot[MAX_CHECKPOINTS];
  34. new CPSERVICE_actualcp[MAX_PLAYERS];
  35.  
  36. stock CPS_AddCheckpoint(Float:X,Float:Y,Float:Z,Float:size,spawn_dist)
  37. {
  38.     new cpid=1;
  39.     while(UsedCPSlot[cpid] == 1) cpid++;
  40.     if(CPSERVICE_active == 0){
  41.         SetTimer("CPSERVICE_Handler",500,true);
  42.         CPSERVICE_active=1;
  43.     }
  44.     UsedCPSlot[cpid]=1;
  45.     Checkpoints[cpid][cpX]=X;
  46.     Checkpoints[cpid][cpY]=Y;
  47.     Checkpoints[cpid][cpZ]=Z;
  48.     Checkpoints[cpid][cpsz]=size;
  49.     Checkpoints[cpid][cpsd]=spawn_dist;
  50.     return cpid;
  51. }
  52.  
  53. stock CPS_IsPlayerInCheckpoint(playerid,cpid)
  54. {
  55.     if(!IsPlayerInCheckpoint(playerid)) return 0;
  56.     if(CPSERVICE_actualcp[playerid] == cpid) return 1;
  57.     else return 0;
  58. }
  59.  
  60. stock CPS_IsPlayerInAnyCheckpoint(playerid)
  61. {
  62.     if(!IsPlayerInCheckpoint(playerid)) return 0;
  63.     if(CPSERVICE_actualcp[playerid] == 0) return 0;
  64.     else return 1;
  65. }
  66.  
  67. stock CPS_GetPlayerCheckpoint(playerid) if(!IsPlayerInCheckpoint(playerid)) return 0; else return CPSERVICE_actualcp[playerid];
  68.  
  69. stock CPS_RemoveCheckpoint(cpid)
  70. {
  71.     if(cpid == 0 || UsedCPSlot[cpid] == 0) return 0;
  72.     UsedCPSlot[cpid]=0;
  73.     return 1;
  74. }
  75.  
  76. public CPSERVICE_Handler()
  77. {
  78.     for(new i; i<MAX_PLAYERS; i++){
  79.         new Float:prevdist = 100000.000;
  80.         new prevcp;
  81.         for(new cpid=1; cpid < MAX_CHECKPOINTS; cpid++){
  82.             if(UsedCPSlot[cpid]) {
  83.                 new Float:dist;
  84.                 dist = CPSERVICE_getdist(i,Checkpoints[cpid][cpX],Checkpoints[cpid][cpY],Checkpoints[cpid][cpZ]);
  85.                 if(dist < prevdist){
  86.                     prevdist = dist;
  87.                     prevcp = cpid;
  88.                 }
  89.             }
  90.         }
  91.         new cpid=prevcp;
  92.         if(CPSERVICE_getdist(i,Checkpoints[cpid][cpX],Checkpoints[cpid][cpY],Checkpoints[cpid][cpZ]) < Checkpoints[cpid][cpsd]) {
  93.             if(CPSERVICE_actualcp[i] != cpid){
  94.                 SetPlayerCheckpoint(i,Checkpoints[cpid][cpX],Checkpoints[cpid][cpY],Checkpoints[cpid][cpZ],Checkpoints[cpid][cpsz]);
  95.                 CPSERVICE_actualcp[i] = cpid;
  96.             }
  97.         } else {
  98.             if(CPSERVICE_actualcp[i] != 0){
  99.                 CPSERVICE_actualcp[i] = 0;
  100.                 DisablePlayerCheckpoint(i);
  101.             }
  102.         }
  103.     }
  104.     return 1;
  105. }
  106.  
  107. stock CPSERVICE_getdist(playerid,Float:x2,Float:y2,Float:z2)
  108. {
  109.     new Float:x1,Float:y1,Float:z1;
  110.     new Float:tmpdis;
  111.     GetPlayerPos(playerid,x1,y1,z1);
  112.     tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  113.     return floatround(tmpdis);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement