SHARE
TWEET

Checkpoint.inc

a guest Jul 25th, 2014 181 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2.  
  3.  
  4. #define MAX_CHECKPOINTS 800
  5.  
  6. forward CPSERVICE_Handler();
  7. enum cpinfo
  8. {
  9.         Float:cpX,
  10.         Float:cpY,
  11.         Float:cpZ,
  12.         Float:cpsz,
  13.         cpsd,
  14. };
  15. new CPSERVICE_active;
  16. new Checkpoints[MAX_CHECKPOINTS][cpinfo];
  17. new UsedCPSlot[MAX_CHECKPOINTS];
  18. new CPSERVICE_actualcp[MAX_PLAYERS];
  19.  
  20. stock CheckPoint_Create(Float:X,Float:Y,Float:Z,Float:size,spawn_dist)
  21. {
  22.         new cpid=1;
  23.         while(UsedCPSlot[cpid] == 1) cpid++;
  24.         if(CPSERVICE_active == 0){
  25.         SetTimer("CPSERVICE_Handler",5000, 1);
  26.     CPSERVICE_active=1;
  27.         }
  28.         UsedCPSlot[cpid]=1;
  29.         Checkpoints[cpid][cpX]=X;
  30.         Checkpoints[cpid][cpY]=Y;
  31.         Checkpoints[cpid][cpZ]=Z;
  32.         Checkpoints[cpid][cpsz]=size;
  33.         Checkpoints[cpid][cpsd]=spawn_dist;
  34.         return cpid;
  35. }
  36.  
  37.  
  38. stock CheckPoint_Del(cpid)
  39. {
  40.         if(cpid == 0 || UsedCPSlot[cpid] == 0) return 0;
  41.         UsedCPSlot[cpid]=0;
  42.         return 1;
  43. }
  44.  
  45.  
  46. stock CPSERVICE_getdist(playerid,Float:x2,Float:y2,Float:z2)
  47. {
  48.         new Float:x1,Float:y1,Float:z1;
  49.         new Float:tmpdis;
  50.         GetPlayerPos(playerid,x1,y1,z1);
  51.         tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  52.         return floatround(tmpdis);
  53. }
  54.  
  55.  
  56. public CPSERVICE_Handler()
  57. {
  58.         for(new i; i<MAX_PLAYERS; i++){
  59.                 new Float:prevdist = 100000.000;
  60.                 new prevcp;
  61.                 for(new cpid=1; cpid < MAX_CHECKPOINTS; cpid++){
  62.                         if(UsedCPSlot[cpid]) {
  63.                             new Float:dist;
  64.                             dist = CPSERVICE_getdist(i,Checkpoints[cpid][cpX],Checkpoints[cpid][cpY],Checkpoints[cpid][cpZ]);
  65.                                 if(dist < prevdist){
  66.                                 prevdist = dist;
  67.                                         prevcp = cpid;
  68.                                 }
  69.                         }
  70.                 }
  71.                 new cpid=prevcp;
  72.                 if(CPSERVICE_getdist(i,Checkpoints[cpid][cpX],Checkpoints[cpid][cpY],Checkpoints[cpid][cpZ]) < Checkpoints[cpid][cpsd]) {
  73.                     if(CPSERVICE_actualcp[i] != cpid){
  74.                             SetPlayerCheckpoint(i,Checkpoints[cpid][cpX],Checkpoints[cpid][cpY],Checkpoints[cpid][cpZ],Checkpoints[cpid][cpsz]);
  75.                             CPSERVICE_actualcp[i] = cpid;
  76.                         }
  77.                 } else {
  78.                     if(CPSERVICE_actualcp[i] != 0){
  79.                             CPSERVICE_actualcp[i] = 0;
  80.                             DisablePlayerCheckpoint(i);
  81.                         }
  82.                 }
  83.         }
  84.         return 1;
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top