How can i check if all zombies dead?
#1

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

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;
}
Reply
#3

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

What should i do?
Reply
#4

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

Under OnPlayerDeath or..?
Reply
#6

Please Help ?
Reply
#7

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

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;

Reply
#9

I use foreach
Reply
#10

Help?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)