Timer problem
#1

helo all
my problem is that i've make a timer but it doesn't work
can some one help me for that pls
Код:
forward infectedtimer(playerid);


public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if((newkeys & KEY_FIRE) && (team[playerid] == 2))
	{
		if(GetDistanceBetweenPlayers(playerid,target) <= 1)
		{
		    SetTimer("infectedtimer", 5000, 1);
                 }
         }
}


public infectedtimer(playerid)
{
    new Float:hp;
    if(team[playerid] == 2)
		{
		    GetPlayerHealth(playerid,hp);
	            SetPlayerHealth(playerid, hp-7);
	            SendClientMessage(playerid,GREEN,"you turn to a zombie.");
 		}
    return 1;
}
Reply
#2

https://sampwiki.blast.hk/wiki/SetTimerEx

Pawn isnt magic, so it cant tell which player you mean by "playerid". Use SetTimerEx to specify which player you actually mean :P.
Reply
#3

mmm can you pls give me an example
cause i want to make a timer that make you loose your HP if you are "infected" & i never use SetTimerEx
Reply
#4

You have an example in the wiki page.

pawn Код:
SetTimerEx("infectedtimer", 5000, true, "d", playerid);

PS: the code posted by me above creates a repeting timer (automatic function call at every 5000 ms). You should consider reading the link that Kyosaur posted for you and change that "true" value to "false" if you just want to delay the execution by 5000 ms.
Reply
#5

well now i have fix this thanks to you guys
BUT i have an other problem
KillTimer wont work !! when a player take anti virus he still loos HP ... any solution pls
Reply
#6

Quote:
Originally Posted by Amine_Mejrhirrou
Посмотреть сообщение
well now i have fix this thanks to you guys
BUT i have an other problem
KillTimer wont work !! when a player take anti virus he still loos HP ... any solution pls
Its because the parameter to kill timer is the id returned from SetTimer(Ex) which you dont seem to be storing.

https://sampwiki.blast.hk/wiki/KillTimer
Reply
#7

New infect_timer[MAX_PLAYERS];

infect_timer[playerid] = SetTimerEx("infectedtimer", 5000, true, "d", playerid);

KillTimer(infect_timer[playerid]);
Reply
#8

gonna try what ikkentim said & i'll give you an answer
Reply
#9

that's what i've made

forward infectedtimer(playerid);

new timer1;

KillTimer(timer1);

timer1 = SetTimerEx("infectedtimer", 5000, true, "d", playerid);

public infectedtimer(playerid)

still wont work
Reply
#10

can some one give me an exeple of infection timer pls
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)