[HELP]Race checkpints help
#11

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.

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 
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:
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
); 
Using this method you can just change the contents of the array without having to worry about anything else.
Reply


Messages In This Thread
[HELP]Race checkpints help - by fuckingcruse - 16.03.2015, 12:54
Re: [HELP]Race checkpints help - by Darrenr - 16.03.2015, 14:33
Re: [HELP]Race checkpints help - by fuckingcruse - 17.03.2015, 16:26
Re: [HELP]Race checkpints help - by CalvinC - 17.03.2015, 16:34
Re: [HELP]Race checkpints help - by fuckingcruse - 17.03.2015, 16:47
Re: [HELP]Race checkpints help - by CalvinC - 17.03.2015, 17:08
Re: [HELP]Race checkpints help - by fuckingcruse - 18.03.2015, 02:35
Re: [HELP]Race checkpints help - by fuckingcruse - 18.03.2015, 16:56
Re: [HELP]Race checkpints help - by CalvinC - 18.03.2015, 16:58
Re: [HELP]Race checkpints help - by fuckingcruse - 18.03.2015, 17:02
Re: [HELP]Race checkpints help - by Vince - 18.03.2015, 17:52
Re: [HELP]Race checkpints help - by fuckingcruse - 19.03.2015, 10:37
Re: [HELP]Race checkpints help - by fuckingcruse - 19.03.2015, 11:45
AW: Re: [HELP]Race checkpints help - by Kaliber - 19.03.2015, 11:50
Re: [HELP]Race checkpints help - by fuckingcruse - 19.03.2015, 11:53

Forum Jump:


Users browsing this thread: 1 Guest(s)