LeonardoBradoks

Include CPSTREAM

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