Raised This Month: $ Target: $400
 0% 

Timer duplication?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
jcarle
Junior Member
Join Date: Jan 2008
Location: Joliette, QC, Canada
Old 01-27-2008 , 18:53   Timer duplication?
Reply With Quote #1

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(CLKEnabledOnConvarChanged);
 if (
GetConVarInt(CLKEnabled) == 1)
  
cTimer CreateTimer(60.0PrintTime_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.0PrintTime_TIMER_REPEAT);
            } else {
    
KillTimer(cTimerfalse);
            }
    }
}
 
public 
OnPluginEnd()
{
 
KillTimer(cTimerfalse); 
}
 
public 
Action:PrintTime(Handle:timer)
{
 
decl String:curTimeZone[10];
 
decl String:curTime[20];
 
 
GetConVarString(TimeZonecurTimeZonesizeof(curTimeZone));
 
FormatTime(curTimesizeof(curTime), "%I:%M %p"GetTime());
 if (
StrContains(curTime":00"false) >= || StrContains(curTime":15"false) >= || StrContains(curTime":30"false) >= || StrContains(curTime":45"false) >= 0)
 {
  
PrintHintTextToAll("%s %s"curTimecurTimeZone);
  
PrintToServer("%s %s"curTimecurTimeZone);
 }
 
 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...
jcarle is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode