Advertisement
Guest User

(1.2.3) Checkpoint.inc - by AnthonyDaSexy

a guest
Aug 1st, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 27.57 KB | None | 0 0
  1. /*====================================================================================================
  2.     Checkpoint: Easy checkpoint management.
  3.    
  4.     Author:
  5.     * AnthonyDaSexy
  6.    
  7.     Version:
  8.     * 1.2.3
  9.    
  10.     Last Updated:
  11.     * 01.08.2016
  12.    
  13.     Credits:
  14.     * SA:MP Team - For creating SA:MP obviously.
  15.     * Ash. - The include was inspired by his.
  16.     * Yashas - His modified version of zcmd (izcmd) was used in the example script.
  17.    
  18.     Description:
  19.     * More functionality and features for checkpoints. Easy management, serversided and much more.
  20.    
  21.     Warranties:
  22.     * This include is provided as is, no warranties whatsoever.
  23.    
  24.     Functions:
  25.     * native SetPlayerCheckpoint(playerid, Float:x, Float:y, Float:z, Float:size, cp_id = UNUSED_CHECKPOINT_ID);
  26.     * native DisablePlayerCheckpoint(playerid);
  27.     * native IsValidCheckpoint(playerid);
  28.     * native GetPlayerCheckpointId(playerid);
  29.     * native GetPlayerCheckpointPos(playerid, &Float:x, &Float:y, &Float:z);
  30.     * native GetPlayerCheckpointSize(playerid, &Float:size);
  31.     * native IsPlayerInRangeOfCheckpoint(playerid, Float:range);
  32.     * native Float:GetPlayerDistanceFromCheckpoint(playerid);
  33.     * native SetPlayerRaceCheckpoint(playerid, type, Float:x, Float:y, Float:z, Float:nextx, Float:nexty, Float:nextz, Float:size, cp_id = UNUSED_CHECKPOINT_ID);
  34.     * native DisablePlayerRaceCheckpoint(playerid);
  35.     * native IsValidRaceCheckpoint(playerid);
  36.     * native GetPlayerRaceCheckpointId(playerid);
  37.     * native GetPlayerRaceCheckpointPos(playerid, &Float:x, &Float:y, &Float:z);
  38.     * native GetPlayerRaceCheckpointNextPos(playerid, &Float:nextx, &Float:nexty, &Float:nextz);
  39.     * native GetPlayerRaceCheckpointSize(playerid, &Float:size);
  40.     * native IsPlayerInRangeOfRaceCheckpoint(playerid, Float:range);
  41.     * native Float:GetDistanceFromRaceCheckpoint(playerid);
  42.    
  43.     Callbacks:
  44.     * native OnPlayerCheckpointSet(playerid);
  45.     * native OnPlayerCheckpointDisable(playerid);
  46.     * native OnPlayerRaceCheckpointSet(playerid);
  47.     * native OnPlayerRaceCheckpointDisable(playerid);
  48.    
  49.     Hooked Callbacks:
  50.     * native OnPlayerConnect(playerid);
  51.     * native OnPlayerEnterCheckpoint(playerid);
  52.     * native OnPlayerLeaveCheckpoint(playerid);
  53.     * native OnPlayerEnterRaceCheckpoint(playerid);
  54.     * native OnPlayerLeaveRaceCheckpoint(playerid);
  55. ====================================================================================================*/
  56. #if !defined _samp_included
  57.     #error Please include 'a_samp.inc' before 'checkpoint.inc'
  58. #endif
  59. #if defined _checkpoint_included
  60.     #endinput
  61. #endif
  62. #define _checkpoint_included
  63. #pragma library checkpoint
  64. /*====================================================================================================
  65.     Define invalid and unused checkpoind id.
  66. ====================================================================================================*/
  67. #define INVALID_CHECKPOINT_ID -1
  68. #define UNUSED_CHECKPOINT_ID 0
  69. /*====================================================================================================
  70.     Variables:
  71.     * enums, arrays, statics, ...:
  72. ====================================================================================================*/
  73. enum E_CHECKPOINT {
  74.     cpId,
  75.     Float:cpX,
  76.     Float:cpY,
  77.     Float:cpZ,
  78.     Float:cpSize
  79. };
  80. static cpData[MAX_PLAYERS][E_CHECKPOINT];
  81.  
  82. enum E_RACE_CHECKPOINT {
  83.     cpId,
  84.     cpType,
  85.     Float:cpX,
  86.     Float:cpY,
  87.     Float:cpZ,
  88.     Float:cpNextX,
  89.     Float:cpNextY,
  90.     Float:cpNextZ,
  91.     Float:cpSize
  92. };
  93. static raceCpData[MAX_PLAYERS][E_RACE_CHECKPOINT];
  94. /*====================================================================================================
  95.     native OnPlayerCheckpointSet(playerid);
  96.     > playerid      >       The id of the player.
  97.     Description:
  98.     * Gets executed whenever a checkpoint is set using SetPlayerCheckpoint. It gets
  99.     executed after the variables are saved so you can use all the include
  100.     functions provided in this callback.
  101. ====================================================================================================*/
  102. #if defined OnPlayerCheckpointSet
  103.     forward OnPlayerCheckpointSet(playerid);
  104. #endif
  105. /*====================================================================================================
  106.     native OnPlayerCheckpointDisable(playerid);
  107.     > playerid      >       The id of the player.
  108.     Description:
  109.     * Gets executed whenever a checkpoint is disabled using DisablePlayerCheckpoint. It gets
  110.     executed before the variables are resetted, so you can use all the functions
  111.     this include provide in the callback to do whatever.
  112. ====================================================================================================*/
  113. #if defined OnPlayerCheckpointDisable
  114.     forward OnPlayerCheckpointDisable(playerid);
  115. #endif
  116. /*====================================================================================================
  117.     native SetPlayerCheckpoint(playerid, Float:x, Float:y, Float:z, Float:size, cp_id = UNUSED_CHECKPOINT_ID);
  118.     > playerid                          =       The id of the player.
  119.     > Float:x                           =       The x position of the checkpoint
  120.     > Float:y                           =       The z position of the checkpoint.
  121.     > Float:size                        =       The size of the checkpoint.
  122.     > cp_id = UNUSED_CHECKPOINT_ID      =       The id of the checkpoint (optional).
  123.     Description:
  124.     * Mark a checkpoint on the map for the player at the specified x, y, z position
  125.     with the specified range. It will return 0 if the player is not connected or invalid
  126.     and 1 if the checkpoint was successfully marked on the map.
  127. ====================================================================================================*/
  128. stock cp_SetPlayerCheckpoint(playerid, Float:x, Float:y, Float:z, Float:size, cp_id = UNUSED_CHECKPOINT_ID) {
  129.  
  130.     if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid))
  131.         return 0;
  132.  
  133.     cpData[playerid][cpId] = cp_id;
  134.     cpData[playerid][cpX] = x, cpData[playerid][cpY] = y, cpData[playerid][cpZ] = z, cpData[playerid][cpSize] = size;
  135.     SetPlayerCheckpoint(playerid, x, y, z, size);
  136.    
  137.     #if defined OnPlayerCheckpointSet
  138.         return OnPlayerCheckpointSet(playerid);
  139.     #else
  140.         return 1;
  141.     #endif
  142. }
  143. #if defined _ALS_SetPlayerCheckpoint
  144.     #undef SetPlayerCheckpoint
  145. #else
  146.     #define _ALS_SetPlayerCheckpoint
  147. #endif
  148. #define SetPlayerCheckpoint cp_SetPlayerCheckpoint
  149. /*====================================================================================================
  150.     native DisablePlayerCheckpoint(playerid);
  151.     > playerid      =       The id of the player.
  152.     Description:
  153.     * Disable / remove the checkpoint from the map, make it invisible for the player.
  154.     It will return 0 if checkpoint is invalid and 1 if the checkpoint was successfully disabled.
  155. ====================================================================================================*/
  156. stock cp_DisablePlayerCheckpoint(playerid) {
  157.  
  158.     if(!IsValidCheckpoint(playerid))
  159.         return DisablePlayerCheckpoint(playerid);
  160.        
  161.     #if defined OnPlayerCheckpointDisable
  162.         OnPlayerCheckpointDisable(playerid);
  163.     #endif
  164.    
  165.     cpData[playerid][cpId] = INVALID_CHECKPOINT_ID;
  166.     cpData[playerid][cpX] = cpData[playerid][cpY] = cpData[playerid][cpZ] = cpData[playerid][cpSize] = 0.0000;
  167.     DisablePlayerCheckpoint(playerid);
  168.     return 1;
  169. }
  170. #if defined _ALS_DisablePlayerCheckpoint
  171.     #undef DisablePlayerCheckpoint
  172. #else
  173.     #define _ALS_DisablePlayerCheckpoint
  174. #endif
  175. #define DisablePlayerCheckpoint cp_DisablePlayerCheckpoint
  176. /*====================================================================================================
  177.     native IsPlayerInCheckpoint(playerid);
  178.     > playerid      =       The id of the player.
  179.     Description:
  180.     * Check if the player is inside the checkpoint, will return 1 if the player is inside the
  181.     checkpoint and 0 if the player is not inside the checkpoint.
  182. ====================================================================================================*/
  183. stock cp_IsPlayerInCheckpoint(playerid) {
  184.  
  185.     if(!IsValidCheckpoint(playerid))
  186.         return 0;
  187.        
  188.     if(!IsPlayerInRangeOfPoint(playerid, cpData[playerid][cpSize], cpData[playerid][cpX], cpData[playerid][cpY], cpData[playerid][cpZ]))
  189.         return 0;
  190.  
  191.     return 1;
  192. }
  193. #if defined _ALS_IsPlayerInCheckpoint
  194.     #undef IsPlayerInCheckpoint
  195. #else
  196.     #define _ALS_IsPlayerInCheckpoint
  197. #endif
  198. #define IsPlayerInCheckpoint cp_IsPlayerInCheckpoint
  199. /*====================================================================================================
  200.     native IsValidCheckpoint(playerid);
  201.     > playerid      =       The id of the player.
  202.     Description:
  203.     * Check if the checkpoint is valid / marked. If the checkpoint is valid it will return 1,
  204.     else if the checkpoint is invalid it will return 0.
  205. ====================================================================================================*/
  206. stock IsValidCheckpoint(playerid) {
  207.    
  208.     if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid))
  209.         return 0;
  210.    
  211.     if(cpData[playerid][cpId] == INVALID_CHECKPOINT_ID && cpData[playerid][cpX] == 0.0000 && cpData[playerid][cpY] == 0.0000 && cpData[playerid][cpZ] == 0.0000 && cpData[playerid][cpSize] == 0.0000)
  212.         return 0;
  213.    
  214.     return 1;
  215. }
  216. /*====================================================================================================
  217.     native GetPlayerCheckpointId(playerid);
  218.     > playerid      =       The id of the player.
  219.     Description:
  220.     * Get player's checkpoint id and returns it, if invalid return INVALID_CHECKPOINT_ID.
  221. ====================================================================================================*/
  222. stock GetPlayerCheckpointId(playerid) {
  223.  
  224.     if(!IsValidCheckpoint(playerid))
  225.         return INVALID_CHECKPOINT_ID;
  226.  
  227.     return cpData[playerid][cpId];
  228. }
  229. /*====================================================================================================
  230.     native GetPlayerCheckpointPos(playerid, &Float:x, &Float:y, &Float:z);
  231.     > playerid      =       The id of the player.
  232.     > &Float:x      =       The x position of the checkpoint.
  233.     > &Float:y      =       The y position of the checkpoint.
  234.     > &Float:z      =       The z position of the checkpoint.
  235.     Description:
  236.     * Get checkpoint position and store them into x, y, z float variables.
  237.     return 1 if the checkpoint exists, else if it doesn't exist it will return 0.
  238. ====================================================================================================*/
  239. stock GetPlayerCheckpointPos(playerid, &Float:x, &Float:y, &Float:z) {
  240.  
  241.     if(!IsValidCheckpoint(playerid))
  242.         return 0;
  243.        
  244.     x = cpData[playerid][cpX], y = cpData[playerid][cpY], z = cpData[playerid][cpZ];
  245.     return 1;
  246. }
  247. /*====================================================================================================
  248.     native GetPlayerCheckpointSize(playerid, &Float:size);
  249.     > playerid      =       The id of the player.
  250.     > &Float:size   =       The size of the checkpoint.
  251.     Description:
  252.     * Get the size of the checkpoint and stores it into the size float variable.
  253.     return 1 if the checkpoint exists, else if it doesn't exist it will return 0.
  254. ====================================================================================================*/
  255. stock GetPlayerCheckpointSize(playerid, &Float:size) {
  256.  
  257.     if(!IsValidCheckpoint(playerid))
  258.         return 0;
  259.  
  260.     size = cpData[playerid][cpSize];
  261.     return 1;
  262. }
  263. /*====================================================================================================
  264.     native IsPlayerInRangeOfCheckpoint(playerid, Float:range);,
  265.     > playerid      =       The id of the player.
  266.     > Float:range   =       The maximum range between the player and the checkpoint.
  267.     Description:
  268.     * Check if player is in range of the checkpoint with specified range. Returns 1 if the player
  269.     is in range, else it returns 0 if player is not in range.
  270. ====================================================================================================*/
  271. stock IsPlayerInRangeOfCheckpoint(playerid, Float:range) {
  272.  
  273.     if(!IsValidCheckpoint(playerid))
  274.         return 0;
  275.        
  276.     if(!IsPlayerInRangeOfPoint(playerid, range, cpData[playerid][cpX], cpData[playerid][cpY], cpData[playerid][cpZ]))
  277.         return 0;
  278.        
  279.     return 1;
  280. }
  281. /*====================================================================================================
  282.     native Float:GetPlayerDistanceFromCheckpoint(playerid);
  283.     > playerid      =       The id of the player.
  284.     Description:
  285.     * Return the distance from player to checkpoint in float value,
  286.     it returns 0.0000 if the checkpoint is invalid.
  287. ====================================================================================================*/
  288. stock Float:GetPlayerDistanceFromCheckpoint(playerid) {
  289.  
  290.     if(!IsValidCheckpoint(playerid))
  291.         return 0.0000;
  292.        
  293.     return GetPlayerDistanceFromPoint(playerid, cpData[playerid][cpX], cpData[playerid][cpY], cpData[playerid][cpZ]);
  294. }
  295. /*====================================================================================================
  296.     native OnPlayerEnterCheckpoint(playerid);
  297.     > playerid      =       The id of the player.
  298.     Description:
  299.     * Hook into OnPlayerEnterCheckpoint and check if the checkpoint is valid,
  300.     if not valid it will return 0.
  301. ====================================================================================================*/
  302. public OnPlayerEnterCheckpoint(playerid) {
  303.    
  304.     if(!IsValidCheckpoint(playerid))
  305.         return 0;
  306.  
  307.     #if defined cp_OnPlayerEnterCheckpoint
  308.         return cp_OnPlayerEnterCheckpoint(playerid);
  309.     #else
  310.         return 1;
  311.     #endif
  312. }
  313. #if defined _ALS_OnPlayerEnterCheckpoint
  314.     #undef OnPlayerEnterCheckpoint
  315. #else
  316.     #define _ALS_OnPlayerEnterCheckpoint
  317. #endif
  318. #define OnPlayerEnterCheckpoint cp_OnPlayerEnterCheckpoint
  319. #if defined cp_OnPlayerEnterCheckpoint
  320.     forward cp_OnPlayerEnterCheckpoint(playerid);
  321. #endif
  322. /*====================================================================================================
  323.     native OnPlayerLeaveCheckpoint(playerid);
  324.     * playerid      =       The id of the player.
  325.     Description:
  326.     * Hook into OnPlayerLeaveCheckpoint and check if the checkpoint is valid,
  327.     if not valid it will return 0.
  328. ====================================================================================================*/
  329. public OnPlayerLeaveCheckpoint(playerid) {
  330.  
  331.     if(!IsValidCheckpoint(playerid))
  332.         return 0;
  333.  
  334.     #if defined cp_OnPlayerLeaveCheckpoint
  335.         return cp_OnPlayerLeaveCheckpoint(playerid);
  336.     #else
  337.         return 1;
  338.     #endif
  339. }
  340. #if defined _ALS_OnPlayerLeaveCheckpoint
  341.     #undef OnPlayerLeaveCheckpoint
  342. #else
  343.     #define _ALS_OnPlayerLeaveCheckpoint
  344. #endif
  345. #define OnPlayerLeaveCheckpoint cp_OnPlayerLeaveCheckpoint
  346. #if defined cp_OnPlayerLeaveCheckpoint
  347.     forward cp_OnPlayerLeaveCheckpoint(playerid);
  348. #endif
  349. /*====================================================================================================
  350.     native OnPlayerRaceCheckpointSet(playerid);
  351.     > playerid      =       The id of the player.
  352.     Description:
  353.     * Gets called whenever 'SetPlayerRaceCheckpoint' is used, all race checkpoint
  354.     functions are usable inside the callback.
  355. ====================================================================================================*/
  356. #if defined OnPlayerRaceCheckpointSet
  357.     forward OnPlayerRaceCheckpointSet(playerid);
  358. #endif
  359. /*====================================================================================================
  360.     native OnPlayerRaceCheckpointDisable(playerid);
  361.     > playerid      =       The id of the player.
  362.     Description:
  363.     * Gets called whenever 'DisablePlayerRaceCheckpoint' is used, all race checkpoint
  364.     functions are usable inside the callback.
  365. ====================================================================================================*/
  366. #if defined OnPlayerRaceCheckpointDisable
  367.     forward OnPlayerRaceCheckpointDisable(playerid);
  368. #endif
  369. /*====================================================================================================
  370.     native SetPlayerRaceCheckpoint(playerid, type, Float:x, Float:y, Float:z, Float:nextx, Float:nexty, Float:nextz, Float:size, cp_id = UNUSED_CHECKPOINT_ID);
  371.     > playerid                          =       The id of the player.
  372.     > type                              =       The type / style of the race checkpoint.
  373.     > Float:x                           =       The x position of the race checkpoint.
  374.     > Float:y                           =       The y position of the race checkpoint.
  375.     > Float:z                           =       The z position of the race checkpoint.
  376.     > Float:nextx                       =       The nextx position of the race checkpoint.
  377.     > Float:nexty                       =       The nexty position of the race checkpoint.
  378.     > Float:nextz                       =       The nextz position of the race checkpoint.
  379.     > Float:size                        =       The size of the race checkpoint.
  380.     > cp_id = UNUSED_CHECKPOINT_ID      =       The id of the checkpoint.
  381.     Description:
  382.     * Mark a race checkpoint on the player's map, stores all information into variables for easy
  383.     access, can also be assigned an id for easier management of the checkpoint.
  384. ====================================================================================================*/
  385. stock cp_SetPlayerRaceCheckpoint(playerid, type, Float:x, Float:y, Float:z, Float:nextx, Float:nexty, Float:nextz, Float:size, cp_id = UNUSED_CHECKPOINT_ID) {
  386.  
  387.     if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid))
  388.         return 0;
  389.  
  390.     raceCpData[playerid][cpId] = cp_id, raceCpData[playerid][cpType] = type,
  391.     raceCpData[playerid][cpX] = x, raceCpData[playerid][cpY] = y, raceCpData[playerid][cpZ] = z,
  392.     raceCpData[playerid][cpNextX] = nextx, raceCpData[playerid][cpNextY] = nexty, raceCpData[playerid][cpNextZ] = nextz,
  393.     raceCpData[playerid][cpSize] = size;
  394.     SetPlayerRaceCheckpoint(playerid, type, x, y, z, nextx, nexty, nextz, size);
  395.    
  396.     #if defined OnPlayerRaceCheckpointSet
  397.         return OnPlayerRaceCheckpointSet(playerid);
  398.     #else
  399.         return 1;
  400.     #endif
  401. }
  402. #if defined _ALS_SetPlayerRaceCheckpoint
  403.     #undef SetPlayerRaceCheckpoint
  404. #else
  405.     #define _ALS_SetPlayerRaceCheckpoint
  406. #endif
  407. #define SetPlayerRaceCheckpoint cp_SetPlayerRaceCheckpoint
  408. /*====================================================================================================
  409.     native DisablePlayerRaceCheckpoint(playerid);
  410.     > playerid      =       The id of the player.
  411.     Description:
  412.     * Disable / unmark race checkpoint from player's map and reset all race checkpoint
  413.     variables.
  414. ====================================================================================================*/
  415. stock cp_DisablePlayerRaceCheckpoint(playerid) {
  416.  
  417.     if(!IsValidRaceCheckpoint(playerid))
  418.         return DisablePlayerRaceCheckpoint(playerid);
  419.        
  420.     raceCpData[playerid][cpId] = raceCpData[playerid][cpType] = INVALID_CHECKPOINT_ID,
  421.     raceCpData[playerid][cpX] = raceCpData[playerid][cpY] = raceCpData[playerid][cpZ] =
  422.     raceCpData[playerid][cpNextX] = raceCpData[playerid][cpNextY] = raceCpData[playerid][cpNextZ] =
  423.     raceCpData[playerid][cpSize] = 0.0000;
  424.     DisablePlayerRaceCheckpoint(playerid);
  425.    
  426.     #if defined OnPlayerRaceCheckpointDisable
  427.         return OnPlayerRaceCheckpointDisable(playerid);
  428.     #else
  429.         return 1;
  430.     #endif
  431. }
  432. #if defined _ALS_DisablePlayerRaceCheckpoin
  433.     #undef DisablePlayerRaceCheckpoint
  434. #else
  435.     #define _ALS_DisablePlayerRaceCheckpoin
  436. #endif
  437. #define DisablePlayerRaceCheckpoint cp_DisablePlayerRaceCheckpoint
  438. /*====================================================================================================
  439.     native IsValidRaceCheckpoint(playerid);
  440.     > playerid      =       The id of the player.
  441.     Description:
  442.     * Checks if the race checkpoint is valid, return 1 if valid
  443.     and return 0 if not valid.
  444. ====================================================================================================*/
  445. stock IsValidRaceCheckpoint(playerid) {
  446.  
  447.     if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid))
  448.         return 0;
  449.        
  450.     if(raceCpData[playerid][cpId] == INVALID_CHECKPOINT_ID && raceCpData[playerid][cpType] == INVALID_CHECKPOINT_ID && raceCpData[playerid][cpX] == 0.0000 && raceCpData[playerid][cpY] == 0.0000 && raceCpData[playerid][cpZ] == 0.0000 && raceCpData[playerid][cpNextX] == 0.0000 && raceCpData[playerid][cpNextY] == 0.0000 && raceCpData[playerid][cpNextZ] == 0.0000 && raceCpData[playerid][cpSize] == 0.0000)
  451.         return 0;
  452.  
  453.     return 1;
  454. }
  455. /*====================================================================================================
  456.     native GetPlayerRaceCheckpointId(playerid);
  457.     > playerid      =       The id of the player.
  458.     Description:
  459.     * Get the player's race checkpoint id and returns it. Will return INVALID_CHECKPOINT_ID
  460.     if player's race checkpoint is invalid.
  461. ====================================================================================================*/
  462. stock GetPlayerRaceCheckpointId(playerid) {
  463.    
  464.     if(!IsValidRaceCheckpoint(playerid))
  465.         return INVALID_CHECKPOINT_ID;
  466.        
  467.     return raceCpData[playerid][cpId];
  468. }
  469. /*====================================================================================================
  470.     native GetPlayerRaceCheckpointPos(playerid, &Float:x, &Float:y, &Float:z);
  471.     > playerid      =       The id of the player.
  472.     > &Float:x      =       The x position of the race checkpoint.
  473.     > &Float:y      =       The y position of the race checkpoint.
  474.     > &Float:z      =       The z position of the race checkpoint.
  475.     Description:
  476.     * Get race checkpoint position and store them into x, y, z float variables.
  477.     return 1 if the race checkpoint exists, else if it doesn't exist it will return 0.
  478. ====================================================================================================*/
  479. stock GetPlayerRaceCheckpointPos(playerid, &Float:x, &Float:y, &Float:z) {
  480.  
  481.     if(!IsValidRaceCheckpoint(playerid))
  482.         return 0;
  483.  
  484.     x = raceCpData[playerid][cpX], y = raceCpData[playerid][cpY], z = raceCpData[playerid][cpZ];
  485.     return 1;
  486. }
  487. /*====================================================================================================
  488.     native GetPlayerRaceCheckpointNextPos(playerid, &Float:nextx, &Float:nexty, &Float:nextz);
  489.     > playerid      =       The id of the player.
  490.     > &Float:nextx      =       The nextx position of the race checkpoint.
  491.     > &Float:nexty      =       The nexty position of the race checkpoint.
  492.     > &Float:nextz      =       The nextz position of the race checkpoint.
  493.     Description:
  494.     * Get race checkpoint next position and store them into nextx, nexty, nextz float variables.
  495.     return 1 if the race checkpoint exists, else if it doesn't exist it will return 0.
  496. ====================================================================================================*/
  497. stock GetPlayerRaceCheckpointNextPos(playerid, &Float:nextx, &Float:nexty, &Float:nextz) {
  498.  
  499.     if(!IsValidRaceCheckpoint(playerid))
  500.         return 0;
  501.  
  502.     nextx = raceCpData[playerid][cpNextX], nexty = raceCpData[playerid][cpNextY], nextz = raceCpData[playerid][cpNextZ];
  503.     return 1;
  504. }
  505. /*====================================================================================================
  506.     native GetPlayerRaceCheckpointSize(playerid, &Float:size);
  507.     > playerid      =       The id of the player.
  508.     > &Float:size   =       The size of the race checkpoint.
  509.     Description:
  510.     * Get the size of the race checkpoint and stores it into the size float variable.
  511.     return 1 if the race checkpoint exists, else if it doesn't exist it will return 0.
  512. ====================================================================================================*/
  513. stock GetPlayerRaceCheckpointSize(playerid, &Float:size) {
  514.  
  515.     if(!IsValidRaceCheckpoint(playerid))
  516.         return 0;
  517.  
  518.     size = raceCpData[playerid][cpSize];
  519.     return 1;
  520. }
  521. /*====================================================================================================
  522.     native IsPlayerInRangeOfRaceCheckpoint(playerid, Float:range);,
  523.     > playerid      =       The id of the player.
  524.     > Float:range   =       The maximum range between the player and the race checkpoint.
  525.     Description:
  526.     * Check if player is in range of the race checkpoint with specified range. Returns 1 if the player
  527.     is in range, else it returns 0 if player is not in range.
  528. ====================================================================================================*/
  529. stock IsPlayerInRangeOfRaceCheckpoint(playerid, Float:range) {
  530.  
  531.     if(!IsValidRaceCheckpoint(playerid))
  532.         return 0;
  533.        
  534.     if(!IsPlayerInRangeOfPoint(playerid, range, raceCpData[playerid][cpX], raceCpData[playerid][cpY], raceCpData[playerid][cpZ]))
  535.         return 0;
  536.        
  537.     return 1;
  538. }
  539. /*====================================================================================================
  540.     native Float:GetDistanceFromRaceCheckpoint(playerid);
  541.     > playerid      =       The id of the player.
  542.     Description:
  543.     * Return the distance from player to race checkpoint in float value,
  544.     it returns 0.0000 if the race checkpoint is invalid.
  545. ====================================================================================================*/
  546. stock Float:GetDistanceFromRaceCheckpoint(playerid) {
  547.  
  548.     if(!IsValidRaceCheckpoint(playerid))
  549.         return 0.0000;
  550.  
  551.     return GetPlayerDistanceFromPoint(playerid, raceCpData[playerid][cpX], raceCpData[playerid][cpY], raceCpData[playerid][cpZ]);
  552. }
  553. /*====================================================================================================
  554.     native OnPlayerEnterRaceCheckpoint(playerid);
  555.     > playerid      =       The id of the player.
  556.     Description:
  557.     * Hook into OnPlayerEnterRaceCheckpoint to check if the race checkpoint
  558.     is valid, return 0 and block the callback if race checkpoint is invalid.
  559. ====================================================================================================*/
  560. public OnPlayerEnterRaceCheckpoint(playerid) {
  561.    
  562.     if(!IsValidRaceCheckpoint(playerid))
  563.         return 0;
  564.  
  565.     #if defined cp_OnPlayerEnterRaceCheckpoint
  566.         return cp_OnPlayerEnterRaceCheckpoint(playerid);
  567.     #else
  568.         return 1;
  569.     #endif
  570. }
  571. #if defined ALS_OnPlayerEnterRaceCheckpoint
  572.     #undef OnPlayerEnterRaceCheckpoint
  573. #else
  574.     #define ALS_OnPlayerEnterRaceCheckpoint
  575. #endif
  576. #define OnPlayerEnterRaceCheckpoint cp_OnPlayerEnterRaceCheckpoint
  577. #if defined cp_OnPlayerEnterRaceCheckpoint
  578.     forward cp_OnPlayerEnterRaceCheckpoint(playerid);
  579. #endif
  580. /*====================================================================================================
  581.     native OnPlayerLeaveRaceCheckpoint(playerid);
  582.     > playerid      =       The id of the player.
  583.     Description:
  584.     * Hook into OnPlayerLeaveRaceCheckpoint to check if the race checkpoint
  585.     is valid, return 0 and block the callback if race checkpoint is invalid.
  586. ====================================================================================================*/
  587. public OnPlayerLeaveRaceCheckpoint(playerid) {
  588.    
  589.     if(!IsValidRaceCheckpoint(playerid))
  590.         return 0;
  591.  
  592.     #if defined cp_OnPlayerLeaveRaceCheckpoint
  593.         return cp_OnPlayerLeaveRaceCheckpoint(playerid);
  594.     #else
  595.         return 1;
  596.     #endif
  597. }
  598. #if defined ALS_OnPlayerLeaveRaceCheckpoint
  599.     #undef OnPlayerLeaveRaceCheckpoint
  600. #else
  601.     #define ALS_OnPlayerLeaveRaceCheckpoint
  602. #endif
  603. #define OnPlayerLeaveRaceCheckpoint cp_OnPlayerLeaveRaceCheckpoint
  604. #if defined cp_OnPlayerLeaveRaceCheckpoint
  605.     forward cp_OnPlayerLeaveRaceCheckpoint(playerid);
  606. #endif
  607. /*====================================================================================================
  608.     native OnPlayerConnect(playerid);
  609.     > playerid      =       The id of the player.
  610.     Description:
  611.     * Hook into OnPlayerConnect and reset both race checkpoint and checkpoint variables.
  612. ====================================================================================================*/
  613. public OnPlayerConnect(playerid) {
  614.    
  615.     if(!IsPlayerConnected(playerid) || IsPlayerNPC(playerid))
  616.         return 0;
  617.        
  618.     cpData[playerid][cpId] = raceCpData[playerid][cpId] = raceCpData[playerid][cpType] = INVALID_CHECKPOINT_ID,
  619.     cpData[playerid][cpX] = cpData[playerid][cpY] = cpData[playerid][cpZ] = cpData[playerid][cpSize] =
  620.     raceCpData[playerid][cpX] = raceCpData[playerid][cpY] = raceCpData[playerid][cpZ] =
  621.     raceCpData[playerid][cpNextX] = raceCpData[playerid][cpNextY] = raceCpData[playerid][cpNextZ] =
  622.     raceCpData[playerid][cpSize] = 0.0000;
  623.  
  624.     #if defined cp_OnPlayerConnect
  625.         return cp_OnPlayerConnect(playerid);
  626.     #else
  627.         return 1;
  628.     #endif
  629. }
  630. #if defined _ALS_OnPlayerConnect
  631.     #undef OnPlayerConnect
  632. #else
  633.     #define _ALS_OnPlayerConnect
  634. #endif
  635. #define OnPlayerConnect cp_OnPlayerConnect
  636. #if defined cp_OnPlayerConnect
  637.     forward cp_OnPlayerConnect(playerid);
  638. #endif
  639. /*====================================================================================================
  640.     End of checkpoint include.
  641. ====================================================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement