Race position - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Race position (
/showthread.php?tid=462590)
Race position -
knackworst - 07.09.2013
Hello
I'm working on a race system and it's almost finished, but one of the last functions I want to implent is a position system.
Now I know this has been asked before but I couldn't find a solution in another FS tutorial...
So here's what I was thinking to do
pawn Код:
public RaceTimeS(raceid)
{
for(new i; i < MAX_PLAYERS; i++)
{
if(PInfo[i][Racing] != raceid) continue; //Find for the players who are in the race
{
}
}
return 1;
}
so that's a timer, that gets called every second, in the race.
but from there I'm kinda stuck.. I was thinking about maybe looping through all the racers and see which players at at the furthest checkpoint, and then within that group checking who is the closest to the checkpoint?
But I have no idea how to do this...
Any help?
Thanks in advance
Re: Race position -
knackworst - 07.09.2013
Here's what I came up with, but I can't test it unfortunately
pawn Код:
stock GetPlayerPosition(playerid, raceid)
{
//We are going to count the amount of players in front of you
new index = 0; //Count the amount of players in front of you, set to 0 because if noone is infront it's index +1 -> you are first
new PlayerPos[MAX_PLAYERS];
for(new j = 0; j < MAX_PLAYERS; j++) //everyone
{
if(PInfo[j][Racing] == raceid) //who is in the race
{
if(j != playerid) // who is not the checked player
{
if(PInfo[playerid][RaceCheckpoint] < PInfo[j][RaceCheckpoint]) //who is in front of the player
{
index++; //for everyone who is in front of the player index goes ++
}
if(PInfo[playerid][RaceCheckpoint] == PInfo[j][RaceCheckpoint]) //who is in the same section as the player
{
new PlayerCheckPoint = PInfo[playerid][RaceCheckpoint];
new ElseCheckPoint = PInfo[j][RaceCheckpoint];
if(GetPlayerDistanceFromPoint(playerid, RaceInfo[raceid][checkpointx][PlayerCheckPoint]+1,RaceInfo[raceid][checkpointy][PlayerCheckPoint]+1, RaceInfo[raceid][checkpointz][PlayerCheckPoint]+1) > GetPlayerDistanceFromPoint(j, RaceInfo[raceid][checkpointx][ElseCheckPoint]+1, RaceInfo[raceid][checkpointy][ElseCheckPoint]+1, RaceInfo[raceid][checkpointz][ElseCheckPoint]+1))
{
index++;
}
}
}
}
}
PlayerPos[playerid] = index +1;
return PlayerPos[playerid];
}