我想要 lua 函数到 运行 一次

I want lua function to run once

我对 lua 脚本编写还很陌生.. 现在我正在尝试在游戏 boss 中编写代码

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% 或更少时说话,但它应该 运行 一次,当我 运行 老板一直在说和攻击的代码时。我怎样才能做到运行一次?

使用在函数回调范围之外创建的布尔值:

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 call, then set the number of repeats to 1 and not 0. This will resolve the