Timer
#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


Messages In This Thread
Timer - by Crowler - 26.10.2014, 13:34
Re: Timer - by HY - 26.10.2014, 13:38
Re: Timer - by Crowler - 26.10.2014, 13:39
Re: Timer - by Laurey - 26.10.2014, 13:47
Re: Timer - by Crowler - 26.10.2014, 14:07
Re: Timer - by Threshold - 26.10.2014, 14:15
Re: Timer - by Laurey - 26.10.2014, 14:17
Re: Timer - by Sawalha - 26.10.2014, 14:26
Re: Timer - by gurmani11 - 26.10.2014, 14:28
Re: Timer - by Crowler - 26.10.2014, 16:09

Forum Jump:


Users browsing this thread: 1 Guest(s)