Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want lua function to run once

I'm quite new to lua scripting.. now i'm trying to code in game 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

this should make the boss talk when his health = 60% or less but it should run one time, when I run the code the boss keep saying and attacking all the time. How can I make it run once?

like image 717
MiDo Avatar asked Mar 05 '26 07:03

MiDo


1 Answers

Use a boolean created outside the scope of the function callback:

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

EDIT

If you are actually using the Eluna Engine's RegisterEvent call, then set the number of repeats to 1 and not 0. This will resolve the issue you had.

like image 106
hjpotter92 Avatar answered Mar 07 '26 03:03

hjpotter92



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!