SA-MP Forums Archive
Get the last standing player in the game - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Get the last standing player in the game (/showthread.php?tid=199914)



Get the last standing player in the game - Koppa, - 16.12.2010

I'm trying to find a way to do it, here's is what I have:

Код:
new player_count = 0;
	for(new i = 0; i < MAX_PLAYERS; i++)
	{
	    if(!GetPlayerState(i) == PLAYER_STATE_SPECTATING)
		{
			player_count++;
		}
	}
	if(player_count == 0)
	{
	    ///--we have a NO winner, everyone is died
	}
	else if(player_count == 1)
	{
		///--we have a single winner
	}
	else if(player_count > 1)
	{
	    ///--there's more than one player alive, continue the game.
	}
but this code can't get the player's name! What can I do?


Re: Get the last standing player in the game - XePloiT - 17.12.2010

try like this:
pawn Код:
new player_count = 0;
    for(new i = 0; i < MAX_PLAYERS; i++) // i recommend to use foreach
        if(!GetPlayerState(i) == PLAYER_STATE_SPECTATING)
            player_count++;
    if(player_count == 0)
    {
        ///--we have a NO winner, everyone is died
    }
    else if(player_count == 1)
    {
        ///--we have a single winner
        new pn[24];
        foreah(Player,i) // or use for however you want...
            if(GetPlayerState(i)!=PLAYER_STATE_SPECTATING)
                GetPlayerName(i,pn,sizeof(pn)); // pn now equals the players name
    }
    else if(player_count > 1)
    {
        ///--there's more than one player alive, continue the game.
    }