我希望lua函数运行一次
我对lua脚本非常陌生。。现在我正试着在游戏《老大》中编写代码我希望lua函数运行一次,lua,azerothcore,eluna-lua-engine,Lua,Azerothcore,Eluna Lua Engine,我对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) --
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
本地功能SlitTheEvents(事件、生物、攻击者、伤害)
如果(生物:GetHealthPct()使用在函数回调范围外创建的布尔值:
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
local has\u=false
本地功能滑动事件(事件、生物、攻击者、伤害)
如果生物:GetHealthPct()他只喊了一次,这很好,他一直在使用这个拼写。这似乎是一个糟糕的解决办法,事件仍在启动,与其让事件什么都不做,不如断开事件本身。他很可能在循环中调用这个函数,检查应该在该函数的循环中进行,也许提到这就是答案?@warspyking你如何定义在love/garry's-mode/任何OP使用的模式中注册它们!看起来好像是为了@MiDo注释,Sliterevents
很可能用于多个生物。它们都共享has_talk
值。这意味着,如果使用此脚本的10个生物中有一个会说话,那么其他任何生物都不会说话。要修复此问题,您需要存储每个生物的布尔值。例如生物:SetData('talked',true)
和以后的如果生物:GetData('talked'),则
。GetData和SetData的详细信息可在