How to detect the leader of a race
#1

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.
Reply
#2

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

GetXYInFrontOfPlayer?
Reply
#4

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));
}
Reply
#5

loop all players and see what player have highest IsQuading
Reply
#6

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!
Reply
#7

Anyone else?
Reply
#8

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;
}
Reply
#9

Thanks mate! I appreciate that
Reply
#10

Still need help with this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)