I wanted to try my hand at this, since I'm relatively new to writing programs. I spent a while figuring out how to do the counter nicely.
The code below should work fine, though the hudmessage is untested. (I tested it with server_print.) Anyway, I'd really appreciate some feedback on this. If you can do this better, or more efficiently, please show me how.
Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Restart Timer"
#define VERSION "1.0"
#define AUTHOR "stupok69"
new itimer
new clocktime[8]
new start_time
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
start_time = register_cvar("restart_server_time", "0")
itimer = get_pcvar_num(start_time)
register_concmd("startcounter", "set_clock", ADMIN_SLAY, "-displays timer, restarts server when finished")
}
public set_clock(id, level, cid)
{
if(!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
set_task(1.0,"my_clock",0,"",0,"a", itimer)
set_task(0.1,"display_clock",0,"",0,"b")
return PLUGIN_CONTINUE
}
public my_clock()
{
output_hms(--itimer, clocktime, 7)
if(itimer == 0) server_cmd("restart")
}
public display_clock()
{
set_hudmessage(255, 255, 255, 0.5, 0.3, 0, 6.0, 12.0)
show_hudmessage(0, "Server Restart In %s", clocktime)
}
output_hms(inputseconds, outputstring[], outputlen)
{
if(!inputseconds) return 0
new hours, minutes, seconds, h, m, s
if(inputseconds > 3600)
{
for(h = inputseconds; h >= 3600; h -= 3600)
{
}
hours = (inputseconds - h) / 3600
}
else
{
hours = 0
}
if(inputseconds > 60)
{
for(s = inputseconds; s >= 60; s -= 60)
{
}
seconds = s
minutes = (inputseconds - s) / 60
for(m = minutes; m >= 60; m -= 60)
{
}
minutes = m
}
else
{
minutes = 0
seconds = inputseconds - 1
}
format(outputstring, outputlen, "%i:%i:%i", hours, minutes, seconds)
return 1
}