搜索
查看: 4146|回复: 14

[AMXX 无源码] 发一个服务器限制玩家客户端命令插件

[复制链接]
发表于 2010-8-22 10:58:32 | 显示全部楼层 |阅读模式 来自 湖南株洲
本帖最后由 Sara 于 2010-8-22 11:38 编辑

这个插件能限制服务器所有玩家在一定时间内无法使用某些命令

官方下载地址:http://forums.alliedmods.net/showthread.php?p=702586

使用插件版本:AMXX 1.80以上

使用方法:

          在addons\amxmodx\configs\  目录下创建 command_limit.txt 文本

          文本内容:
  1. // Format: command type [limit] [time] [access]=格式:[命令] [时间] [类型]
  2. // type: cl, srv or con=类型:cl代表客户端,srv=服务器,con=代表服务器和客户端
  3. // limit: how many times the command can be used before the counter is reset (by time, if specified, or on round end)=被限制时间内使用命令的次数
  4. // time: Reset the command counter each (this) seconds=被限制的时间(秒计算)
  5. // access: Limit only valid for users with this admin flags. Use '*' for everyone. Check users.ini for more info=可以对服务器users.ini拥有权限的人限制,要是是所有完家那么请选Z
  6. //例如:限制客户端的玩家1分钟内只能执行amx_help一次,格式如下
  7. amx_help cl 1 60 z
复制代码
翻译的不好请见谅

插件源码:
  1. #include <amxmisc>

  2. #define TASKID_COUNTER_RESET 1000

  3. stock const iEmptyArray[33] = {0, ...}
  4. new Array:hCommandArray
  5. new Array:hLimitArray
  6. new Array:hCountArray
  7. new Array:hTimeArray
  8. new Array:hLevelArray

  9. public plugin_init()
  10. {
  11.         register_plugin("Command Limiter", "1.1", "danielkza")
  12.        
  13.         // This is cstrike only, but AFAIK, there's no universal alternative
  14.         register_logevent("RoundEnd_Event", 2, "1=Round_End")
  15.        
  16.         register_concmd("cmd_limit_reload",        "Reload_Command",        ADMIN_RCON)
  17.        
  18.         LoadConfig()       
  19. }

  20. public plugin_end()
  21. {
  22.         ArrayDestroy(hCommandArray)
  23.         ArrayDestroy(hLimitArray)
  24.         ArrayDestroy(hCountArray)
  25.         ArrayDestroy(hTimeArray)
  26. }

  27. public Reload_Command(id,level,cid)
  28. {
  29.         if(cmd_access(id,level,cid, 1))
  30.                 LoadConfig()
  31.        
  32.         return PLUGIN_HANDLED
  33. }

  34. public RoundEnd_Event()
  35. {
  36.         new iSize = ArraySize(hCountArray)
  37.        
  38.         for(new i=0; i < iSize; i++)
  39.                 ArraySetArray(hCountArray, i, iEmptyArray)
  40. }

  41. OpenFile(&iCreated = 0)
  42. {
  43.         static szFile[64]
  44.         if(!szFile[0])
  45.         {
  46.                 get_configsdir(szFile, charsmax(szFile))
  47.                 add(szFile, charsmax(szFile), "\command_limit.txt")
  48.         }
  49.        
  50.         new hFile = fopen(szFile,"r")
  51.         if(!hFile)
  52.         {
  53.                 hFile = fopen(szFile,"w+")
  54.                 if(hFile)
  55.                 {
  56.                         fprintf(hFile,
  57.                                 "// Format:        command type [limit] [time] [access]^n\
  58.                                 // command:        text of the command you want to be limited^n\
  59.                                 // type:        cl, srv or con^n")
  60.                         fprintf(hFile,
  61.                                 "// limit:        how many times the command can be used before the counter is reset (by time, if specified, or on round end)^n\
  62.                                 // time:        Reset the command counter each (this) seconds^n\
  63.                                 // access:        Limit only valid for users with this admin flags. Use '*' for everyone. Check users.ini for more info.^n^n\
  64.                                 // Example: 'amx_help cl 1 60 z' - Non-Admin clients can only use amx_help one time each 60 seconds")
  65.                        
  66.                         iCreated = true
  67.                 }
  68.         }
  69.         else
  70.                 iCreated = false
  71.        
  72.         return hFile
  73. }
  74.        
  75. LoadConfig(id = 0)
  76. {       
  77.         if(hCommandArray)
  78.         {
  79.                 ArrayClear(hCommandArray)
  80.                 ArrayClear(hLimitArray)
  81.                 ArrayClear(hCountArray)
  82.                 ArrayClear(hTimeArray)
  83.                 ArrayClear(hLevelArray)
  84.         }
  85.         else
  86.         {       
  87.                 hCommandArray = ArrayCreate(1)
  88.                 hLimitArray = ArrayCreate(1)
  89.                 hCountArray = ArrayCreate(33)
  90.                 hTimeArray = ArrayCreate(1)
  91.                 hLevelArray = ArrayCreate(1)
  92.         }
  93.        
  94.         new iCreated
  95.         new hFile = OpenFile(iCreated)
  96.        
  97.         if(!hFile)
  98.         {
  99.                 log_amx("[ERROR] Can't create/load command list file. Make sure 'command_limit.txt' exists on your configs folder, or that you have proper access.")
  100.                 set_fail_state("Can't load command list")
  101.                 return
  102.         }
  103.         else if(iCreated)
  104.                 goto CloseFile

  105.         new szTemp[128], szLimit[8], szType[8], szTime[8], szLevel[32]
  106.         new cid
  107.        
  108.         while(!feof(hFile))
  109.         {
  110.                 fgets(hFile, szTemp, charsmax(szTemp))
  111.                 if(!strlen(szTemp) || szTemp[0] == ';' || equali(szTemp, "//", 2))
  112.                         continue
  113.                
  114.                 trim(szTemp)
  115.                 if(!strlen(szTemp))
  116.                         continue
  117.                
  118.                 parse(szTemp, szTemp, charsmax(szTemp), szType, charsmax(szType), szLimit, charsmax(szLimit), szTime, charsmax(szTime), szLevel, charsmax(szLevel))
  119.                 if(!strlen(szTemp))
  120.                         continue
  121.                
  122.                 new iLimit = str_to_num(szLimit)
  123.                 if(!iLimit)
  124.                         continue
  125.                
  126.                 new Float:fTime = str_to_float(szTime)
  127.                
  128.                 new iLevel = ADMIN_ALL
  129.                 if(equali(szType, "srv"))
  130.                         cid = register_srvcmd(szTemp, "Command_Handler")
  131.                 else
  132.                 {
  133.                         if(equali(szType, "cl"))
  134.                                 cid = register_clcmd(szTemp, "Command_Handler")
  135.                         else
  136.                                 cid = register_concmd(szTemp, "Command_Handler")
  137.                        
  138.                         if(strlen(szLevel) && szLevel[0] != '*')
  139.                                 iLevel = read_flags(szLevel)
  140.                 }
  141.                
  142.                 if(cid)
  143.                 {
  144.                         ArrayPushCell(hCommandArray, cid)
  145.                         ArrayPushCell(hLimitArray, iLimit)
  146.                         ArrayPushArray(hCountArray, iEmptyArray)
  147.                         ArrayPushCell(hTimeArray, fTime)
  148.                         ArrayPushCell(hLevelArray, iLevel)
  149.                        
  150.                         if(fTime != 0.0)
  151.                                 set_task(fTime, "Command_Time_Task", cid+TASKID_COUNTER_RESET, _, _, "b")
  152.                 }
  153.         }
  154.        
  155.         CloseFile:
  156.         fclose(hFile)
  157.        
  158.         new iCount = ArraySize(hCommandArray)
  159.         server_print("[AMXX] %d command limits loaded.", iCount)
  160.         if(is_user_connected(id))
  161.                 console_print(id, "[AMXX] %d command limits loaded.", iCount)
  162. }

  163. public Command_Time_Task(cid)
  164. {
  165.         cid -= TASKID_COUNTER_RESET
  166.        
  167.         new iPos = ArrayFindInt(hCommandArray, cid)
  168.         if(iPos != -1)
  169.                 ArraySetArray(hCountArray, iPos, iEmptyArray)
  170. }
  171.                
  172. stock ArrayFindInt(const Array:hArray, const any:iSearch, const iStart = 0)
  173. {
  174.         if(hArray)
  175.         {
  176.                 new iSize = ArraySize(hArray)
  177.                 for(new i=iStart; i < iSize; i++)
  178.                 {
  179.                         if(ArrayGetCell(hArray, i) == iSearch)
  180.                                 return i
  181.                 }
  182.         }
  183.        
  184.         return -1
  185. }

  186. public Command_Handler(id, level, cid)
  187. {
  188.         new iPos = -1
  189.         while((iPos = ArrayFindInt(hCommandArray, cid, iPos+1)) != -1)
  190.         {       
  191.                 new iFlags = ArrayGetCell(hLevelArray, iPos)

  192.                 if(access(id, iFlags))
  193.                 {
  194.                         new iLimit = ArrayGetCell(hLimitArray, iPos)
  195.                         new iCount[33]
  196.                         ArrayGetArray(hCountArray, iPos, iCount)
  197.                        
  198.                         if(++iCount[id] > iLimit)
  199.                         {
  200.                                 client_print(id, print_console, "[ERROR] You reached the limit of %d uses for this command. Wait a while before using it again.", iLimit)
  201.                                 return PLUGIN_HANDLED
  202.                         }
  203.                        
  204.                         ArraySetArray(hCountArray, iPos, iCount)
  205.                 }
  206.         }
  207.        
  208.         return PLUGIN_CONTINUE
  209. }
  210.        
复制代码
源码打包

本帖子中包含更多资源

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

×
 楼主| 发表于 2010-8-22 11:22:08 | 显示全部楼层 来自 湖南株洲
沙发自己做,我服务器已经在用,2个月未出现任何状况。

欢迎大家测试
回复

使用道具 举报

发表于 2010-8-22 22:34:51 | 显示全部楼层 来自 浙江嘉兴
学习! 顶拉!!!!
回复

使用道具 举报

 楼主| 发表于 2010-8-24 10:39:17 | 显示全部楼层 来自 湖南株洲
呵呵,相信很多人在找这个样的插件,怎么就没顶

9527欢迎你来作客哈
回复

使用道具 举报

发表于 2010-8-25 01:49:50 | 显示全部楼层 来自 福建宁德
楼主,这款插件主要在什么情况下使用?我一时没理解这插件的作用。
回复

使用道具 举报

发表于 2010-9-6 23:56:36 | 显示全部楼层 来自 天津
你不想让别人用你的插件
回复

使用道具 举报

发表于 2010-9-14 23:19:38 | 显示全部楼层 来自 辽宁沈阳
YEAH!! 强帖
回复

使用道具 举报

发表于 2010-10-3 09:47:41 | 显示全部楼层 来自 湖北武汉
怎么我测试的命令无效啊

我的环境 cs1.5   amx1.81  

我就测试amx_help cl 1 60 z

用非管理员账号进入游戏后刷新几十次都行、、


还有怎么样禁止一个命令?  时间改成0  ?
回复

使用道具 举报

 楼主| 发表于 2010-10-3 21:47:40 | 显示全部楼层 来自 湖南株洲
8# decade


amx_help cl 1 60 z

amx_help不是刷新命令

你自己搞错了吧

是客户端玩家在控制执行 amx_help
回复

使用道具 举报

发表于 2010-10-13 09:34:11 | 显示全部楼层 来自 云南临沧
中文中文中文
回复

使用道具 举报

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

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