发一个服务器限制玩家客户端命令插件
本帖最后由 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 =格式:[命令] [时间] [类型]
// 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 = {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
if(!szFile)
{
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 ^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(" 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, szLimit, szType, szTime, szLevel
new cid
while(!feof(hFile))
{
fgets(hFile, szTemp, charsmax(szTemp))
if(!strlen(szTemp) || szTemp == ';' || 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 != '*')
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(" %d command limits loaded.", iCount)
if(is_user_connected(id))
console_print(id, " %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
ArrayGetArray(hCountArray, iPos, iCount)
if(++iCount > iLimit)
{
client_print(id, print_console, " 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
}
源码打包
沙发自己做,我服务器已经在用,2个月未出现任何状况。
欢迎大家测试 学习! 顶拉!!!! 呵呵,相信很多人在找这个样的插件,怎么就没顶
9527欢迎你来作客哈 楼主,这款插件主要在什么情况下使用?我一时没理解这插件的作用。 你不想让别人用你的插件 YEAH!! 强帖 怎么我测试的命令无效啊
我的环境 cs1.5 amx1.81
我就测试amx_help cl 1 60 z
用非管理员账号进入游戏后刷新几十次都行、、
还有怎么样禁止一个命令?时间改成0? 8# decade
amx_help cl 1 60 z
amx_help不是刷新命令
你自己搞错了吧
是客户端玩家在控制执行 amx_help 中文中文中文
页:
[1]
2