View Full Version : [SOLVED] Event launched every x seconds by an NPC

02-12-2016, 10:07 AM
Hi guys.

I need to create an infinite script with a x seconds delay.

I have already tried (just for testing):

local function init(event, creature, diff)
if(cooldown <= 0) then
creature:SendUnitYell(diff, 0)
cooldown = 5000
cooldown = cooldown - diff


RegisterCreatureEvent(npcId, 7, init)

But it still does not work, because the diff is shared on every NPC I think.

I need to script an NPC, which spams a spell every x seconds/millis. In C++ it's easy, but I assume that in Eluna it's easier.

If someone has something like this, I would be grateful.

02-12-2016, 12:15 PM
You are correct saying that the cooldown is shared for every creature that uses this script.
This is because (for as far as I can tell) cooldown is a global variable.

If you simply want to make a creature cast a spell every x amount of seconds, lets say when he enters combat,
you can use the WorldObject:RegisterEvent (http://eluna.emudevs.com/WorldObject/RegisterEvent.html) method. To demonstrate this:

local function onEnterCombat(event, creature)
-- Delay is 10 seconds (10000 ms).
-- The 0 means that the event will be repeated an infinite amount of times.
creature:RegisterEvent(castSomeSpell, 10000, 0);

-- Notice that this function has the same name as registered above.
local function castSomeSpell(eventId, delay, repeats, creature)
-- Do stuff here

RegisterCreatureEvent(npcId, 1, onEnterCombat);

If for some reason, you want to stop the event from being executed you can use this method: WorldObject:RemoveEvents (http://eluna.emudevs.com/WorldObject/RemoveEvents.html).

Also as a side note, this is the wrong section for this. You should post this in the support section.

02-12-2016, 01:44 PM
Sorry for wrong section - I can't move my post :(

Working like a charm, thanks!