SA-MP Forums Archive
How to detect the leader of a race - 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: How to detect the leader of a race (/showthread.php?tid=311026)



How to detect the leader of a race - Luis- - 14.01.2012

How can I do this? Here's the code.
pawn Код:
public OnPlayerEnterRaceCheckpoint(playerid)
{
    foreach(Player, i)
    {
        if(PlayerInQuadRace(i))
        {
            new Winner = i;
            new quad1 = QuadCheckpoints[i]++;
            new string[128];
            if(IsQuading[i] == 1)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(playerid, 0, -2207.9607,-2091.2292,76.7566, -2119.5029,-1952.6241,99.1260, 5.0);
                IsQuading[i] = 2;
            }
            else if(IsQuading[i] == 2)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2119.5029,-1952.6241,99.1260, -2126.6528,-1902.5149,113.9288, 5.0);
                IsQuading[i] = 3;
            }
            else if(IsQuading[i] == 3)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2126.6528,-1902.5149,113.9288, -2221.3625,-2050.3083,119.3457, 5.0);
                IsQuading[i] = 4;
            }
            else if(IsQuading[i] == 4)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2221.3625,-2050.3083,119.3457, -2429.5652,-2087.6035,122.6606, 5.0);
                IsQuading[i] = 5;
            }
            else if(IsQuading[i] == 5)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2429.5652,-2087.6035,122.6606, -2522.4373,-1977.1553,172.0493, 5.0);
                IsQuading[i] = 6;
            }
            else if(IsQuading[i] == 6)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2522.4373,-1977.1553,172.0493, -2648.2371,-1797.8871,231.5805, 5.0);
                IsQuading[i] = 7;
            }
            else if(IsQuading[i] == 7)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2648.2371,-1797.8871,231.5805, -2554.5425,-1863.8778,285.0632, 5.0);
                IsQuading[i] = 8;
            }
            else if(IsQuading[i] == 8)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2554.5425,-1863.8778,285.0632, -2589.1680,-1790.0142,317.7771, 5.0);
                IsQuading[i] = 9;
            }
            else if(IsQuading[i] == 9)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2589.1680,-1790.0142,317.7771, -2546.4878,-1799.8230,372.5261, 5.0);
                IsQuading[i] = 10;
            }
            else if(IsQuading[i] == 10)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2546.4878,-1799.8230,372.5261, -2529.7617,-1709.2963,401.5350, 5.0);
                IsQuading[i] = 11;
            }
            else if(IsQuading[i] == 11)
            {
                DisablePlayerRaceCheckpoint(i);
                format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", quad1, Name(Winner));
                SetPlayerRaceCheckpoint(i, 0, -2529.7617,-1709.2963,401.5350, -2452.4207,-1755.9547,421.2779, 5.0);
                IsQuading[i] = 12;
            }
            GameTextForPlayer(i, string, 5355234364634634, 3);
        }
    }
    return 1;
}
Yeah, it's long, sorry.


Re: How to detect the leader of a race - Luis- - 14.01.2012

I'm SERIOUSLY needing this, if I get a infraction for bumping this then i'm sorry.


Re: How to detect the leader of a race - fiki574 - 14.01.2012

GetXYInFrontOfPlayer?


Re: How to detect the leader of a race - Vince - 14.01.2012

That is indeed some really inefficient coding.

To detect the position, you will need to do a few things: First, loop through all players to see who's the furthest in the race. If two or more players are at the same checkpoint, measure the distance between that checkpoint and each player separately to determine who's closer.

pawn Код:
stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
    x1 -= x2;
    y1 -= y2;
    z1 -= z2;
    return floatsqroot((x1 * x1) + (y1 * y1) + (z1 * z1));
}



Re: How to detect the leader of a race - StreetGT - 14.01.2012

loop all players and see what player have highest IsQuading


Re: How to detect the leader of a race - Luis- - 14.01.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
That is indeed some really inefficient coding.

To detect the position, you will need to do a few things: First, loop through all players to see who's the furthest in the race. If two or more players are at the same checkpoint, measure the distance between that checkpoint and each player separately to determine who's closer.

pawn Код:
stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
    x1 -= x2;
    y1 -= y2;
    z1 -= z2;
    return floatsqroot((x1 * x1) + (y1 * y1) + (z1 * z1));
}
I'm hopeless with coords, what would I put in the Float1 etc? I need to learn someday. Thanks!


Re: How to detect the leader of a race - Luis- - 15.01.2012

Anyone else?


Re: How to detect the leader of a race - coole210 - 15.01.2012

I took some time to fix up your function, making it cleaner

pawn Код:
new Float:QuadPositions[][6] = {
{ -2207.9607,-2091.2292,76.7566, -2119.5029,-1952.6241,99.1260 },
{ -2119.5029,-1952.6241,99.1260, -2126.6528,-1902.5149,113.9288 },
{ -2126.6528,-1902.5149,113.9288, -2221.3625,-2050.3083,119.3457 },
{ -2221.3625,-2050.3083,119.3457, -2429.5652,-2087.6035,122.6606 },
{ -2429.5652,-2087.6035,122.6606, -2522.4373,-1977.1553,172.0493 },
{ -2522.4373,-1977.1553,172.0493, -2648.2371,-1797.8871,231.5805 },
{ -2648.2371,-1797.8871,231.5805, -2554.5425,-1863.8778,285.0632 },
{ -2554.5425,-1863.8778,285.0632, -2589.1680,-1790.0142,317.7771 },
{ -2589.1680,-1790.0142,317.7771, -2546.4878,-1799.8230,372.5261 },
{ -2546.4878,-1799.8230,372.5261, -2529.7617,-1709.2963,401.5350  },
{ -2529.7617,-1709.2963,401.5350, -2452.4207,-1755.9547,421.2779 }
};

public OnPlayerEnterRaceCheckpoint(playerid)
{
    new string[256];
    foreach(Player, i)
    {
        if(PlayerInQuadRace(i))
        {
            QuadCheckpoints[i]++;
            DisablePlayerRaceCheckpoint(i);
            format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~QUAD RACING~n~~r~Checkpoint: ~w~%d/15 ~r~Leader: ~w~%s", QuadCheckponts[i], Name(i));
            SetPlayerRaceCheckpoint(playerid, 0, QuadPositions[IsQuading[i]][0], QuadPositions[IsQuading[i]][1], QuadPositions[IsQuading[i]][2], QuadPositions[IsQuading[i]][3], QuadPositions[IsQuading[i]][4], QuadPositions[IsQuading[i]][5], 5.0);
            GameTextForPlayer(i, string, 5355234364634634, 3);
            IsQuading[i]++;
            if(IsQuading[i] == 11) {
                IsQuading[i] = 0;
            }
        }
    }
    return 1;
}



Re: How to detect the leader of a race - Luis- - 15.01.2012

Thanks mate! I appreciate that


Re: How to detect the leader of a race - Luis- - 15.01.2012

Still need help with this.