SA-MP Forums Archive
Issue with timer - 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: Issue with timer (/showthread.php?tid=626688)



Issue with timer - AndreiWow - 18.01.2017

Command:
Код:
CMD:reqmed(playerid, params[])
{
	new string[64], option[4], item[5], amount[5];
	
	sscanf(params, "sss", option, item, amount);
	
	if(isnull(option))
	{
	    SendClientMessage(playerid, COLOR_GREY, "USAGE: /reqmed <optiune>");
	    SendClientMessage(playerid, COLOR_GREY, "OPTIUNI: brokenleg");
	    return 1;
	}
	if (!strcmp(option, "brokenleg"))
  	{
	    if(pLegBroken[playerid] == true)
	    {
	        SetPlayerPos(playerid, 1506.3864,-1530.9393,1971.8003);
	        TogglePlayerControllable(playerid, 0);
	        LoopingAnim(playerid, "CRACK", "crckdeth2", 4.0, 1, 0, 0, 0, 0);
	        SendClientMessage(playerid, COLOR_GREEN, "Ai fost trimis in sala de operatie, te rugam sa astepti.");
			CountDownTimer = SetTimerEx("CountDown", 1000, false, "i", playerid);
		}
		else
		{
		    SendClientMessage(playerid, COLOR_GREY, "Nu ai picioarele ranite.");
		}
	}
  	return 1;
}
Timer:
Код:
forward CountDown(playerid);
public CountDown(playerid)
{
     CountDownVar--;
     new str[128];
     if(CountDownVar == 0)
     {
            KillTimer(CountDownTimer);
            CountDownVar = 4;
            if(pLegBroken[playerid] ==  true)
            {
                pLegBroken[playerid] = false;
                SendClientMessage(playerid, 0x33AA33AA, "> Ai fost eliberat din spital, piciorul tau este mai bine.");
				SetPlayerPos(playerid, 1502.5439,-1546.3174,1970.7870);
				TogglePlayerControllable(playerid, 1);
			}
     }
     else
     {
           format(str, sizeof(str), "Timp ramas in operatie: %d", CountDownTimer);
           GameTextForPlayer(playerid, str, 1000, 1);
     }
     return 1;
}
Why is the time raising instead of going down? From 40 it got to 370, I want it to go down from 50 seconds to zero...


Re: Issue with timer - Sew_Sumi - 18.01.2017

Where do you actually set CountDownVar?

Rather than doing =0, you could put <1... Then it won't "miss" if the timer skips somehow.


Re: Issue with timer - SyS - 19.01.2017

timer should set to repeat. you are passing false Boolean to repeat arguement. Also make sure count down var has initial value before timer calls.

ps: I'm on phone so I cant type the codes sorry.


Re: Issue with timer - Nate4 - 19.01.2017

Should CountDownTimer as shown here:

PHP код:
format(strsizeof(str), "Timp ramas in operatie: %d"CountDownTimer); 
Not be CountDownVar?

PHP код:
format(strsizeof(str), "Timp ramas in operatie: %d"CountDownVar); 
It seems you were accidentally displaying the timer ID rather than the seconds variable.

Also, make the change that Sreyas mentioned, so that the function repeats every second..

PHP код:
CountDownTimer SetTimerEx("CountDown"1000true"i"playerid); 



Re: Issue with timer - Sew_Sumi - 19.01.2017

Good spotting Nate4... That could cause the sense of the time being 360+.


Re: Issue with timer - AndreiWow - 19.01.2017

Thanks alot guys!