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=593400)



Timer problem - Sh4d0w2 - 05.11.2015

Ok I have this code that I got from old post :

PHP код:
new TimeTimeMTimeS;
new 
Text:Textdraw0
PHP код:
Textdraw0 TextDrawCreate(605.0,25.0,"5:00");
TextDrawBackgroundColor(Textdraw00x000000AA);
TextDrawFont(Textdraw03);
TextDrawLetterSize(Textdraw00.5,1.5);
TextDrawAlignment(Textdraw0,3);
TextDrawSetOutline(Textdraw02);
TextDrawSetProportional(Textdraw01);
TextDrawColor(Textdraw0,0xFFFFFFFF);
TimeM 5;
TimeS 0;
Time SetTimer("UpdateTime",1000true); 
PHP код:
TextDrawShowForPlayer(playeridTextdraw0); 
PHP код:
forward UpdateTime();
public 
UpdateTime()
{
  new 
Str[34];
  
TimeS --;
  if(
TimeM == && TimeS == 0)
  {
    
KillTimer(Time);
  }
  if(
TimeS == -1)
  {
    
TimeM--;
    
TimeS 59;
  }
  
format(Strsizeof(Str), "%02d:%02d"TimeMTimeS);
  
TextDrawSetString(Textdraw0Str);
  return 
1;

I want to make the textdraw start countdown from 5 minutes.But when I try IG its start from 4:30.


Re: Timer problem - iKarim - 05.11.2015

Can you kindly explain more?
I can't understand what you mean.


Re: Timer problem - Sh4d0w2 - 05.11.2015

Ive got all this code from old topic how to make timer textdraw.So I copy all of them and tried it in my server and its work.But as I know from that old post,I only need to change the
PHP код:
TimeM 5;
TimeS 0
to change the minutes and seconds.But when I tried it to change to 5 the textdraw start the countdown from 4:30.Thats the problem.


Re: Timer problem - iKarim - 05.11.2015

PHP код:
TimeM 5;
TimeS 30



Re: Timer problem - Sh4d0w2 - 05.11.2015

I tried it but it start at 5:02 but when I change the
PHP код:
TimeS 24 
its start at 5:00 By the way,thanks.


Re: Timer problem - PrO.GameR - 05.11.2015

it could be the reason that you put this in OnGameModeInit and it starts when you start the server not when you join the server
put a printf("%d:%d",TimeM,TimeS); under your textdraw create and in the updatetimer to see exactly if it countdowns right or not.


Re: Timer problem - Sh4d0w2 - 05.11.2015

Nah my problem is its start at 5:02


Re: Timer problem - Vince - 05.11.2015

Time units are relative and any unit can be converted to another. It is common knowledge that a minute is 60 seconds. Hence, 5 minutes is 5 x 60 = 300 seconds. So why two variables?

It then becomes:
PHP код:
forward UpdateTime();
public 
UpdateTime()
{
  if(--
TimeS <= 0)
  {
    
KillTimer(Time);
  }
    
  new 
Str[34];
  
format(Strsizeof(Str), "%02d:%02d"TimeS 60TimeS 60);
  
TextDrawSetString(Textdraw0Str);
  return 
1;

Obviously set TimeS to 300 seconds (= 5 minutes).