GameTextForPlayer countdown
#1

Hi,
I need that someone explain me how I could create a counter with GameTextForPlayer.

Example.
With a Trashmaster I go to a point and I perform /command.
This command send a nearByMessage and,a GameTextForPlayer, show me how many second remain for the end of the action.

Second: 30 to 0

Thanks for help.
Reply
#2

pawn Код:
#include <a_samp>

new
    p_Countdown[MAX_PLAYERS] = 30;
   
forward CountingDown(playerid);
public CountingDown(playerid)
{
    switch(p_Countdown[playerid])
    {
        case 30: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 29: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 28: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 27: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 26: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 25: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 24: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 23: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 22: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 21: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 20: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 19: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 18: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 17: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 16: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 15: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 14: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 13: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 12: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 11: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 10: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 9: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 8: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 7: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 6: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 5: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 4: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 3: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 2: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 1: {
            GameTextForPlayer(playerid, p_Countdown[playerid], 3, 1000), p_Countdown[playerid]--;
        }
        case 0: //The end.
        {
            GameTextForPlayer(playerid, "~g~Go!", 3, 100);
            p_Countdown[playerid] = 30;
            TogglePlayerControllable(playerid, 1); //Unfreeze them.
            SendClientMessage(playerid, 0xFFFFFFFF, "Go!");
        }
    }
    p_Countdown[playerid]--;
    return true;
}

//Put this in your command to start this.
SetTimerEx("CountingDown", 1000, true, "i", playerid);
Reply
#3

pawn Код:
#include <a_samp>
   
forward CountingDown(playerid, time);
public CountingDown(playerid, time)
{
    if(time != 0)
    {
        new string[5];
        format(string, sizeof(string), "%d", time);
        GameTextForPlayer(playerid, string, 1200, 4);
        SetTimerEx("CountingDown", 1000, true, "ii", playerid, time-1);
    }
    else
    {
        GameTextForPlayer(playerid, "~g~Go!", 2500, 3);
        TogglePlayerControllable(playerid, 1);
        SendClientMessage(playerid, -1, "Go!");
    }
    return true;
}

//Put this in your command to start this.
SetTimerEx("CountingDown", 1000, true, "ii", playerid, 30);
This is much better because it doesn't require a variable and it doesn't need a switch statement. Also, yours wouldn't work because it's trying to use an integer for a string parameter.
Reply
#4

sorry wrong thread
Reply
#5

pawn Код:
new a[MAX_PLAYERS];
new Timer[MAX_PLAYERS];

CMD:command(playerid,params[])//change the command name
{
    a[playerid] = 30;//change it with the timer time
    Timer[playerid] = SetTimerEx("timer",1000,1,"i",playerid);
    return 1;
}

forward timer(playerid);
public timer(playerid)
{
    if(a[playerid] > 0)
    {
        new str[10];
        format(str,10,"%i",a[playerid]);
        GameTextForPlayer(playerid,str,500,6);
        a[playerid] = a[playerid] - 1;
    }
    else
    {
        GameTextForPlayer(playerid,"Go !",500,6);
    }
    return 1;
}
Reply
#6

bumping 1 year old thread nice
Reply
#7

Sorry for this off topic. But I wonder why that guy bump this old thread.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)