TextDraw countdown
#1

<FIXED>
Reply
#2

Sure,

All there = https://sampwiki.blast.hk/wiki/TextDrawCreate

https://sampwiki.blast.hk/wiki/SetTimer
Reply
#3

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(TDStringsizeof(TDString), "%s"CountDownNumber);//formatting the textdraw's string to hold the number value.
        
TextDrawSetString(textdrawidstring);//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(IDtextdrawid); //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...
Reply
#4

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(TDStringsizeof(TDString), "%s"CountDownNumber);//formatting the textdraw's string to hold the number value.
        
TextDrawSetString(textdrawidstring);//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(IDtextdrawid); //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?
Reply
#5

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.
Reply
#6

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)