Never worked with timers so help me please
#1

Hello,

I wanna make a timer for zombies, that if they just used ALT to bite someone they have to wait 30 secs.

pawn Код:
new NearestPlayer = GetClosestPlayer(playerid);
    if(newkeys & KEY_WALK)
    {
        if(Player[playerid][Zombie] == 1)
        {
            if(GetDistanceBetweenPlayers(NearestPlayer, playerid) < 4)
            {
                if(Player[NearestPlayer][Infected] == 0)
                {
                    Player[NearestPlayer][Infected] = 1;
                }
                else if(Player[NearestPlayer][Infected] == 1)
                {
                    Player[NearestPlayer][Zombie] = 1;
                    Player[NearestPlayer][Human] = 0;
                    Player[NearestPlayer][Infected] = 0;
                }
            }
            else
            {
                GameTextForPlayer(playerid, "~w~There is no one nearby!", 3500, 3);
            }
        }
    }
Anyone can help me with that timer?
Reply
#2

pawn Код:
// simply declare a global variable
new HasToWait[MAX_PLAYERS];
/*
    - if HasToWait = 0 (Default) then a player/zombie can bite.
    - if HasToWait = 1 then a player/zombie can not bite.
*/



new NearestPlayer = GetClosestPlayer(playerid);
if(newkeys & KEY_WALK)
{
    if(Player[playerid][Zombie] == 1)
    {
        if(HasToWait[playerid] != 1)
        {
            if(GetDistanceBetweenPlayers(NearestPlayer, playerid) < 4)
            {
                if(Player[NearestPlayer][Infected] == 0)
                {
                    Player[NearestPlayer][Infected] = 1;
                    HasToWait[playerid] = 1; // I'm not sure if this's the right place. If this is the part which the zombie bites someone then it's ok
                    SetTimerEx("ResetZombieStatus", 30000, false, "d", playerid);
                }
                else if(Player[NearestPlayer][Infected] == 1)
                {
                    Player[NearestPlayer][Zombie] = 1;
                    Player[NearestPlayer][Human] = 0;
                    Player[NearestPlayer][Infected] = 0;
                }
            }
        }
        else
        {
            GameTextForPlayer(playerid, "~r~You have to wait before another bite!", 3000, 3);
        }
    }
    else
    {
        GameTextForPlayer(playerid, "~w~There is no one nearby!", 3500, 3);
    }
}

forward ResetZombieStatus(playerid);

public ResetZombieStatus(playerid)
{
    HasToWait[playerid] = 0; // resetting it 0 so he can bite again
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)