• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Event launched every x seconds by an NPC

Status
Not open for further replies.

stfurca

Member
Hi guys.

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

I have already tried (just for testing):
Code:
local function init(event, creature, diff)
	if(cooldown <= 0) then
		creature:SendUnitYell(diff, 0)
		cooldown = 5000
	else
	    cooldown = cooldown - diff
	end
	
end

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.
 

Grandelf

Esteemed Member
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 method. To demonstrate this:

Code:
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); 
end

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

RegisterCreatureEvent(npcId, 1, onEnterCombat);

If for some reason, you want to stop the event from being executed you can use this method: WorldObject:RemoveEvents.

Also as a side note, this is the wrong section for this. You should post this in the support section.
 
Last edited:
Status
Not open for further replies.
Top