I wrote the following clock script :
PHP Code:
#include <sourcemod>
#define PLUGIN_VERSION "1.0.0"
new Handle:CLKEnabled;
new Handle:TimeZone;
new Handle:cTimer;
public Plugin:myinfo =
{
name = "Clock",
author = "Jean-Sebastien Carle",
description = "Displays the system time to all clients.",
version = PLUGIN_VERSION,
url = "http://www.sourcemod.net/"
}
public OnPluginStart()
{
CreateConVar("clk_version", PLUGIN_VERSION, "Clock Version", FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY);
CLKEnabled = CreateConVar("clk_enabled", "1", "Enable plugin");
TimeZone = CreateConVar("clk_timezone", "GMT-5", "Timezone");
AutoExecConfig(true, "plugin.clock", "sourcemod");
}
public OnConfigsExecuted()
{
PrintToServer("[Clock] Plugin loaded.");
HookConVarChange(CLKEnabled, OnConvarChanged);
if (GetConVarInt(CLKEnabled) == 1)
cTimer = CreateTimer(60.0, PrintTime, _, TIMER_REPEAT);
}
public OnConvarChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
static iNewVal = 0;
if (convar == CLKEnabled)
{
iNewVal = StringToInt(newValue);
if (StringToInt(oldValue) != iNewVal)
if (iNewVal > 0) {
cTimer = CreateTimer(60.0, PrintTime, _, TIMER_REPEAT);
} else {
KillTimer(cTimer, false);
}
}
}
public OnPluginEnd()
{
KillTimer(cTimer, false);
}
public Action:PrintTime(Handle:timer)
{
decl String:curTimeZone[10];
decl String:curTime[20];
GetConVarString(TimeZone, curTimeZone, sizeof(curTimeZone));
FormatTime(curTime, sizeof(curTime), "%I:%M %p", GetTime());
if (StrContains(curTime, ":00", false) >= 0 || StrContains(curTime, ":15", false) >= 0 || StrContains(curTime, ":30", false) >= 0 || StrContains(curTime, ":45", false) >= 0)
{
PrintHintTextToAll("%s %s", curTime, curTimeZone);
PrintToServer("%s %s", curTime, curTimeZone);
}
return Plugin_Continue;
}
For some reason, sometimes, it seems like the timers double up and I end up getting the time displayed multiple times in a row...