Not Tested.
PHP Code:
#pragma semicolon 1
#include <amxmodx>
#include <hamsandwich>
#define PLUGIN "StopWatch"
#define VERSION "0.1"
#define AUTHOR "Aoi.Kagase"
#define TASK_ID 1122
enum _:WATCH_STATUS
{
START,
STOP,
}
new g_starttime;
new g_counttime;
new WATCH_STATUS:g_status;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_clcmd("say", "stopwatch");
RegisterHam(Ham_Think, "player", "ThinkTime");
}
public stopwatch(id)
{
new said[32];
read_argv(1, said, charsmax(said));
if (equali(said,"/start"))
{
g_starttime = get_systime();
g_counttime = 0;
g_status = WATCH_STATUS:START;
return PLUGIN_HANDLED;
} else
if (equali(said, "/stop"))
{
g_counttime = (get_systime() - g_starttime);
g_status = WATCH_STATUS:STOP;
return PLUGIN_HANDLED;
} else
if (equali(said, "/pause"))
{
g_counttime = (get_systime() - g_starttime);
g_status = WATCH_STATUS:STOP;
return PLUGIN_HANDLED;
} else
if (equali(said, "/resume"))
{
g_status = WATCH_STATUS:START;
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public ThinkTime(id)
{
static timeformat[8];
switch(g_status)
{
case START:
{
get_time_format((get_systime() - g_starttime) + g_counttime, timeformat, charsmax(timeformat), 0);
set_hudmessage(0, 0, 255, -1.0, 0.35, 0, 0.5, 1.0, 0.0, 0.1, -1);
show_hudmessage(0, "[STOP WATCH]: %s", timeformat);
}
case STOP:
{
get_time_format(g_counttime, timeformat, charsmax(timeformat), 0);
set_hudmessage(0, 0, 255, -1.0, 0.35, 0, 0.5, 5.0, 0.0, 0.1, -1);
show_hudmessage(0, "[STOP WATCH]: %s", timeformat);
}
}
}
get_time_format(times, result[], len, mode)
{
switch(mode)
{
case 'H':
format_time(result, len, "%H", times);
case 'M':
format_time(result, len, "%M", times);
case 'S':
format_time(result, len, "%S", times);
default:
format_time(result, len, "%H:%M:%S", times);
}
}