11.06.2015, 07:37
Actually, "time remaining" and a "countdown" is exactly the same thing.
Usage:
During the interval of the countdown, interval_text[] + countdown progress in format of minutes:
When the countdown finishes, complete_text[]:
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: 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);
}
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);
}
}
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;
}
pawn Код:
SetPlayerCountdown(playerid, time, interval_text[], complete_text[]);
When the countdown finishes, complete_text[]: