Countdown Timer
#1

Hi,
How can I make a countdown timer that starts from 900 seconds to 0 second?
I need the code in the easiest level.
Reply
#2

pawn Код:
// [ DEVELOPMENT GAMEMODE ]

// INCLUDES:

#include <a_samp>
#include <sscanf2>
#include <zcmd>

// DEFINES:

// FUNCTIONS:

#define function%0(%1) forward%0(%1); public%0(%1)
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)

// PER-PLAYER VARIABLES:

// GENERAL:

new pCountdown[MAX_PLAYERS],
pCountdownText[MAX_PLAYERS][2][128];

// TIMERS:

new tmPlayerCountdown[MAX_PLAYERS];

// MAIN:

main()
{
    print("Development Mode: player_countdown.amx");
}

// CALLBACKS:

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// COMMANDS:

CMD:playercountdown(playerid, params[])
{
    new time;
    if(sscanf(params, "i", time)) return SendClientMessage(playerid, -1, "Usage: /countdown (time in seconds).");
    if(time <= 0) return SendClientMessage(playerid, -1, "You have entered an invalid number.");

    SetPlayerCountdown(playerid, time, "Player countdown: ", "Countdown over!");
    return 1;
}

// FUNCTIONS:

stock SetPlayerCountdown(playerid, time, interval_text[], complete_text[])
{
    pCountdown[playerid] = time + 1;
    strcpy(pCountdownText[playerid][0], interval_text, 128);
    strcpy(pCountdownText[playerid][1], complete_text, 128);

    KillTimer(tmPlayerCountdown[playerid]);
    tmPlayerCountdown[playerid] = SetTimerEx("PlayerCountdown", 1000, true, "i", playerid);
    return 1;
}

function PlayerCountdown(playerid)
{
    new string[144];
    pCountdown[playerid] --;

    if(pCountdown[playerid] <= 0)
    {
        GameTextForPlayer(playerid, pCountdownText[playerid][1], 5000, 3);

        KillTimer(tmPlayerCountdown[playerid]);
    }
    else
    {
        format(string, sizeof(string), "%s%s", pCountdownText[playerid][0], ConvertToMinutes(pCountdown[playerid]));
        GameTextForPlayer(playerid, string, 5000, 3);
    }
    return 1;
}

stock ConvertToMinutes(time)
{
    new string[10], minutes, seconds;
    if(time > 59)
    {
        minutes = floatround(time / 60);
        seconds = floatround(time - minutes * 60);
        format(string, sizeof(string), "%01d:%02d", minutes, seconds);
    }
    else
    {
        seconds = floatround(time);
        format(string, sizeof(string), "0:%02d", seconds);
    }
    return string;
}
You figure out the rest, Einstein.
Reply
#3

Код:
#include <a_samp>

forward test(playerid);

new timer;
new count = 900;

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp("/startcount", cmdtext, true, 11) == 0)
    {
        timer = SetTimerEx("test", 1000, 1, "d", playerid);
        return 1;
        }
    return 1;
}
public test(playerid)
{
    count--;
    if(count==0)
    {
        KillTimer(timer);
        GameTextForPlayer(playerid,"~r~Go Go Go",2000,5);
        }else{
            new string[24];
            format(string, sizeof(string), "Please wait: %d", count);
            return GameTextForPlayer(playerid, string, 100, 5);
        }
    return 1;
}
Reply
#4

https://sampforum.blast.hk/showthread.php?tid=169023
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)