Advertisement
Johurt

[FS] jCheckpoints.

Apr 4th, 2013
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.71 KB | None | 0 0
  1. /*
  2.     jCheckpoints by Johurt(ES.^, Edgar).
  3.         Date: 04-04-2013
  4.     Video: http://www.youtube.com/watch?v=WQqVz1sJ9Xo
  5. */
  6. #include <a_samp>
  7.  
  8. #define MAX_PLAYER_CPS  5
  9. #define PLUS_CP_SIZE    2.0
  10.  
  11. new pCPID[MAX_PLAYERS],
  12.     Float:pCPPosX[MAX_PLAYERS][MAX_PLAYER_CPS],
  13.     Float:pCPPosY[MAX_PLAYERS][MAX_PLAYER_CPS],
  14.     Float:pCPPosZ[MAX_PLAYERS][MAX_PLAYER_CPS],
  15.     Float:pCPSize[MAX_PLAYERS][MAX_PLAYER_CPS],
  16.     bool:pCPShow[MAX_PLAYERS][MAX_PLAYER_CPS];
  17.  
  18. public OnPlayerConnect(playerid)
  19. {
  20.     pCPID[playerid] = -1;
  21.     for(new cp; cp < MAX_PLAYER_CPS; cp++)
  22.     {
  23.         pCPPosX[playerid][cp] = 0.0;
  24.         pCPPosY[playerid][cp] = 0.0;
  25.         pCPPosZ[playerid][cp] = 0.0;
  26.         pCPSize[playerid][cp] = 0.0;
  27.         pCPShow[playerid][cp] = false;
  28.     }
  29.     return 1;
  30. }
  31.  
  32. public OnPlayerCommandText(playerid, cmdtext[])
  33. {
  34.     if(!strcmp("/cp1", cmdtext, true, 4))
  35.     {
  36.         SetPlayerCheckpointEx(playerid, 0, -2026.5967, -101.1647, 35.1641, 3.0);
  37.         return 1;
  38.     }
  39.     if(!strcmp("/cp2", cmdtext, true, 4))
  40.     {
  41.         SetPlayerCheckpointEx(playerid, 1, -2027.8463, -41.2431, 38.8047, 3.0);
  42.         return 1;
  43.     }
  44.     return 0;
  45. }
  46.  
  47. public OnPlayerEnterCheckpoint(playerid)
  48. {
  49.     new cpid = pCPID[playerid];
  50.     switch(cpid)
  51.     {
  52.         case 0:
  53.             {
  54.             if(IsPlayerInCheckpointEx(playerid, cpid))
  55.                 {
  56.                 printf("Player enter %d ID checkpoint.", cpid);
  57.                 DisablePlayerCheckpointEx(playerid, 0);
  58.             }
  59.         }
  60.         case 1:
  61.             {
  62.             if(IsPlayerInCheckpointEx(playerid, cpid))
  63.                 {
  64.                 printf("Player enter %d ID checkpoint.", cpid);
  65.                 DisablePlayerCheckpointEx(playerid, 1);
  66.             }
  67.             }
  68.     }
  69.     return 1;
  70. }
  71.  
  72. public OnPlayerLeaveCheckpoint(playerid)
  73. {
  74.     new cpid = pCPID[playerid];
  75.     switch(cpid)
  76.     {
  77.         case 1:
  78.             {
  79.                 if(IsPlayerInCheckpointEx(playerid, cpid))
  80.                 {
  81.                 printf("Player leave %d ID checkpoint.", cpid);
  82.             }
  83.             }
  84.     }
  85.     return 1;
  86. }
  87.  
  88. stock SetPlayerCheckpointEx(playerid, cpid, Float:x, Float:y, Float:z, Float:size)
  89. {
  90.     if(cpid < 0 || cpid > MAX_PLAYER_CPS - 1)
  91.     {
  92.         printf("Error, you can't create cp with %d ID.", cpid);
  93.             return 1;
  94.     }
  95.     pCPPosX[playerid][cpid] = x;
  96.     pCPPosY[playerid][cpid] = y;
  97.     pCPPosZ[playerid][cpid] = z;
  98.     pCPSize[playerid][cpid] = size;
  99.     pCPShow[playerid][cpid] = true;
  100.     pCPID[playerid] = cpid;
  101.     SetPlayerCheckpoint(playerid, x, y, z, size);
  102.     return 1;
  103. }
  104.  
  105. stock DisablePlayerCheckpointEx(playerid, cpid)
  106. {
  107.     if(cpid < 0 || cpid > MAX_PLAYER_CPS - 1)
  108.     {
  109.         printf("Error, you can't delete cp with %d ID.", cpid);
  110.             return 1;
  111.     }
  112.     pCPID[playerid] = -1;
  113.     pCPPosX[playerid][cpid] = 0.0;
  114.     pCPPosY[playerid][cpid] = 0.0;
  115.     pCPPosZ[playerid][cpid] = 0.0;
  116.     pCPSize[playerid][cpid] = 0.0;
  117.     pCPShow[playerid][cpid] = false;
  118.     DisablePlayerCheckpoint(playerid);
  119.     for(new cp; cp < MAX_PLAYER_CPS; cp++)
  120.     {
  121.         if(pCPShow[playerid][cp])
  122.             {
  123.                 pCPID[playerid] = cp;
  124.             SetPlayerCheckpoint(playerid, pCPPosX[playerid][cp], pCPPosY[playerid][cp], pCPPosZ[playerid][cp], pCPSize[playerid][cp]);
  125.             break;
  126.         }
  127.     }
  128.     return 1;
  129. }
  130.  
  131. stock DisableAllPlayerCheckpoints(playerid)
  132. {
  133.     pCPID[playerid] = -1;
  134.     DisablePlayerCheckpoint(playerid);
  135.     for(new cp; cp < MAX_PLAYER_CPS; cp++)
  136.     {
  137.         if(pCPShow[playerid][cp])
  138.         {
  139.             pCPPosX[playerid][cp] = 0.0;
  140.             pCPPosY[playerid][cp] = 0.0;
  141.             pCPPosZ[playerid][cp] = 0.0;
  142.             pCPSize[playerid][cp] = 0.0;
  143.             pCPShow[playerid][cp] = false;
  144.         }
  145.     }
  146.     return 1;
  147. }
  148.  
  149. stock IsPlayerInCheckpointEx(playerid, cpid)
  150. {
  151.     if(cpid < 0 || cpid > MAX_PLAYER_CPS)
  152.     {
  153.         printf("Error, you can't check cp with %d ID.", cpid);
  154.             return false;
  155.     }
  156.     if(!pCPShow[playerid][cpid]) return false;
  157.     if(!IsPlayerInRangeOfPoint(playerid, pCPSize[playerid][cpid] + PLUS_CP_SIZE, pCPPosX[playerid][cpid], pCPPosY[playerid][cpid], pCPPosZ[playerid][cpid])) return false;
  158.     return true;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement