
   /*
   plugin_jack9_chime.sma
   Server Clock Chime Plugin
   Coded by Jack9
   "Powered by AMX Mod"
   Custom Alterations to original by Jack9 11/24/02
   Custom Alterations to original by Jack9 02/14/03
   **** Updates by Vantage aka Mouse ****
   1.9 Fixed offset bug (don't ask...)
   1.9  **** New Cvar and All Cvars have changed names and act different!
   *******
   1.8  Fixed  very poor coding bugs. 12am as 0 fix. Offset code fixed(ok
   maybe not)
   1.8 Added Option for Center Color Time display like in SM.
   1.8 Commented my code better
   */
   /* COMMANDS
       Client:
           say "time" in chat (wo quotes)
       Server:
           "time" in console (wo quotes)

       ********    When  not  using default cvars, must set cvars, before
   server start, in server/listenserver cfg file. ********
           cvar  -  j9_time_display  "abc"  is default. "a" displays chat
   time. "b" displays chat date.
               "c" displays time in color on top center of screen like in
   SM.
           cvar  -  j9_time_speak  - 2 is default. 0 = No sound, 1 = Just
   Beep, 2 = Beep and Time Speak
           cvar  -  j9_time_interval  - 1 is default. 0 = Every Hour, 1 =
   Half Hour, 2 = 15 Minutes
           cvar  -  j9_time_offset  -  0  is default. Can set negative or
   positive the number of hours to offset time by.
   */
   #include <amxmod>
   new CENTER_TIME_COLOR[3] = {255,100,0}
   new MONTHS[12][] =
   {"January","February","March","April","May","June","July","August","Se
   ptember","October","November","December"}
   new  Float:Time_Interval = 300.0 // Interval client "say time" command
   can be used in seconds.
   new cant_time[33]
   new cvar_display
   new cvar_speak
   new cvar_interval
   new cvar_offset
   public SpeakTime(id)
   {
       if(id){
           if(cant_time[id]){
               client_print(id,  print_chat,"***  You  can  only use this
   command every %.0f minutes. ***", Time_Interval/60.0)
               return PLUGIN_HANDLED
           }

           cant_time[id] = 1
           new a_id[1]
           a_id[0] = id
           set_task(Time_Interval,"remove_cant_time",0, a_id,1)
       }
       new w_Hour[11], w_Minutes1[11], w_Minutes2[11], am_pm[3]
       new ns_Hour[3], ns_Minutes[3],ns_Month[3],ns_Day[3],ns_Year[5]
       get_time("%H",ns_Hour, 2)
       get_time("%M", ns_Minutes, 2)
       get_time("%m", ns_Month, 2)
       get_time("%d", ns_Day, 2)
       get_time("%Y", ns_Year, 4)

       new num_Hour = strtonum(ns_Hour) + cvar_offset
       if(num_Hour > 23) // To fix offset
           num_Hour = num_Hour - 24
       if(num_Hour < 0)
           num_Hour = 24 + num_Hour
       if(num_Hour > 11){  // If it's pm save as such but correct time so
   its 0-11 o'clock (0 = 11) instead of 12-23 pm
           num_Hour -= 12
           copy(am_pm,2,"pm")
       }
       else
           copy(am_pm,2,"am")
       if(!num_Hour) // If = to 0 it's really 12 o'clock am/pm
           num_Hour = 12
       if (cvar_speak == 2){
           num_to_word(num_Hour,w_Hour,10)  //  vox "hour" real/wave file
   name

           if(ns_Minutes[0]  == '1'){ // for speech if minutes are teens,
   vox has all teens as wav files so...
               num_to_word(strtonum(ns_Minutes),w_Minutes1,10)   //  turn
   teens in to their real/wav names
           }
           else{
               if(ns_Minutes[0] == '0'){ // Minutes = 0
                   if(ns_Minutes[1] != '0')
                       copy(w_Minutes1,10,"boop")
               }
               else{  // Minutes = 20 30 40 50
                   new PH[] = "00"
                   PH[0] = ns_Minutes[0]
                   num_to_word(strtonum(PH),w_Minutes1,10)
               }
               if(ns_Minutes[1]   !=   '0'){  //  Minutes  =  21,22,23...
   31,32,33... etc
                   num_to_word(strtonum(ns_Minutes[1]),w_Minutes2,10)
               }
           }

           client_cmd(id,"speak  ^"fvox/bell  time_is_now %s %s %s _comma
   %s^"", w_Hour, w_Minutes1, w_Minutes2, am_pm)
       }
       else if(cvar_speak == 1)
           client_cmd(id,"speak fvox/bell")

       strtoupper(am_pm)

       if(1 & cvar_display)
           client_print(id,    print_chat,    "[    %s    %s,    %s   ]",
   MONTHS[strtonum(ns_Month) - 1], ns_Day, ns_Year)
       if(2 & cvar_display)
           client_print(id,  print_chat, "[ Current Server Time: %d:%s %s
   ]", num_Hour, ns_Minutes,am_pm)
       if(4 & cvar_display){
           set_hudmessage(CENTER_TIME_COLOR[0],     CENTER_TIME_COLOR[1],
   CENTER_TIME_COLOR[2], -1.0, 0.30, 0, 0.5, 6.0 , 2.0, 2.0, 1)
         show_hudmessage(id,"Server            Time:            %02d:%02s
   %s",num_Hour,ns_Minutes,am_pm)
       }
       if(!id){
           server_print("[  %s %s, %s ]", MONTHS[strtonum(ns_Month) - 1],
   ns_Day, ns_Year)
           server_print("[  Current  Server  Time: %d:%s %s ]", num_Hour,
   ns_Minutes,am_pm)
       }
       return PLUGIN_HANDLED
   }
   public chime_check()
   {
       // Set cvars
       new cvar_Sdisplay[4]
       get_cvar_string("j9_time_display",cvar_Sdisplay,3)
       cvar_display = read_flags(cvar_Sdisplay)
       cvar_offset = get_cvar_num("j9_time_offset")
       cvar_speak = get_cvar_num("j9_time_speak")
       cvar_interval = get_cvar_num("j9_time_interval")
       new s_Minutes[3], s_Seconds[3]
       get_time("%M", s_Minutes, 2)
       get_time("%S", s_Seconds, 2)
       new num_Minutes = strtonum(s_Minutes)
       new num_Seconds = strtonum(s_Seconds)
       new Float:exec_time
       if(num_Seconds  >  30)  // seconds to add to exec time so we don't
   cut it close
           exec_time = 30.0
       else
           exec_time = 60.0

       exec_time += float(get_exec_time(num_Minutes))
       set_task(exec_time, "exec_time_chime",1014)
   }
   public remove_cant_time(a_id[])
   {
       cant_time[a_id[0]] = 0
   }
   public exec_time_chime()
   {
       SpeakTime(0) // Display/Speech the time
       new s_Minutes[3], s_Seconds[3]
       get_time("%M", s_Minutes, 2)
       get_time("%S", s_Seconds, 2)
       new num_Minutes = strtonum(s_Minutes)
       new num_Seconds = strtonum(s_Seconds)
       new Float:exec_time
       if(num_Seconds  >  30)  // seconds to add to exec time so we don't
   cut it close
           exec_time = 30.0
       else
           exec_time = 60.0
       exec_time  +=  float(get_exec_time(num_Minutes))  // get next exec
   time for diplay/speaking the time
       set_task(exec_time, "exec_time_chime",1015)
   }
   public  get_exec_time(num_Minutes) // return number of seconds to exec
   the time display/speech function
   {
       new seconds
       if(cvar_interval == 0){
           seconds = (59 - num_Minutes) * 60
       }
       else if(cvar_interval == 2){
           if(num_Minutes < 15){
               seconds = (14 - num_Minutes) * 60
           }
           else if(num_Minutes < 30){
               seconds = (29 - num_Minutes) * 60
           }
           else if(num_Minutes < 45){
               seconds = (44 - num_Minutes) * 60
           }
           else{
               seconds = (59 - num_Minutes) * 60
           }
       }
       else{
           if(num_Minutes < 30)
               seconds = (29 - num_Minutes) * 60
           else
               seconds = (59 - num_Minutes) * 60
       }

       return seconds
   }
   public plugin_init()
   {
       register_plugin("Server Chime Plugin", "1.9 AMX", "Jack9")
       register_cvar("j9_time_display","abc")
       register_cvar("j9_time_speak","2")
       register_cvar("j9_time_interval", "1")
       register_cvar("j9_time_offset","0")
       register_srvcmd("time","SpeakTime")
       register_clcmd("say time","SpeakTime")
       set_task(5.0,"chime_check",1013)
       return PLUGIN_CONTINUE
   }
