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

TFS 0.X What is the best way to register many globalevents?

mRefaat

Marketing and Coding
Joined
Jan 18, 2014
Messages
854
Solutions
3
Reaction score
141
Location
Egypt
Hello

What is best way to register many global events?
I am asking because sometimes a conflict happen and one event can cancel another one because they happened st same time.

TFS 0.3.x
 
Last edited:
The best way is to configure a specific time for each event so that there is no way for them to collide, this in case such events can use the same resources and it is necessary that each one is executed at different times.

You can also create a single global event and runs a table of predesigned events, in this way each event will be executed at given intervals and without colliding at any time, obviously you must have a good iteration system, making use of variables where you can store the current index of the event that is being executed and in this way have control
 
You could use global storage for the events which you think might be conflicting. Before each event starts check whether any other event is active and in that case prevent the event from starting.
I think you didn't get what i mean, sometimes when i set an event at x hour, it conflicts with save maybe.

The best way is to configure a specific time for each event so that there is no way for them to collide, this in case such events can use the same resources and it is necessary that each one is executed at different times.

You can also create a single global event and runs a table of predesigned events, in this way each event will be executed at given intervals and without colliding at any time, obviously you must have a good iteration system, making use of variables where you can store the current index of the event that is being executed and in this way have control
A good idea and i was thinking to make something like that, but sometimes save cancel other events.
Another question, is there a way to make something like when time is now it load a file? (how i add all global events in 1 file?)
 
I think you didn't get what i mean, sometimes when i set an event at x hour, it conflicts with save maybe.


A good idea and i was thinking to make something like that, but sometimes save cancel other events.
Another question, is there a way to make something like when time is now it load a file? (how i add all global events in 1 file?)
Lua:
local event1 = {}
function event1.run()
end
local event2 = {}
function event2.run()
end
local event3 = {}
function event3.run()
end

local events = {
event1,
event2,
event3
}
local index = 1

function onThink()
local event = events[index]
if event then
event.run()
index = index +1
else
index = 1
end
return true
end

This is a very shabby example, but keep the idea that I mentioned
 
Lua:
local event1 = {}
function event1.run()
end
local event2 = {}
function event2.run()
end
local event 3= {}
function event3.run()
end

local events = {
event1,
event2,
event3
}
local index = 1

function onThink()
local event = events[index]
if event then
event.run()
index = index +1
else
index = 1
end
return true
end

This is a very shabby example, but keep the idea that I mentioned
I will try that, thanks.
 
Lua:
local event1 = {}
function event1.run()
end
local event2 = {}
function event2.run()
end
local event3 = {}
function event3.run()
end

local events = {
event1,
event2,
event3
}
local index = 1

function onThink()
local event = events[index]
if event then
event.run()
index = index +1
else
index = 1
end
return true
end

This is a very shabby example, but keep the idea that I mentioned
can you explain to me please the use of index = 1?

also what if i made a lib file for events i want to run and used 1 script in global events to check every 1 min the functions?
something like that
Lua:
function onThink(cid, interval, lastExecution)
    functionOne()
    functionTwo()
    functionThree()
    return true
end
 
Last edited:
Back
Top