• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua StopEvent in another script

Sherice

Sky&Wind
Joined
Jan 20, 2012
Messages
183
Reaction score
7
Location
Sweden
Hai, everyone!

How can I stop an event in a script, with another script?
E.g. in a spell script, I add an event with a time, let's say 5 seconds, then it will happen something. How can I stop the event with the function "stopEvent" in another script?

Thaaaanks in advance for the helps!
Sherice.
 
addEvent returns internal ID of the event, store it in a global storage:
Lua:
doSetStorage(123, addEvent(callback, delay, params))
stopEvent takes 1 argument, the event ID. use it like this in the other script:
Lua:
stopEvent(getStorage(123))
doSetStorage(123, nil)
if you try to stop an event that wasn't initiated from the same scripting interface (eg. spells and talkactions) you'll probably get a crash
 
Basically it could be possible to store an addevent ID in a global variable and execute another script to stop it?

Lua:
myID = 0
function onUse(..)
myID = addEvent(...)
end
next
Lua:
function onSay(...)
stopEvent(myID)
end

Or am I getting this wrong?
 
Basically it could be possible to store an addevent ID in a global variable and execute another script to stop it?

Lua:
myID = 0
function onUse(..)
myID = addEvent(...)
end
next
Lua:
function onSay(...)
stopEvent(myID)
end

Or am I getting this wrong?
first, values of global variables are different for each interface (actions and talkactions)
second, stopping an event started from a different interface would crash the server
third, using global storage instead of global variables is preferred (doesn't perish on interface reload)

other than that, you got how it works
 
yes, you have to do it in a different way

maybe set some global storage, then add a check to your addEvent callback function whether that storage is set, and if so terminate exection
Lua:
function callback(params)
	if getStorage(1234) == 1 then
		return -- this stops further processing
	end

	-- your code here
end

addEvent(callback, 10 * 1000, ...)
 
Uh does it all have to be a global storage?

[EDITZORS]: Well, anyways, it worked, thanks once again =)
 
Last edited:
Back
Top