SA-MP Forums Archive
How can i check if all zombies dead? - 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)
+--- Thread: How can i check if all zombies dead? (/showthread.php?tid=577091)



How can i check if all zombies dead? - KillerDVX - 08.06.2015

I have 2 teams.

TEAM_SURVIVANTS

and

TEAM_ZOMBIES.

I wan't to create a checkpoint when all zombies dead.

But how could i check that.. ?

Help !


Re: How can i check if all zombies dead? - SickAttack - 08.06.2015

Get the total amount of zombies once the game has started (save it in a variable), if a new zombie joins the game during the act, increase that amount by one. If one leaves, decrease it by one. If one dies, decrease it by one. And once there are no more zombies alive, create the checkpoint.

Or you could loop through all the players and check if there are any zombies left, and if the script finds at least one, stop the loop because the process doesn't need to continue as it will already return false because one zombie is alive.

This will require foreach, go get it if you do not have it yet:
pawn Код:
stock AreAllZombiesDead()
{
    new bool:alive = false;
    foreach(new i: Player)
    {
        if(pTeam[playerid] == TEAM_ZOMBIE)
        {
            alive = true;
            break;
        }
    }

    if(!alive) return true;
    return false;
}



Re : How can i check if all zombies dead? - KillerDVX - 08.06.2015

Now, if all zombies are dead, and i wanna to send to all players that they are dead,

What should i do?


Re: How can i check if all zombies dead? - jamesbond007 - 09.06.2015

pawn Код:
if(AreAllZombiesDead())
{
    SendClientMessageToAll(-1, "The zombies are all dead");
}



Re : How can i check if all zombies dead? - KillerDVX - 09.06.2015

Under OnPlayerDeath or..?


Re : How can i check if all zombies dead? - KillerDVX - 09.06.2015

Please Help ?


Re: How can i check if all zombies dead? - JaydenJason - 09.06.2015

Make a global timer for that, or it can go under onplayerdeath


Re: How can i check if all zombies dead? - DarkLouis - 09.06.2015

If you don't use foreach, you can do:

PHP код:


public Zombies()
{
    for(new 
0GetPlayerPoolSize(); <= ji++)
    {
        if(!
IsPlayerConnected(i)) continue;
        new 
zombie;
        if(
pTeam[i] == TEAM_ZOMBIE))
        {
            
zombie ++;
        }
    }
    return 
zombie;
}

public 
OnPlayerDeath(playeridkilleridreason)
{
    for(new 
0GetPlayerPoolSize(); <= ji++)
    {
        if(!
IsPlayerConnected(i)) continue;
        if(!
Zombies())
        {
            
SendClientMessage(i, -1"All zombies are dead!" )
        }
    }
    return 
1;




Re : How can i check if all zombies dead? - KillerDVX - 09.06.2015

I use foreach


Re : How can i check if all zombies dead? - KillerDVX - 09.06.2015

Help?