This is an example countdown timer. Make modifications if you wish:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Countdown Example"
#define VERSION "1.0"
#define AUTHOR "M249-M4A1"
new gTime, thetimer
new number_as_word[32]
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
// the command to start the countdown
register_concmd("amx_countdown", "initCountDown", 0)
// stops the countdown
register_concmd("amx_abort_count", "stopCountDown", 0)
thetimer = register_cvar("count_timer", "10") // <--- 10 second countdown to 0
}
public initCountDown(id) {
if (!task_exists(92133)) {
gTime = get_pcvar_num(thetimer)
client_print(id, print_chat, "[AMXX] Countdown started - Counting from %i to 0...", gTime)
set_task(1.0, "countdown", 92133, "", 0, "b")
}
else
console_print(id, "[AMXX] Countdown has not finished! Type amx_abort_count to stop the countdown.")
return PLUGIN_HANDLED
}
public countdown() {
// this was the same design used in miscstats for the bomb counter
if (gTime > 0) {
// convert the number to a work, to be used with the vox system
num_to_word(gTime, number_as_word, 31)
client_cmd(0, "spk ^"vox/%s^"", number_as_word)
// decrement the timer manually
gTime--
}
else
// remove the countdown task, as it shouldve reached 0 by now
remove_task(92133)
}
public stopCountDown(id) {
if (!task_exists(92133)) {
console_print(id, "[AMXX] There is no countdown!")
}
else
{
console_print(id, "[AMXX] Countdown has been terminated!")
remove_task(92133)
}
return PLUGIN_HANDLED
}
__________________