How to get the last person!
#10

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.
}
Reply


Messages In This Thread
How to get the last person! - by Flokx - 25.01.2015, 15:19
Re: How to get the last person! - by Smileys - 25.01.2015, 15:23
Re: How to get the last person! - by Stanford - 25.01.2015, 15:24
Re: How to get the last person! - by Flokx - 25.01.2015, 15:33
Re: How to get the last person! - by Stanford - 25.01.2015, 16:49
Re: How to get the last person! - by Flokx - 25.01.2015, 17:13
Re: How to get the last person! - by Smileys - 25.01.2015, 17:18
Re: How to get the last person! - by Flokx - 25.01.2015, 17:34
Re: How to get the last person! - by Flokx - 25.01.2015, 18:16
Re: How to get the last person! - by Smileys - 25.01.2015, 19:08

Forum Jump:


Users browsing this thread: 1 Guest(s)