Timer problem
#1

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

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
Reply
#3

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


Forum Jump:


Users browsing this thread: 1 Guest(s)