TextDraw countdown - 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 (
/showthread.php?tid=649423)
TextDraw -
PundacheMakalae - 08.02.2018
<FIXED>
Re: TextDraw countdown -
wallen - 08.02.2018
Sure,
All there =
https://sampwiki.blast.hk/wiki/TextDrawCreate
https://sampwiki.blast.hk/wiki/SetTimer
Re: TextDraw countdown -
RogueDrifter - 08.02.2018
As an example i'd provide is:
First go on top of the script and do:
PHP код:
new CountdownNumber = -1; //setting a value to make sure it doesn't keep calling itself.
new TDTimer; //making a timer variable to kill it later
go to the place where you want to make the countdown and do something like:
PHP код:
CountdownNumber = 5;// in this case its 5 seconds.
TDTimer = SetTimer("CountdownTextdraw",1000,true); //setting the timer for the function gets called every 1 second
and then at the function itself would look like:
PHP код:
CountdownTextdraw()
{
if(CountDownNumber != -1)
{
new TDString[10];//textdraw string
format(TDString, sizeof(TDString), "%s", CountDownNumber);//formatting the textdraw's string to hold the number value.
TextDrawSetString(textdrawid, string);//setting the textdraw's string.
TextDrawShowForPlayer(ID,textdrawid);//showing the textdraw.
CountdownNumber--;//Taking out -1 of the number's value to decrease it one by one.
}
else
{
KillTimer(TDTimer);//Killing the timer for next use
TextDrawHideForPlayer(ID, textdrawid); //hiding it after its done being used.
}
return 1;
}
This is an example of a timer that works once, so you can't do this as a command that can be used 2 times in a row. You also didn't say if you wanted it for a player or not so you can change the SetTimer to SetTimerEx to pass a player's id you can also change the textdraw's type to a playertextdraw if that's what you're going for and so on...
Re: TextDraw countdown -
PundacheMakalae - 08.02.2018
Quote:
Originally Posted by RogueDrifter
As an example i'd provide is:
First go on top of the script and do:
PHP код:
new CountdownNumber = -1; //setting a value to make sure it doesn't keep calling itself.
new TDTimer; //making a timer variable to kill it later
go to the place where you want to make the countdown and do something like:
PHP код:
CountdownNumber = 5;// in this case its 5 seconds.
TDTimer = SetTimer("CountdownTextdraw",1000,true); //setting the timer for the function gets called every 1 second
and then at the function itself would look like:
PHP код:
CountdownTextdraw()
{
if(CountDownNumber != -1)
{
new TDString[10];//textdraw string
format(TDString, sizeof(TDString), "%s", CountDownNumber);//formatting the textdraw's string to hold the number value.
TextDrawSetString(textdrawid, string);//setting the textdraw's string.
TextDrawShowForPlayer(ID,textdrawid);//showing the textdraw.
CountdownNumber--;//Taking out -1 of the number's value to decrease it one by one.
}
else
{
KillTimer(TDTimer);//Killing the timer for next use
TextDrawHideForPlayer(ID, textdrawid); //hiding it after its done being used.
return 1;
}
This is an example of a timer that works once, so you can't do this as a command that can be used 2 times in a row.
|
This is what i wanted, so where should i place the created textdraw, under ongamemodeinit or onplayerconnect?
Re: TextDraw countdown -
RogueDrifter - 08.02.2018
I edited my example so please review it and that also depends, do you want it to be a global one? create it at ongamemode/filterscript init but if you want it to be player textdraw then create it at OnPlayerConnect and destroy it at OnPlayerDisconnect.
Re: TextDraw countdown -
PundacheMakalae - 08.02.2018
Quote:
Originally Posted by RogueDrifter
I edited my example so please review it and that also depends, do you want it to be a global one? create it at ongamemode/filterscript init but if you want it to be player textdraw then create it at OnPlayerConnect and destroy it at OnPlayerDisconnect.
|
Yeah I've reviewed it, the first thing i did lol. Anyway thank you so much dude.
Re: TextDraw countdown -
RogueDrifter - 08.02.2018
Please re-edit your post to the original form to help others see it if they face the same query and to not confuse them.
NOTE: the question was about how to make a textdraw countdown. reason for the fix was the code i provided for anyone viewing this after a while.