25.01.2015, 15:19
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?
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;
}
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.
}