SA-MP Forums Archive
Timer doesn't stop - 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: Timer doesn't stop (/showthread.php?tid=574295)



Timer doesn't stop - pollo97 - 15.05.2015

Hi everyone, im making jail command using a timer with repeating true, but when i try to cut off the timer it doesn't.
Here the script.
Код:
stock CheckJail(playerid)
	{
		new time[20];
		if(PlayerData[playerid][pJailTime]==0)
		{
			SendClientMessage(playerid,BIANCO,"Jail finito");
			SetPlayerPos(playerid,2127.7607,2360.1333,10.8203);
			PlayerTextDrawHide(playerid,JailRemainTime[playerid]);
			SetPlayerVirtualWorld(playerid,0);
			KillTimer(JailTimer[playerid]);
		}
		else
		{
			PlayerTextDrawHide(playerid,JailRemainTime[playerid]);
			format(time,sizeof(time),"%d minuti rimanenti",PlayerData[playerid][pJailTime]);
			PlayerTextDrawSetString(playerid,JailRemainTime[playerid],time);  
			PlayerTextDrawShow(playerid,JailRemainTime[playerid]);
		}

	}
This function should kill timer if jail time is 0, else refresh textdraw.


Код:
stock JailTimeLeft(playerid,time,bool:First)
	{
		new hour,minute;
		new tsjail;
		gettime(hour,minute);
		tsjail=(hour*60)+minute;
		printf("%d %d\n",tsjail,tsjailPlusOne[playerid]);
		if(tsjail==tsjailPlusOne[playerid]||First==true)
		{
			if(First)
			{
				TimeForSjail[playerid]=(hour*60)+time+minute;
			}
			tsjailPlusOne[playerid]=(hour*60)+minute+1;
			PlayerData[playerid][pJailTime]=TimeForSjail[playerid]-tsjail;
			CheckJail(playerid);
			printf("%d %d %d\n",PlayerData[playerid][pJailTime],tsjail,tsjailPlusOne[playerid]);
		}
         }
This function get the remaining time.

Код:
JailTimeLeft(id,PlayerData[id][pJailTime],true);
JailTimer[id] = SetTimerEx("WaitTime",1000,true,"ii",id,PlayerData[id][pJailTime]);
When /jail is perform

Код:
forward WaitTime(playerid,time);
	public WaitTime(playerid,time)
	{
		JailTimeLeft(playerid,time,false);
	}
The call of JailTimeLeft every second for refresh time.

How to fix this timer problem?


Re: Timer doesn't stop - Azula - 15.05.2015

JailTimer[id] = SetTimerEx("WaitTime",1000,true,"if",id,PlayerData[id][pJailTime]);


Re: Timer doesn't stop - Joe Staff - 15.05.2015

Try if jail time <= 0


Re: Timer doesn't stop - pollo97 - 15.05.2015

Quote:
Originally Posted by Azula
Посмотреть сообщение
JailTimer[id] = SetTimerEx("WaitTime",1000,true,"if",id,PlayerData[id][pJailTime]);
Umm... Why i should set PlayerData[id][pJailTime] as a float? It is an integer


Re: Timer doesn't stop - pollo97 - 15.05.2015

Quote:
Originally Posted by Joe Staff
Посмотреть сообщение
Try if jail time <= 0
It doesn't work, the timer keep run also if the player disconnect from server.
But i kill timer when player disconnect too.