2019-02-20 | #1 |
高级会员
注册: 08年10月01日
来自: 客栈
帖子: 165
声望力: 18
声望:
43
积分:8
精华:1
现金:55两梁山币
资产:1282两梁山币
致谢数: 0
获感谢文章数:0
获会员感谢数:0 |
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 欢迎各种技术上的砖头~ |
|
2019-02-20 | #2 |
正式会员
注册: 14年09月29日
来自: 广东深圳
帖子: 8
声望力: 0
声望:
10
现金:16两梁山币
资产:16两梁山币
致谢数: 0
获感谢文章数:0
获会员感谢数:0 |
回复: MushClient一个防止重复触发的例子
对上你的论坛id了,之前看过不少你的贴子。除了看数据增长,编写机器是这个游戏的主要乐趣了,多多分享机器经验啊!
|
断断续续玩了几年,代码看了几圈,机器写了不少,大米练了一批,就差主ID了,addoil!
|
|
|