|
本帖最后由 Sara 于 2010-8-22 11:38 编辑
这个插件能限制服务器所有玩家在一定时间内无法使用某些命令
官方下载地址:http://forums.alliedmods.net/showthread.php?p=702586
使用插件版本:AMXX 1.80以上
使用方法:
在addons\amxmodx\configs\ 目录下创建 command_limit.txt 文本
文本内容:- // Format: command type [limit] [time] [access]=格式:[命令] [时间] [类型]
- // type: cl, srv or con=类型:cl代表客户端,srv=服务器,con=代表服务器和客户端
- // limit: how many times the command can be used before the counter is reset (by time, if specified, or on round end)=被限制时间内使用命令的次数
- // time: Reset the command counter each (this) seconds=被限制的时间(秒计算)
- // access: Limit only valid for users with this admin flags. Use '*' for everyone. Check users.ini for more info=可以对服务器users.ini拥有权限的人限制,要是是所有完家那么请选Z
- //例如:限制客户端的玩家1分钟内只能执行amx_help一次,格式如下
- amx_help cl 1 60 z
复制代码 翻译的不好请见谅
插件源码:- #include <amxmisc>
- #define TASKID_COUNTER_RESET 1000
- stock const iEmptyArray[33] = {0, ...}
- new Array:hCommandArray
- new Array:hLimitArray
- new Array:hCountArray
- new Array:hTimeArray
- new Array:hLevelArray
- public plugin_init()
- {
- register_plugin("Command Limiter", "1.1", "danielkza")
-
- // This is cstrike only, but AFAIK, there's no universal alternative
- register_logevent("RoundEnd_Event", 2, "1=Round_End")
-
- register_concmd("cmd_limit_reload", "Reload_Command", ADMIN_RCON)
-
- LoadConfig()
- }
- public plugin_end()
- {
- ArrayDestroy(hCommandArray)
- ArrayDestroy(hLimitArray)
- ArrayDestroy(hCountArray)
- ArrayDestroy(hTimeArray)
- }
- public Reload_Command(id,level,cid)
- {
- if(cmd_access(id,level,cid, 1))
- LoadConfig()
-
- return PLUGIN_HANDLED
- }
- public RoundEnd_Event()
- {
- new iSize = ArraySize(hCountArray)
-
- for(new i=0; i < iSize; i++)
- ArraySetArray(hCountArray, i, iEmptyArray)
- }
- OpenFile(&iCreated = 0)
- {
- static szFile[64]
- if(!szFile[0])
- {
- get_configsdir(szFile, charsmax(szFile))
- add(szFile, charsmax(szFile), "\command_limit.txt")
- }
-
- new hFile = fopen(szFile,"r")
- if(!hFile)
- {
- hFile = fopen(szFile,"w+")
- if(hFile)
- {
- fprintf(hFile,
- "// Format: command type [limit] [time] [access]^n\
- // command: text of the command you want to be limited^n\
- // type: cl, srv or con^n")
- fprintf(hFile,
- "// limit: how many times the command can be used before the counter is reset (by time, if specified, or on round end)^n\
- // time: Reset the command counter each (this) seconds^n\
- // access: Limit only valid for users with this admin flags. Use '*' for everyone. Check users.ini for more info.^n^n\
- // Example: 'amx_help cl 1 60 z' - Non-Admin clients can only use amx_help one time each 60 seconds")
-
- iCreated = true
- }
- }
- else
- iCreated = false
-
- return hFile
- }
-
- LoadConfig(id = 0)
- {
- if(hCommandArray)
- {
- ArrayClear(hCommandArray)
- ArrayClear(hLimitArray)
- ArrayClear(hCountArray)
- ArrayClear(hTimeArray)
- ArrayClear(hLevelArray)
- }
- else
- {
- hCommandArray = ArrayCreate(1)
- hLimitArray = ArrayCreate(1)
- hCountArray = ArrayCreate(33)
- hTimeArray = ArrayCreate(1)
- hLevelArray = ArrayCreate(1)
- }
-
- new iCreated
- new hFile = OpenFile(iCreated)
-
- if(!hFile)
- {
- 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.")
- set_fail_state("Can't load command list")
- return
- }
- else if(iCreated)
- goto CloseFile
- new szTemp[128], szLimit[8], szType[8], szTime[8], szLevel[32]
- new cid
-
- while(!feof(hFile))
- {
- fgets(hFile, szTemp, charsmax(szTemp))
- if(!strlen(szTemp) || szTemp[0] == ';' || equali(szTemp, "//", 2))
- continue
-
- trim(szTemp)
- if(!strlen(szTemp))
- continue
-
- parse(szTemp, szTemp, charsmax(szTemp), szType, charsmax(szType), szLimit, charsmax(szLimit), szTime, charsmax(szTime), szLevel, charsmax(szLevel))
- if(!strlen(szTemp))
- continue
-
- new iLimit = str_to_num(szLimit)
- if(!iLimit)
- continue
-
- new Float:fTime = str_to_float(szTime)
-
- new iLevel = ADMIN_ALL
- if(equali(szType, "srv"))
- cid = register_srvcmd(szTemp, "Command_Handler")
- else
- {
- if(equali(szType, "cl"))
- cid = register_clcmd(szTemp, "Command_Handler")
- else
- cid = register_concmd(szTemp, "Command_Handler")
-
- if(strlen(szLevel) && szLevel[0] != '*')
- iLevel = read_flags(szLevel)
- }
-
- if(cid)
- {
- ArrayPushCell(hCommandArray, cid)
- ArrayPushCell(hLimitArray, iLimit)
- ArrayPushArray(hCountArray, iEmptyArray)
- ArrayPushCell(hTimeArray, fTime)
- ArrayPushCell(hLevelArray, iLevel)
-
- if(fTime != 0.0)
- set_task(fTime, "Command_Time_Task", cid+TASKID_COUNTER_RESET, _, _, "b")
- }
- }
-
- CloseFile:
- fclose(hFile)
-
- new iCount = ArraySize(hCommandArray)
- server_print("[AMXX] %d command limits loaded.", iCount)
- if(is_user_connected(id))
- console_print(id, "[AMXX] %d command limits loaded.", iCount)
- }
- public Command_Time_Task(cid)
- {
- cid -= TASKID_COUNTER_RESET
-
- new iPos = ArrayFindInt(hCommandArray, cid)
- if(iPos != -1)
- ArraySetArray(hCountArray, iPos, iEmptyArray)
- }
-
- stock ArrayFindInt(const Array:hArray, const any:iSearch, const iStart = 0)
- {
- if(hArray)
- {
- new iSize = ArraySize(hArray)
- for(new i=iStart; i < iSize; i++)
- {
- if(ArrayGetCell(hArray, i) == iSearch)
- return i
- }
- }
-
- return -1
- }
- public Command_Handler(id, level, cid)
- {
- new iPos = -1
- while((iPos = ArrayFindInt(hCommandArray, cid, iPos+1)) != -1)
- {
- new iFlags = ArrayGetCell(hLevelArray, iPos)
- if(access(id, iFlags))
- {
- new iLimit = ArrayGetCell(hLimitArray, iPos)
- new iCount[33]
- ArrayGetArray(hCountArray, iPos, iCount)
-
- if(++iCount[id] > iLimit)
- {
- client_print(id, print_console, "[ERROR] You reached the limit of %d uses for this command. Wait a while before using it again.", iLimit)
- return PLUGIN_HANDLED
- }
-
- ArraySetArray(hCountArray, iPos, iCount)
- }
- }
-
- return PLUGIN_CONTINUE
- }
-
复制代码 源码打包
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注个册吧
×
|