18.03.2015, 17:52
Geez, just put everything in one big array so you can use the array index to set the next checkpoint. Checking every single checkpoint by hand is just a big waste of time and very hard to maintain. When making a change, you only want to do it one place. Not in several different places.
In OnPlayerEnterRaceCheckpoint, you increment the above player variable by 1. Then you check if it is equal to "sizeof(gCheckpoints)" to check if they've gone through all checkpoints (and thus have finished the race).
If this isn't the case, you proceed to check if the variable is equal to "sizeof(gCheckpoints) - 1" so you can set the "finish flag" on the last checkpoint and prevent an out of bounds error (nextx/y/z referring to a checkpoint that does not exist).
In any other case, you just continue with a normal checkpoint, like so:
Using this method you can just change the contents of the array without having to worry about anything else.
PHP Code:
new const Float:gCheckpoints[][3] = {
{-1145.5658,-1045.6901,128.5027},
{-1183.2870,-1002.4471,128.5025},
// etc, etc
{-1145.9674,-1034.9795,128.5025}
};
new gCurrentPlayerCheckpoint[MAX_PLAYERS] = {0, ...}; // this stores the id of the currently visible checkpoint
If this isn't the case, you proceed to check if the variable is equal to "sizeof(gCheckpoints) - 1" so you can set the "finish flag" on the last checkpoint and prevent an out of bounds error (nextx/y/z referring to a checkpoint that does not exist).
In any other case, you just continue with a normal checkpoint, like so:
PHP Code:
SetPlayerRaceCheckpoint
(
playerid,
0, // type
gCheckpoints[gCurrentPlayerCheckpoint[playerid]][0], // x
gCheckpoints[gCurrentPlayerCheckpoint[playerid]][1], // y
gCheckpoints[gCurrentPlayerCheckpoint[playerid]][2], // z
gCheckpoints[gCurrentPlayerCheckpoint[playerid] + 1][0], //nextx
gCheckpoints[gCurrentPlayerCheckpoint[playerid] + 1][1], //nexty
gCheckpoints[gCurrentPlayerCheckpoint[playerid] + 1][2], // nextz
6.0 // size
);