搜索
查看: 6735|回复: 13

[AMXX 无源码] 时间提示带源码

[复制链接]
发表于 2010-11-28 12:46:51 | 显示全部楼层 |阅读模式 来自 中国–河北–秦皇岛–海港区
  1. /*
  2. server_chime_plugin.sma
  3. Server Clock Chime Plugin
  4. 服务器时间报时插件
  5. Coded by Jack9
  6. "Powered by AMX Mod"

  7. Custom Alterations to original by Jack9 11/24/02
  8. Custom Alterations to original by Jack9 02/14/03

  9. **** Updates by Vantage aka Mouse ****
  10. 1.9 Fixed offset bug (don't ask...)
  11. 1.9 **** New Cvar and All Cvars have changed names and act different! *******
  12. 1.8 Fixed very poor coding bugs. 12am as 0 fix. Offset code fixed(ok maybe not)
  13. 1.8 Added Option for Center Color Time display like in SM.
  14. 1.8 Commented my code better


  15. */

  16. /* COMMANDS

  17.         Client:
  18.                 say "time" in chat (wo quotes)
  19.         Server:
  20.                 "time" in console (wo quotes)
  21.                
  22.         ********        When not using default cvars, must set cvars, before server start, in server/listenserver cfg file. ********
  23.                 cvar - j9_time_display "abc" is default. "a" displays chat time. "b" displays chat date.
  24.                         "c" displays time in color on top center of screen like in SM.
  25.                 cvar - j9_time_speak - 2 is default. 0 = No sound, 1 = Just Beep, 2 = Beep and Time Speak
  26.                 cvar - j9_time_interval - 1 is default. 0 = Every Hour, 1 = Half Hour, 2 = 15 Minutes
  27.                 cvar - j9_time_offset - 0 is default. Can set negative or positive the number of hours to offset time by.
  28. */
  29. //命令变量
  30. //j9_time_display "abc"  是默认设置。a显示时间,b显示日期,c象SM一样,在屏幕中上方显示有颜色的时间。
  31. //j9_time_speak 2是默认值。0无声,1只有嘟嘟声,2嘟嘟声和发出时间声
  32. //j9_time_interval 1是默认值。0每小时,1半个小时,2是15分钟
  33. //j9_time_offset   0是默认值。 可以抵消正负时间数值。

  34. #include <amxmod>

  35. new CENTER_TIME_COLOR[3] = {255,0,125}
  36. new MONTHS[12][] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}
  37. new WEEK[7][] = {"日","一","二","三","四","五","六"}
  38. new DAY[31][] = {"一","二","三","四","五","六","七","八","九","十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十","三十一"}

  39. new Float:Time_Interval = 180.0 // Interval client "say time" command can be used in seconds多少秒时间间隔才能用say time命令.
  40. new cant_time[33]

  41. new cvar_display
  42. new cvar_speak
  43. new cvar_interval
  44. new cvar_offset


  45. public SpeakTime(id)
  46. {
  47.         if(id){
  48.                 if(cant_time[id]){
  49.                         client_print(id, print_chat,"*** 你只能每 %.0f 分钟使用一次这个命令. ***", Time_Interval/60.0)
  50.                         return PLUGIN_HANDLED
  51.                 }
  52.        
  53.                 cant_time[id] = 1
  54.                 new a_id[1]
  55.                 a_id[0] = id
  56.                 set_task(Time_Interval,"remove_cant_time",0, a_id,1)
  57.         }

  58.         new w_Hour[11], w_Minutes1[11], w_Minutes2[11], am_pm[9], apm[3]
  59.         new ns_Hour[3], ns_Minutes[3],ns_Month[3],ns_Day[3],ns_Year[5], ns_Week[5]

  60.         get_time("%H",ns_Hour, 2)
  61.         get_time("%M", ns_Minutes, 2)
  62.         get_time("%m", ns_Month, 2)
  63.         get_time("%d", ns_Day, 2)
  64.         get_time("%Y", ns_Year, 4)
  65.         get_time("%w", ns_Week, 4)
  66.        
  67.         new num_Hour = str_to_num(ns_Hour) + cvar_offset

  68.         if(num_Hour > 23) // To fix offset
  69.                 num_Hour = num_Hour - 24
  70.         if(num_Hour < 0)
  71.                 num_Hour = 24 + num_Hour
  72.        
  73.         /*以下是增加显示“凌晨、早晨、上午、中午、下午、黄昏、晚上、午夜”时间段功能代码 By Undoer*/
  74.         switch(num_Hour)
  75.         {
  76.                 case 0: copy(am_pm,8,"凌晨")
  77.                 case 1: copy(am_pm,8,"凌晨")
  78.                 case 2: copy(am_pm,8,"凌晨")
  79.                 case 3: copy(am_pm,8,"凌晨")
  80.                 case 4: copy(am_pm,8,"凌晨")
  81.                 case 5: copy(am_pm,8,"凌晨")
  82.                 case 6: copy(am_pm,8,"早晨")
  83.                 case 7: copy(am_pm,8,"早晨")
  84.                 case 8: copy(am_pm,8,"上午")
  85.                 case 9: copy(am_pm,8,"上午")
  86.                 case 10: copy(am_pm,8,"上午")
  87.                 case 11: copy(am_pm,8,"上午")
  88.                 case 12: copy(am_pm,8,"中午")
  89.                 case 13: copy(am_pm,8,"下午")
  90.                 case 14: copy(am_pm,8,"下午")
  91.                 case 15: copy(am_pm,8,"下午")
  92.                 case 16: copy(am_pm,8,"下午")
  93.                 case 17: copy(am_pm,8,"下午")
  94.                 case 18: copy(am_pm,8,"黄昏")
  95.                 case 19: copy(am_pm,8,"晚上")
  96.                 case 20: copy(am_pm,8,"晚上")
  97.                 case 21: copy(am_pm,8,"晚上")
  98.                 case 22: copy(am_pm,8,"晚上")
  99.                 case 23: copy(am_pm,8,"午夜")
  100.                 case 24: copy(am_pm,8,"凌晨")
  101.         }                                        /*增加止2005-04-11*/
  102.        
  103.         /*由于报时声音文件的原因,当时间大于20点时就无法报出时间声音!
  104.           为了可以正常报时,还是使用原代码发音代码,但显示已改了实际时间。*/
  105.         new u_Hour = num_Hour
  106.         if(u_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
  107.                 u_Hour -= 12
  108.                 copy(apm,2,"pm")
  109.         }
  110.         else
  111.                 copy(apm,2,"am")

  112.         if(!u_Hour) // If = to 0 it's really 12 o'clock am/pm
  113.                 u_Hour = 12

  114.         if (cvar_speak == 2){
  115.                 num_to_word(u_Hour,w_Hour,10) // vox "hour" real/wave file name
  116.                   
  117.                 if(ns_Minutes[0] == '1'){ // for speech if minutes are teens, vox has all teens as wav files so...
  118.                         num_to_word(str_to_num(ns_Minutes),w_Minutes1,10) // turn teens in to their real/wav names
  119.                 }
  120.                 else{
  121.                         if(ns_Minutes[0] == '0'){ // Minutes = 0
  122.                                 if(ns_Minutes[1] != '0')
  123.                                         copy(w_Minutes1,10,"boop")
  124.                         }
  125.                         else{  // Minutes = 20 30 40 50
  126.                                 new PH[] = "00"
  127.                                 PH[0] = ns_Minutes[0]
  128.                                 num_to_word(str_to_num(PH),w_Minutes1,10)
  129.                         }

  130.                         if(ns_Minutes[1] != '0'){ // Minutes = 21,22,23... 31,32,33... etc
  131.                                 num_to_word(str_to_num(ns_Minutes[1]),w_Minutes2,10)
  132.                         }
  133.                 }
  134.        
  135.                 client_cmd(id,"speak ^"misc/fvox/blip _comma blip _comma blip _comma blip _comma bell2 time_is_now %s %s %s _comma %s^"", w_Hour, w_Minutes1, w_Minutes2, apm)
  136.         }
  137.         else if(cvar_speak == 1)
  138.                 client_cmd(id,"speak misc/fvox/blip _comma blip _comma blip _comma blip _comma bell2")
  139.          
  140.         strtoupper(apm)
  141.        
  142.         if(1 & cvar_display){
  143.                 client_print(id, print_chat, "【日期: %s年 %s %s日 星期%s】", ns_Year, MONTHS[str_to_num(ns_Month) - 1], DAY[str_to_num(ns_Day) - 1], WEEK[str_to_num(ns_Week)])
  144.                 client_print(id, print_chat, "【时间: %s  %d点 %s分】", am_pm, num_Hour, ns_Minutes)
  145.         }
  146.         if(4 & cvar_display){
  147.                 set_hudmessage(CENTER_TIME_COLOR[0], CENTER_TIME_COLOR[1], CENTER_TIME_COLOR[2], -1.0, 0.2, 0, 0.5, 6.0 , 2.0, 2.0, 17)
  148.     show_hudmessage(id,"【北京时间】^n %s %d点 %s分",am_pm, num_Hour,ns_Minutes)
  149.         }

  150.         if(!id){
  151.                 server_print("【日期: %s年 %s %s日 星期%s】", ns_Year, MONTHS[str_to_num(ns_Month) - 1], DAY[str_to_num(ns_Day) - 1], WEEK[str_to_num(ns_Week)])
  152.                 server_print("【时间: %s  %d点 %s分】", am_pm, num_Hour, ns_Minutes)  
  153.         }

  154.         return PLUGIN_HANDLED
  155. }

  156. public chime_check()
  157. {
  158.         // Set cvars
  159.         new cvar_Sdisplay[4]
  160.         get_cvar_string("j9_time_display",cvar_Sdisplay,3)

  161.         cvar_display = read_flags(cvar_Sdisplay)
  162.         cvar_offset = get_cvar_num("j9_time_offset")
  163.         cvar_speak = get_cvar_num("j9_time_speak")
  164.         cvar_interval = get_cvar_num("j9_time_interval")

  165.         new s_Minutes[3], s_Seconds[3]

  166.         get_time("%M", s_Minutes, 2)
  167.         get_time("%S", s_Seconds, 2)

  168.         new num_Minutes = str_to_num(s_Minutes)
  169.         new num_Seconds = str_to_num(s_Seconds)

  170.         new Float:exec_time

  171.         if(num_Seconds > 30) // seconds to add to exec time so we don't cut it close
  172.                 exec_time = 30.0
  173.         else
  174.                 exec_time = 60.0
  175.          
  176.         exec_time += float(get_exec_time(num_Minutes))

  177.         set_task(exec_time, "exec_time_chime",1014)
  178. }


  179. public remove_cant_time(a_id[])
  180. {
  181.         cant_time[a_id[0]] = 0
  182. }


  183. public exec_time_chime()
  184. {
  185.         SpeakTime(0) // Display/Speech the time

  186.         new s_Minutes[3], s_Seconds[3]

  187.         get_time("%M", s_Minutes, 2)
  188.         get_time("%S", s_Seconds, 2)

  189.         new num_Minutes = str_to_num(s_Minutes)
  190.         new num_Seconds = str_to_num(s_Seconds)

  191.         new Float:exec_time

  192.         if(num_Seconds > 30) // seconds to add to exec time so we don't cut it close
  193.                 exec_time = 30.0
  194.         else
  195.                 exec_time = 60.0

  196.         exec_time += float(get_exec_time(num_Minutes)) // get next exec time for diplay/speaking the time

  197.         set_task(exec_time, "exec_time_chime",1015)

  198. }

  199. public get_exec_time(num_Minutes) // return number of seconds to exec the time display/speech function
  200. {
  201.         new seconds  

  202.         if(cvar_interval == 0){
  203.                 seconds = (59 - num_Minutes) * 60
  204.         }
  205.         else if(cvar_interval == 2){
  206.                 if(num_Minutes < 15){
  207.                         seconds = (14 - num_Minutes) * 60
  208.                 }
  209.                 else if(num_Minutes < 30){
  210.                         seconds = (29 - num_Minutes) * 60
  211.                 }
  212.                 else if(num_Minutes < 45){
  213.                         seconds = (44 - num_Minutes) * 60
  214.                 }
  215.                 else{
  216.                         seconds = (59 - num_Minutes) * 60
  217.                 }
  218.         }
  219.         else{
  220.                 if(num_Minutes < 30)
  221.                         seconds = (29 - num_Minutes) * 60
  222.                 else
  223.                         seconds = (59 - num_Minutes) * 60
  224.         }
  225.          
  226.         return seconds
  227. }

  228. public plugin_init()
  229. {
  230.         register_plugin("Server Chime Plugin", "0.9 AMX", "Edited By Undoer")
  231.         register_cvar("j9_time_display","abc")
  232.         register_cvar("j9_time_speak","2")
  233.         register_cvar("j9_time_interval", "1")
  234.         register_cvar("j9_time_offset","0")
  235.         register_srvcmd("time","SpeakTime")
  236.         register_clcmd("say time","SpeakTime")

  237.         set_task(5.0,"chime_check",1013)

  238.         return PLUGIN_CONTINUE
  239. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注个册吧

×
发表于 2010-11-28 14:01:15 | 显示全部楼层 来自 中国–广西–南宁
不错········
回复

使用道具 举报

发表于 2010-12-9 08:45:02 | 显示全部楼层 来自 中国–山东–济宁
怎么用 给说下不
回复

使用道具 举报

发表于 2010-12-13 16:45:52 | 显示全部楼层 来自 中国–云南–楚雄彝族自治州
顶了。。。先下了收藏!
回复

使用道具 举报

发表于 2011-4-2 15:33:55 | 显示全部楼层 来自 中国–湖南–邵阳
学习了  不错的插件啊
回复

使用道具 举报

发表于 2011-5-1 19:16:08 | 显示全部楼层 来自 中国–陕西–西安
server_chime_plugin.sma
这都拿出来发
还是支持了。
回复

使用道具 举报

发表于 2011-10-1 14:31:25 | 显示全部楼层 来自 中国–云南–临沧
顶了 替换我那个时间报错的东西
回复

使用道具 举报

发表于 2011-10-2 16:17:13 | 显示全部楼层 来自 中国–云南–临沧
要不了。。。。
回复

使用道具 举报

发表于 2012-3-30 01:57:34 | 显示全部楼层 来自 中国–山东–济宁
根据源码编译修改了个适合自己的
回复

使用道具 举报

发表于 2012-4-14 13:05:32 | 显示全部楼层 来自 中国–广东–揭阳
好东西,收下了
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表