SA-MP Forums Archive
[HELP]Last Man Alive - 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: [HELP]Last Man Alive (/showthread.php?tid=109809)



[HELP]Last Man Alive - Tigerbeast11 - 22.11.2009

How to make a last man alive?

I made it so it doesnt allow respawns but, how to make a message saying "You win!" for those who stay alive until 8 mins?



P.S Need more info about what Im saying? Just ask =D


Re: Last Man Alive - Tigerbeast11 - 22.11.2009

Quote:
Originally Posted by Seif_
First, make sure you have a variable to check if someone is dead or not. Set it to true in OnPlayerDeath and false in OnPlayerSpawn and wherever that can respawn you if it's possible.
Then, after 8 minutes, make a loop to check how many aren't dead.
pawn Код:
new alivecount, survivor;
for(new i, m = GetMaxPlayers(); i < m; i++)
{
    if (!IsPlayerConnected(i)) continue;
    if (!Dead[i])
    {
        alivecount++;
        survivor = i;
    }
}
if (alivecount) SendClientMessage(survivor, GREEN, "You win!");
I understand your first bit, but the code sounds giberis to me =S


Re: [HELP]Last Man Alive - Tigerbeast11 - 22.11.2009

Quote:
Originally Posted by Seif_
Quote:
Originally Posted by Tigerbeast11
Quote:
Originally Posted by Seif_
First, make sure you have a variable to check if someone is dead or not. Set it to true in OnPlayerDeath and false in OnPlayerSpawn and wherever that can respawn you if it's possible.
Then, after 8 minutes, make a loop to check how many aren't dead.
pawn Код:
new alivecount, survivor;
for(new i, m = GetMaxPlayers(); i < m; i++)
{
    if (!IsPlayerConnected(i)) continue;
    if (!Dead[i])
    {
        alivecount++;
        survivor = i;
    }
}
if (alivecount) SendClientMessage(survivor, GREEN, "You win!");
I understand your first bit, but the code sounds giberis to me =S
It's simple. You're making a loop to make a check on all current players.
If they're not connected, you skip. When they are, it checks if they are not dead(!Dead[i] is the same as Dead[i] == 0).
When they're not dead, it increases the amount of players alive in the script and sets "survivor" to the player alive.
Logically, if there's only 1 alive, it's no problem to do that. Which is why at the end, outside the loop, we check if there's only 1 survivor(alivecount is the same as alivecount == 1).
Nice! But i dont wanna check for the last survivor, i wanna check for the last survors at the end of 8 mins.


Re: [HELP]Last Man Alive - Tigerbeast11 - 23.11.2009

Quote:
Originally Posted by Seif_
pawn Код:
for(new i, m = GetMaxPlayers(); i < m; i++)
{
    if (!IsPlayerConnected(i)) continue;
    if (!Dead[i])
    {
        GameTextForPlayer(playerid, "You win!", 5000, 3);
    }
}
Sorry, but I don't know what to do...

Where do i put that?

I your pm, you said set a timer, what sort of timer?


Sorry, I only started scripting 5 months ago