Textdraw countdown 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: Textdraw countdown problem (
/showthread.php?tid=366364)
Textdraw countdown problem -
newbienoob - 06.08.2012
I'm trying to make a countdown textdraw. It doesn't work properly.
pawn Код:
new mins = 1, seconds = 60,textdrawtimer; //at the top
textdrawtimer = SetTimer("test",1000,true); //ongamemodeinit
forward test(playerid);
public test(playerid)
{
new str[30];
seconds--;
if(seconds == 0)
{
mins--;
seconds = 59;
}
if(mins == 0 && seconds == 0)
{
SendClientMessage(playerid,red,"aaa");
KillTimer(textdrawtimer);
TextDrawDestroy(timeleft);
}
format(str,sizeof(str),"TimeLeft: %d:%d",mins,seconds);
TextDrawSetString(timeleft,str);
return 1;
}
Problems:
1) This part doesn't work
pawn Код:
if(mins == 0 && seconds == 0)
{
SendClientMessage(playerid,red,"aaa");
KillTimer(textdrawtimer);
TextDrawDestroy(timeleft);
}
It won't send "aaa" text, destroy the textdraw and timer.
2)
How can I make it like 1:09 and not 1:9?
Re: Textdraw countdown problem -
LetsOWN[PL] - 06.08.2012
Hello.
pawn Код:
//SetTimer("test",1000,true);
SetTimerEx("test",1000,true,"d",playerid);
2nd question:
Just use this code:
pawn Код:
format(str,sizeof(str),"TimeLeft: %d:%02d",mins,seconds);
TextDrawSetString(timeleft,str);
However, I'd have it done in another way.
mins = 1, seconds = 60 makes 2 mins, right?
So lets create one var.
Now
pawn Код:
forward test(playerid);
public test(playerid)
{
new str[30];
Var--;
if(Var == 0)
{
SendClientMessage(playerid,red,"aaa");
KillTimer(textdrawtimer);
TextDrawDestroy(timeleft);
}
format(str,sizeof(str),"TimeLeft: %d:%02d",Var/60, Var%60);
TextDrawSetString(timeleft,str);
return 1;
}
Greetz,
LetsOWN
Re: Textdraw countdown problem -
newbienoob - 06.08.2012
Works perfect! But can you/someone explain me this?
pawn Код:
format(str,sizeof(str),"TimeLeft: %d:%02d",Var/60, Var%60);
//Var/60, Var%60 ????
Re: Textdraw countdown problem -
LetsOWN[PL] - 06.08.2012
Sure.
Var/60 calculates minutes from Var and Var%60 calculates seconds from Var.
For example, if Var = 102 then:
Var/60 = 1 and Var%60 = 42
Explained, or need longer explain ?
Greetz
LetsOWN
Re: Textdraw countdown problem -
newbienoob - 06.08.2012
Hmm...
1) Var/60
That means 120 ч 60?
2) Var%60
Can you explain this?
Re: Textdraw countdown problem -
LetsOWN[PL] - 06.08.2012
Quote:
Originally Posted by newbienoob
Hmm...
1) Var/60
That means 120 ч 60?
2) Var%60
Can you explain this?
|
1) Yes. But it takes number without numbers after ,
So if Var = 90 then Var/60 (90:60) will equal 1, not 1,5.
2) Var%60 - % is used for modulus (finding the remainder of one number divided by another). For example 5%2 = 1