tibia-client/modules/core/dispatcher.lua

40 lines
846 B
Lua
Raw Normal View History

2011-11-07 01:14:51 +01:00
local eventId = 0
local eventsTable = { }
local orig = { scheduleEvent = scheduleEvent,
addEvent = addEvent }
-- fix original scheduleEvent
function scheduleEvent(func, delay)
2011-11-07 01:14:51 +01:00
eventId = eventId + 1
local id = eventId
local function proxyFunc()
if eventsTable[id] then
func()
2011-11-07 01:14:51 +01:00
eventsTable[id] = nil
end
end
eventsTable[id] = proxyFunc
orig.scheduleEvent(proxyFunc, delay)
return id
end
function removeEvent(id)
if id and eventsTable[id] then
eventsTable[id] = nil
end
end
-- fix original addEvent
function addEvent(func)
eventId = eventId + 1
2011-11-07 01:14:51 +01:00
local id = eventId
local function proxyFunc()
2011-11-07 01:14:51 +01:00
if eventsTable[id] then
func()
eventsTable[id] = nil
end
end
2011-11-07 01:14:51 +01:00
eventsTable[id] = proxyFunc
orig.addEvent(proxyFunc)
2011-11-07 01:14:51 +01:00
return id
end