我对lua脚本是个新手..现在我正试着在游戏中编码老大
local function SlitherEvents(event, creature, attacker, damage)
if(creature:GetHealthPct() <= 60) then
creature:SendUnitYell("Will punish you all",0)
creature:RegisterEvent(AirBurst, 1000, 0) -- 1 seconds
return
end
end
这应该会让老板在他的健康= 60%或更少的时候说话,但它应该运行一次,当我运行代码的时候,老板一直在说和攻击。怎样才能让它运行一次呢?
发布于 2017-02-13 07:32:31
使用在函数回调作用域之外创建的布尔值:
local has_talked = false
local function SlitherEvents(event, creature, attacker, damage)
if creature:GetHealthPct() <= 60 and not has_talked then
has_talked = true
creature:SendUnitYell("Will punish you all",0)
creature:RegisterEvent(AirBurst, 1000, 1) -- 1 seconds
return
end
end
编辑
如果您实际使用的是Eluna Engine's RegisterEvent
调用,则将重复次数设置为1,而不是0。这将解析issue you had。
https://stackoverflow.com/questions/42194327
复制相似问题