How to get the last person!
#1

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

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

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

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)