SA-MP Forums Archive
Timer problem - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Timer problem (/showthread.php?tid=210067)



Timer problem - Amine_Mejrhirrou - 12.01.2011

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;
}



Re: Timer problem - Kyosaur - 12.01.2011

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.


Re : Timer problem - Amine_Mejrhirrou - 12.01.2011

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


Re: Timer problem - xxmitsu - 12.01.2011

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.


Re : Timer problem - Amine_Mejrhirrou - 12.01.2011

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


Re: Re : Timer problem - Kyosaur - 12.01.2011

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


Re: Timer problem - ikkentim - 12.01.2011

New infect_timer[MAX_PLAYERS];

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

KillTimer(infect_timer[playerid]);


Re : Timer problem - Amine_Mejrhirrou - 13.01.2011

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


Re : Timer problem - Amine_Mejrhirrou - 13.01.2011

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


Re : Timer problem - Amine_Mejrhirrou - 13.01.2011

can some one give me an exeple of infection timer pls