diff --git a/main.lua b/main.lua index a2530bf..171a88d 100644 --- a/main.lua +++ b/main.lua @@ -30,6 +30,7 @@ function Main:Init() o.impls = {} o.initializedImpls = {} o.lastTimeImplRegistered = 0 + o.onReadyCallbacks = {} o.ready = false if not IsDuplicityVersion() then o.playerId = PlayerId() @@ -63,6 +64,11 @@ function Main:Init() return o end +function Main:ListenOnReady(handler) + if self.ready then return handler() end + table.insert(self.onReadyCallbacks, handler) +end + if not IsDuplicityVersion() then function Main:Thread1() Citizen.CreateThread(function() @@ -296,6 +302,10 @@ function Main:InitImplAfterPlayerLoaded() }) end self.ready = true + for k, v in ipairs(self.onReadyCallbacks) do + v() + end + self.onReadyCallbacks = {} end function Main:GetImpl(name) @@ -333,6 +343,10 @@ end main = Main:Init() +AddEventHandler(("%s:onReady"):format(GetCurrentGameName()), function(handler) + main:ListenOnReady(handler) +end) + --[[ local origAddEventHandler = AddEventHandler function AddEventHandler(eventName, ...) if RegisteredEvents[eventName] then