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)
+--- Thread: Timer problem (/showthread.php?tid=616950)



Timer problem - StR_MaRy - 13.09.2016

hey guys i have this timer on a rob but is still on 30 sec he wont go down like 29,28,27 etc...

Код HTML:
new RobSec = 0;
in the sistem i have this

Код HTML:
RobSec = 30;
so i can have a textdraw to know how much time i have

Код HTML:
format(string, sizeof(string), "Time Left: ~y~%d", RobSec);
			PlayerTextDrawSetString(playerid, Rob2Text[playerid], string);
why isn't working ? and staying at "Time Left: 30"


Re: Timer problem - SyS - 13.09.2016

create a timer that is repeating in 1 seconds and also set a var to value 30 and on each call (ie each second) of the public function called on the settimeEx decrement the value of var by one (var--) and on that public function format the string of text draw with this var and update


Re: Timer problem - JordanZaundd - 13.09.2016

You need a timer that repeats every second that calls a function to update the textdraw with the latest time. I've done so for you here:
PHP код:
new robTimer// For 'rob' command
new robClock 30// 30 seconds(will reduce by 1 every 1000ms)
CMD:rob(playerid)
{
    
//...
    
robTimer SetTimerEx("RobCounter"10001"d"playerid); // Creates timer to run 'RobCounter' every 1000ms/1s
    //If player leaves point without completing robbery, use "KillTimer(robTimer)"
    
SendClientMessage(playeridCOLOR_LIGHTRED"You have began to rob the business!"); // Alerts player they are robbing the business
    
TextDrawShowForPlayer(Rob2Text[playerid]); // Shows the countdown for the robbery.
    
return 1;
}
public 
RobCounter(playerid)
{
    new 
string[64];
    
format(stringsizeof(string), "Time Left: ~y~%d"robClock); // Formats the textdraw to show updated timer.
    
TextDrawSetString(Rob2Text[playerid], string); // Updates the textdraw with the string
    
robClock--; // Decreases clock by 1
    
if(robclock == 0)
    {
        
//...Let the player know he completed the robbery successfully and grant him his money,
    
}
    return 
1;
}
forward RobCounter(playerid);