2020-11-06, 11:04 AM
Code:
// Change 20 to max race entries or MAX_PLAYERS if it's not limited
// Also, this works if you can have only one race started at the time, otherwise add [x] to the iterator,ex:
//new Iterator:RaceMembers[5]<20>;
new Iterator: RaceMembers<20>;
CMD:enter(playerid, params[])
{
if(Iter_Contains(RaceMembers, playerid))
return SendClientMessage(playerid, -1, "You're already in the race!");
if(RaceStarted == true)
{
TogglePlayerSpectating(playerid, 1);
PlayerSpectatePlayer(playerid, Iter_Random(RaceMembers));
}
else if(RaceStarted == false)
{
// Add player to the RaceMembers iterator, don't forget to remove them via Iter_Remove(RaceMembers, playerid); once the race is over/they exit/disconnect or they'll still be treated as the race member
new success = Iter_Add(RaceMembers, playerid);
if(!success)
return SendClientMessage(playerid, -1, "Ths race is already full!");
// Enter race code...
}
}
Also, don't forget to add PlayerSpectatePlayer(playerid, Iter_Random(RaceMembers)); to the OnPlayerKeyStateChange
Using Pawn.CMD?
If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.