文字MUD游戏论坛-天下泥潭群英会-水泊梁山

文字MUD游戏论坛-天下泥潭群英会-水泊梁山 (http://www.aolai.org/forums/)
-   『 机器人制作及下载 』 (http://www.aolai.org/forums/f5/)
-   -   MushClient一个防止重复触发的例子 (http://www.aolai.org/forums/t20374/)

sansouci 2019-02-20 16:38

MushClient一个防止重复触发的例子
 
首先感谢grimlock建议,现在改成了两个版本。
直接上lua代码:

代码:

--第一个版本,封装一个临时timer,使连续相同触发时只有第一个触发有效
function ExecFirstTriCmd(cmd,tName,sTime)
--[[       
                cmd:string,待执行的mud指令字符串
                sTime:float,最小0.5,禁止重复触发的时间长度,单位:s
                tName:string,timer名称
--]]
        if not sTime then sTime = 2        end
        if not tName then tName = "abcdeTimer" end
        if not cmd then
                print("Error: cmd不能为空!看到该信息表明未来sTime秒或2秒内什么也不会执行!")
                cmd = ''
        end
        local _,s = GetTimer(tName)
        if not s then
                AddTimer(tName, 0, 0, sTime, '', timer_flag.Enabled + timer_flag.OneShot, "")
                SetTimerOption(tName, "send_to", 12)
                Execute(cmd)
                print('This cmd will not be executed again in '..sTime..' seconds.')
        end
end


--第二个版本,封装一个临时timer,使连续相同触发时只有第一个触发有效
function ExecFirstTriScript(script,tName,sTime)
--[[       
                script:string,待执行的脚本
                sTime:float,最小0.5,禁止重复触发的时间长度,单位:s
                tName:string,timer名称
--]]
        if not sTime then sTime = 2        end
        if not tName then tName = "abcdeTimer" end
        if not script then
                print("Error: script不能为空!看到该信息表明未来sTime秒或2秒内什么也不会执行!")
                script = ''
        end
        local _,s = GetTimer(tName)
        if not s then
                AddTimer(tName, 0, 0, sTime, '', timer_flag.Enabled + timer_flag.OneShot, "")
                SetTimerOption(tName, "send_to", 12)
                DoAfterSpecial(0.5,script,12)
                print('This script will not be executed again in '..sTime..' seconds.')
        end
end

当然由于上面的函数参数不是(name, line, wildcards, styles)格式,不适合纯脚本模式,要做成纯脚本模式需要做一些取舍与修改。
欢迎各种技术上的砖头~

grimlock 2019-02-20 22:50

回复: MushClient一个防止重复触发的例子
 
对上你的论坛id了,之前看过不少你的贴子。除了看数据增长,编写机器是这个游戏的主要乐趣了,多多分享机器经验啊!


所有时间均为格林尼治时间 +9, 现在的时间是 00:54.

Powered by SPLS
版权所有 2001-2023 水泊梁山
皖ICP备05012024号

站长 fengyue


Content Relevant URLs by vBSEO 3.6.1