26.10.2014, 13:34
Guys, can someone give me a tutorial or an example teaching how to make a timer like this in a textdraw?:
TextDrawCreate - https://sampwiki.blast.hk/wiki/TextDrawCreate
TextDrawSetString - https://sampwiki.blast.hk/wiki/TextDrawSetString |
new Text:TimeTD
TimeTD = TextDrawCreate(633.000000,428.000000,"game time");
TextDrawFont(TimeTD,2);
TextDrawSetShadow(TimeTD,0);
TextDrawSetOutline(TimeTD,1);
TextDrawAlignment(TimeTD,3);
TextDrawLetterSize(TimeTD,0.399999,1.500000);
TextDrawColor(TimeTD,0x00B2EEFF);
format(string,sizeof(string),"~r~game time: ~w~%d:%d:%d", thour, tmin, tsec);
TextDrawSetString(TimeTD, string);
new mins = 4, secs = 60;
// Creating minutes & seconds variables.
new timer;
public OnGameModeInit()
{
timer = SetTimer("minsec", 1000, true);
return 1; // we have created the timer.
}
// Creating the callback "minsec" for the timer:
forward minsec();
public minsec()
{
sec--; // decreasing "sec" value every second.
if(sec == 0)
{
min--
sec = 60; // if the second is 0 , we decrease the value of minutes, and we reset the value of seconds to "60"
}
if(sec == 0 && min == 0) KillTimer(timer); // if the seconds and mins are 0 both, we kill the timer.
// TextDrawSetString(... etc, );
return 1;
}
public OnGameModeExit()
{
KillTimer(timer); // killing the timer after the server is down / off.
return 1;
}
#include a_samp
#include zcmd // for command processor
new PlayerText:Countdown[MAX_PLAYERS];// Variable for a player textdraw
new Ctdown[MAX_PLAYERS]; // Variable for the number length
new Countdown_Timer[MAX_PLAYERS]; // variable to kill a timer at Zero "0"
public OnPlayerConnect(playerid)
{
Create_Countdown_Textdraw(playerid); // Creating PlayerText for a player
return 1;
}
stock Create_Countdown_Textdraw(playerid) // suing stock to create a textdraw first
{
Countdown[playerid] = CreatePlayerTextDraw(playerid, 46.000000, 164.000000, "_");
PlayerTextDrawBackgroundColor(playerid, Countdown[playerid], -1728053214);
PlayerTextDrawFont(playerid, Countdown[playerid], 2);
PlayerTextDrawLetterSize(playerid, Countdown[playerid], 0.189999, 1.000000);
PlayerTextDrawColor(playerid, Countdown[playerid], 255);
PlayerTextDrawSetOutline(playerid, Countdown[playerid], 1);
PlayerTextDrawSetProportional(playerid, Countdown[playerid], 1);
PlayerTextDrawSetSelectable(playerid, Countdown[playerid], 0);
}
CMD:Ctdown(playerid, params[])
{
Show_Countdown(playerid); // using stock to start a countdown
return 1;
}
stock Show_Countdown(playerid) // it will show the textdraw
{
PlayerTextDrawShow(playerid, Countdown[playerid]); // this will show a textdraw which is empty in statement
Ctdown[playerid] = 20; // that variable we defiend at top we set the value of it to 20 to start a countdown from 20
Countdown_Timer[playerid] = SetTimerEx("CtDwn", 1000, true, "i", playerid); //Timer repeating value has been set to 'true' so on each 1 second it will count down the value
}
forward CtDwn(playerid); // to repeat till it goes to "0"
public CtDwn(playerid)
{
Ctdown[playerid] --; // Subtracted
new tdstr[50]; // string for textdraw
format(tdstr, sizeof(tdstr), "Countdown %d", Ctdown[playerid]); // it will format the text in the string 'tdstr'
PlayerTextDrawSetString(playerid,Countdown[playerid], tdstr); // so, now we set the string to the textdraw which is already shown using 'tdstr'
if(Ctdown[playerid] < 1) // checking if the countdown value is lower than '1' so it will not be in minus
{
Hide_Countdown(playerid); // now if the countdown is '0' or '-1' or so on it will hide the countdown |again we use stock here|
}
}
stock Hide_Countdown(playerid) // Stock goes here
{
new tdstr[10]; // same string
format(tdstr, sizeof(tdstr), "_"); // we set it to blank first
PlayerTextDrawSetString(playerid,Countdown[playerid], tdstr);// set the string in the player's screen
PlayerTextDrawHide(playerid, Countdown[playerid]); // hiding the textdraw
KillTimer(Countdown_Timer[playerid]); // Killing the timer
}