• 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!

How to stop multiple events

Lucas Durais

New Member
Joined
Jan 13, 2017
Messages
40
Reaction score
1
Hello guys

I want to know if there is a way of stopping a lot of events in the same time without creating a lot of stopEvent functions...

I tried to do like:
Code:
for i = 1, 100 do
     stopEvent(event+[i])
end

But I get nil value for event

Thanks!
 
Solution
Thanks for the replys guys

I tried to put all the events with the same name, for example, event1, and stop them all with just stopEvent(event1), but also doesn't work
Why is that?
because you cant do that, if you keep assigning values to the same variable they will be overwritten
unless you use a table and add a new index for each event
Lua:
local events = {}
for i = 1, 10 do
    events[i] = addEvent(function() print(i) end, 10000)
end
and use this to stop them
Lua:
for i = 1, 10 do
    stopEvent(events[i])
end
you don't need to use a stopEvent every time you use addEvent
if you're planning on using stopEvent, do what wibbenz said and save it in a table or variable somewhere so you can access it later
an example would be like this:
Lua:
events = {}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cid = player:getId()
    if events[cid] then
        stopEvent(events[cid])
    end
    events[cid] = addEvent(function() print(100) end, 5000)
    return true
end
saved an event id to events table using player id as the table key, so if the player keeps using the item, it will stop the old event and add a new one
if you wanted to create multiple events with the same player id, you can have a table like
events[cid] = {}
and then use a loop to add events to that new table
 
Thanks for the replys guys

I tried to put all the events with the same name, for example, event1, and stop them all with just stopEvent(event1), but also doesn't work
Why is that?
 
Thanks for the replys guys

I tried to put all the events with the same name, for example, event1, and stop them all with just stopEvent(event1), but also doesn't work
Why is that?
because you cant do that, if you keep assigning values to the same variable they will be overwritten
unless you use a table and add a new index for each event
Lua:
local events = {}
for i = 1, 10 do
    events[i] = addEvent(function() print(i) end, 10000)
end
and use this to stop them
Lua:
for i = 1, 10 do
    stopEvent(events[i])
end
 
Solution
Back
Top