搜索
查看: 7902|回复: 24

[AMXX 带源码] 公共服务器规则【直接发源码】

[复制链接]
发表于 2009-1-8 22:13:37 | 显示全部楼层 |阅读模式 来自 中国–广东–韶关
本帖最后由 8874323 于 2009-1-8 22:16 编辑
  1. /*
  2. PUBLIC SERVER RULES 1.20 ( 2005-08-18 )

  3. Plugin by Priski

  4. Usage :
  5. Put rules in rules.txt file in cstrike folder
  6. and set rules_speed and rules_interval whatever you like

  7. Commands :
  8. rules_show         - shows rules listed in rules.txt
  9. rules_enable         - set this to 0 to disable automatic rules display
  10. say /rules         - displays rules to normal user

  11. CVARS :
  12. rules_interval                - interval between automatic rules display
  13. rules_admin_only        - disables say /rules command from regular users
  14. rules_join                - if set 1 displays rules after player have joined server
  15. rules_hudmessage_time        - time how long hudmessage is displayed
  16. rules_join_timeout        - delay to show rules when joining to the server

  17. Changelog :

  18. 1.20 / 2005-08-18
  19. - removed client chat rules
  20. - fixed major bugs

  21. 1.11 / 2005-08-15
  22. - fixed some bugs

  23. 1.10 / 2005-08-14
  24. - new CVARs : rules_hudmessage, rules_hudmessage_time
  25. rules_join_timeout
  26. - Rules in hudmessage mode also

  27. 1.03 / 2005-08-12
  28. - rules_enable command fix.
  29. - new CVAR "rules_join" set 1 to show rules
  30. to players when they join server

  31. 1.02 / 2005-08-11
  32. - optimized code
  33. - rules_enable is now a command       
  34. - default interval is now 10 minutes

  35. 1.01 / 2005-08-11
  36. - added rules_admin_only & say /rules command
  37. - variables are global now

  38. 1.0 / 2005-08-11
  39. - first release

  40. */

  41. #include <amxmodx>
  42. #include <amxmisc>

  43. new base[] = "rules.txt"

  44. new i, num, text[127], hudmsg[440] //max hudmessage length was 439 chars (?)

  45. public plugin_init()
  46. {
  47.        
  48.         register_plugin("AMXX Public server rules", "1.20", "Priski")
  49.        
  50.         // register command
  51.        
  52.         register_concmd("rules_show", "rules", ADMIN_KICK, "- show rules to everybody")
  53.         register_concmd("rules_enable", "r_enable", ADMIN_KICK, "- <1|0> set automessagin on/off")
  54.         register_cvar("rules_admin_only", "0")
  55.         register_cvar("rules_join", "1")
  56.         register_cvar("rules_join_timeout", "5")
  57.         register_cvar("rules_hudmessage_time", "10")
  58.         register_cvar("rules_interval", "600")
  59.         register_clcmd("say /rules", "clientrules", ADMIN_ALL, "- show rules")
  60. }

  61. public plugin_cfg() {
  62.        
  63.         if (!file_exists(base)) {
  64.                 write_file(base, "; This is the public rules file, put your rules below")
  65.                 write_file(base, "; Remember, max amount of characters is 439")
  66.                 console_print(0, "%s file not found. creating new ...", base)
  67.         }
  68.        
  69. }

  70. public client_authorized ( id ) {
  71.         // on join display rules
  72.        
  73.         if (get_cvar_num("rules_join")) {
  74.                 new tmp[1]
  75.                 tmp[0] = id
  76.                 set_task(1.0, "showrules",id,tmp,1)
  77.                 console_print(0, "[user %d] client auth!", tmp[0])
  78.         }
  79.        
  80.         return PLUGIN_HANDLED
  81. }


  82. public showrules (pid[]) {
  83.         new id = pid[0]
  84.        
  85.         if ( get_user_team(id) != 1 && get_user_team(id) != 2 ) {
  86.                 if (id) {
  87.                         new tmp[1]
  88.                         tmp[0] = id
  89.                         set_task(2.0, "showrules",id,tmp,1)  // not yet in server
  90.                         console_print(0, "[user %d] wait for joining team ...", id)
  91.                 }
  92.                 return PLUGIN_HANDLED
  93.         }
  94.        
  95.         new tmp[1]
  96.         tmp[0] = id
  97.        
  98.         console_print(0, "[user %d] joined team : %d", id, get_user_team(id))
  99.         console_print(0, "[user %d] printing rules after %d seconds", id, get_cvar_num("rules_join_timeout"))
  100.        
  101.         set_task(get_cvar_float("rules_join_timeout"), "printrules", id, tmp, 1)  // not yet in server
  102.        
  103.         return PLUGIN_HANDLED
  104. }

  105. public printrules(pid[])
  106. {
  107.         new id = pid[0]
  108.         if (file_exists(base))
  109.                 {
  110.                
  111.                 console_print(0, "[user] printing rules for user %d", id)
  112.                
  113.                 set_hudmessage ( 200, 150, 0, 0.02, 0.25, 2, 0.1, get_cvar_float("rules_hudmessage_time"), 0.05, 1.0, 1)
  114.                 format(hudmsg, 439, "")
  115.                
  116.                 // read all the rules
  117.                 for(i=0; read_file(base, i, text, 127, num); i++) {
  118.                         if (num > 0 && text[0] != ';') {
  119.                                 // display with predefined delay
  120.                                 add(hudmsg,439,text)
  121.                                 add(hudmsg,439,"^n")
  122.                         }
  123.                 }
  124.                
  125.                 // show hudmessages
  126.                 show_hudmessage(id, hudmsg)
  127.                
  128.         }
  129.        
  130.         return PLUGIN_HANDLED
  131. }


  132. public r_enable(id, level, cid)
  133. {
  134.         if (!cmd_access(id, level, cid, 0)) {  // NOT ADMIN
  135.                 return PLUGIN_HANDLED
  136.         }
  137.        
  138.         new arg[3]
  139.        
  140.         read_argv(1, arg, 2)
  141.         new value = str_to_num(arg)
  142.        
  143.         if (!isalnum(arg[0]))
  144.                 value = -1
  145.        
  146.         if (value == 0) {
  147.                
  148.                 if (task_exists(2)) // close task
  149.                         remove_task(2)       
  150.                
  151.                 console_print(id, "You have disabled automatic messages")
  152.                 return PLUGIN_HANDLED
  153.                
  154.         }
  155.         if (value == 1) {
  156.                 // activate task, reload if already exist
  157.                 if (task_exists(2)) {
  158.                         change_task(2, get_cvar_float("rules_interval"))
  159.                         } else {
  160.                         set_task(get_cvar_float("rules_interval"), "rules", 2, "", 0, "b")
  161.                 }       
  162.                 console_print(id, "You have enabled automatic messages")
  163.                 return PLUGIN_HANDLED               
  164.         }
  165.         if (task_exists(2)) {
  166.                 console_print(id, "automessages is ON.")
  167.                 } else {
  168.                 console_print(id, "automessages is OFF.")
  169.         }
  170.         console_print(id, "rules_enable <1|0> (1 = ON, 0 = OFF)")
  171.         return PLUGIN_HANDLED               
  172.        
  173. }

  174. public clientrules(id, level, cid) {
  175.         new pID[1]
  176.         pID[0] = id
  177.        
  178.         console_print(0,"[user %d]Print rules for me only",pID[0])
  179.         printrules(pID[0])
  180. }

  181. public rules(id, level, cid)
  182. {
  183.         new pID[1]
  184.         pID[0] = id
  185.                        
  186.         if (!cmd_access(id, level, cid, 0)) {  // NOT ADMIN
  187.                 return PLUGIN_HANDLED
  188.         }
  189.        
  190.         // read file to all users
  191.         pID[0] = 0
  192.         console_print(0,"[user %d]Print rules for all",id)
  193.         printrules(pID[0])
  194.        
  195.         // Reset scheduled task after display
  196.         if (get_cvar_float("rules_interval") > 0) {
  197.                 if (task_exists(2)) {
  198.                         change_task(2, get_cvar_float("rules_interval"))
  199.                         } else {
  200.                         set_task(get_cvar_float("rules_interval"), "rules", 200, "", 0, "b")
  201.                 }
  202.         }
  203.        
  204.         return PLUGIN_HANDLED
  205. }
复制代码
 楼主| 发表于 2009-1-8 22:21:30 | 显示全部楼层 来自 中国–广东–韶关
不会E文的我说下(玩E文也不太好、希望纠正错误)
用法:
rules.txt规则文件中cstrike文件夹
并设置
rules_show -显示规则中列出rules.txt
rules_enable - set this to 0 to disable automatic rules display rules_enable -设置为0禁用自动显示规则
rules_join -如果设置1显示规则在玩家加入时显示
rules_hudmessage_time -时间显示长度
rules_join_timeout -一直显示
回复

使用道具 举报

发表于 2009-1-9 18:55:41 | 显示全部楼层 来自 马来西亚
只是楼主,希望楼主能够发更多源码。
回复

使用道具 举报

发表于 2009-1-11 12:07:03 | 显示全部楼层 来自 中国–广东–珠海
谢谢楼主了,虽然我还不用
回复

使用道具 举报

发表于 2009-1-12 05:10:02 | 显示全部楼层 来自 中国–云南–大理白族自治州–大理市
呵呵,看不懂
回复

使用道具 举报

发表于 2009-1-12 09:45:43 | 显示全部楼层 来自 中国–香港
希望版主會發更多插件的源碼吧!!
回复

使用道具 举报

发表于 2009-1-15 21:36:24 | 显示全部楼层 来自 中国–河南–商丘
我也看不懂。。
回复

使用道具 举报

发表于 2009-1-15 22:26:44 | 显示全部楼层 来自 中国–广东–珠海
顶顶枯。。
回复

使用道具 举报

发表于 2009-1-15 22:57:17 | 显示全部楼层 来自 中国–广东–东莞
thank you!
回复

使用道具 举报

发表于 2009-1-23 09:25:54 | 显示全部楼层 来自 中国–香港
這個好,我找了這個sma很久了
回复

使用道具 举报

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

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