Issue with timer
#1

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...
Reply
#2

Where do you actually set CountDownVar?

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

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.
Reply
#4

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); 
Reply
#5

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

Thanks alot guys!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)