SA-MP Forums Archive
How to get the last person! - 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 get the last person! (/showthread.php?tid=559841)



How to get the last person! - Flokx - 25.01.2015

So when a player join /event I goes to the code and set player InEvent = 1. So 10 players can join in one time. Then when everyone dies how I see who is the last one?


Re: How to get the last person! - Smileys - 25.01.2015

uhh could you explain it abit more? I'm not quite sure what you mean.


Re: How to get the last person! - Stanford - 25.01.2015

Well,under OnPlayerDeath, clear the InEvent to 0 and then do a command to check who's still inside event.

pawn Код:
CMD:eventsurvivors(playerid, params[])
{
        new string[MAX_PLAYER_NAME + 30], playername[MAX_PLAYER_NAME];
       foreach(new i : Player)
       {
              GetPlayerName(i, playername, sizeof(playername));
             if(InEvent[i]) { format(string,sizeof(string), "%s is at event.", playername); SendClientMessage(playerid, -1, string); }
        }
        return 1;
}
I hope I helped any feedback would be appreciated!


Re: How to get the last person! - Flokx - 25.01.2015

Thanks for the code Stanford but this is not what I wanted. I meant, OnPlayerUpdate I wanna see the last person standing and SendClientMessageToAll that he won the event. Not with a cmd
Smileys I guess now you know what I meant


Re: How to get the last person! - Stanford - 25.01.2015

Why would you use a callback that calls itself for about 30 times a second, use a timer.
The solution goes for your issue that you explained is almost the same; Create a new variable StillAlive[playerid] and set it to '1' when the player joins the event and when he dies under OnPlayerDeath set it to '0' and keep the timer see if more than one player has StillAlive[playerid]; if so then theres no winner still, if not then announce the winner using a formatted message!


Re: How to get the last person! - Flokx - 25.01.2015

I get it and nice idea that is. Can you please show me a little script :O


Re: How to get the last person! - Smileys - 25.01.2015

I'll help ya when I get home, cba coding on phone lol


Re: How to get the last person! - Flokx - 25.01.2015

Thanks but I am still waiting for Sandford to share a code with me


Re: How to get the last person! - Flokx - 25.01.2015

Bump


Re: How to get the last person! - Smileys - 25.01.2015

pawn Код:
new bool: InEvent[ MAX_PLAYERS char ]; // set this to true if someone is inside the event.

stock GetLastPerson( )
{
    new count = 0, last_player = -1; // declaring some variables.
    foreach( new i : Player) // looping through the players.
    {
        if( InEvent{ i } )
        {
            count++; // increasing the counter to see if there's more than 1 player in the game.
            last_player = i; // assigning the player's id to last_player so we can then use it later on outside the loop.
        }
    }
    if( count == 1 ) // only 1 player is left.
        return last_player; // we return the player's id.

    else // there's more than 1 player left.
        return -1; // so we return -1, as -1 is never a playerid.
}

// now like
new last_player = GetLastPerson( ); // grabbing the last person if there is only 1 left.
if( last_player != -1 ) // checking if the function actually returned a playerid instead of -1.
{
    new name[ MAX_PLAYER_NAME ]; // declaring a variable to store the player's name in.
    GetPlayerName( last_player, name, sizeof( name ) ); // grabbing the name of the player who won.

    new str[ 48 ]; // change this to a different size if you edit the message.
    format( str, sizeof( str ), "%s has won!", name ); // formatting the mesage.
    SendClientMessageToAll( -1, str ); // sending the message to everyone.
}