tibia-client/modules/core_scripts/dispatcher.lua

43 lines
946 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()
2011-11-07 18:20:13 +01:00
if eventsTable[id] then
func()
eventsTable[id] = nil
end
2011-11-07 01:14:51 +01:00
end
eventsTable[id] = proxyFunc
orig.scheduleEvent(proxyFunc, delay)
return id
end
2011-11-07 18:20:13 +01:00
-- FIXME: the event function can be collected
-- and the dispatcher would call an invalid function, generating an warning
2011-11-07 01:14:51 +01:00
function removeEvent(id)
if id and eventsTable[id] then
eventsTable[id] = nil
2011-11-07 18:20:13 +01:00
return true
2011-11-07 01:14:51 +01:00
end
end
-- fix original addEvent
function addEvent(func)
2011-11-07 18:20:13 +01:00
eventId = eventId + 1
local id = eventId
local function proxyFunc()
if eventsTable[id] then
func()
eventsTable[id] = nil
end
2011-11-07 18:20:13 +01:00
end
eventsTable[id] = proxyFunc
orig.addEvent(proxyFunc)
return id
end