#1

Guys, can someone give me a tutorial or an example teaching how to make a timer like this in a textdraw?:

Reply
#2

Click.
Reply
#3

Quote:
Originally Posted by HY
Посмотреть сообщение
Did you read my post?
Reply
#4

TextDrawCreate - https://sampwiki.blast.hk/wiki/TextDrawCreate
TextDrawSetString - https://sampwiki.blast.hk/wiki/TextDrawSetString
Reply
#5

Quote:
Originally Posted by Laurey
Посмотреть сообщение
Thanks mate but I already know that, i want to know how to make that timer in a textdraw
Reply
#6

SetTimer - https://sampwiki.blast.hk/wiki/SetTimer
SetTimerEx - https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#7

Define the time's textdraw on the top,
pawn Код:
new Text:TimeTD
Textdraw's creation
pawn Код:
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);
Then in the public of your clock system you have to implement the given textdraw something like this
pawn Код:
format(string,sizeof(string),"~r~game time: ~w~%d:%d:%d", thour, tmin, tsec);
   TextDrawSetString(TimeTD, string);
It was just a simple idea you can do it on its basis.
PS: Its for the clock system if you meant that.
Reply
#8

if your textdraw is ready, well good.
this is if you want a countdown:
pawn Код:
new mins = 4, secs = 60;
// Creating minutes & seconds variables.
pawn Код:
new timer;
public OnGameModeInit()
{
     timer = SetTimer("minsec", 1000, true);
     return 1; // we have created the timer.
}
pawn Код:
// 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;
}
pawn Код:
public OnGameModeExit()
{
   KillTimer(timer); // killing the timer after the server is down / off.
   return 1;
}
Reply
#9

Here you go
pawn Код:
#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
}
Hope this helps
Reply
#10

Not working @gurmani11
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)