Never worked with timers so help me please - 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: Never worked with timers so help me please (
/showthread.php?tid=353758)
Never worked with timers so help me please -
Stefand - 24.06.2012
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?
Re: Never worked with timers so help me please -
[KHK]Khalid - 24.06.2012
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;
}