diff --git a/impl.lua b/impl.lua index 134c896..24ce5b9 100644 --- a/impl.lua +++ b/impl.lua @@ -114,11 +114,18 @@ end function Impl:Destroy() self.destroyed = true main:LogInfo("%s destroyed", self.name) + for k, v in pairs(self.eventHandlers) do + RemoveEventHandler(v) + end + self:OnDestroy() end function Impl:OnReady(...) end +function Impl:OnDestroy(...) +end + function Impl:HookMethod(method, hookFn) local oldMethod = self[method] if not oldMethod then @@ -196,6 +203,14 @@ function Impl:Off(name, handler) main:LogError("Event %s:%s not registered", self.name, name) end +function Impl:AddEventHandler(eventName, ...) + self.eventHandlers[eventName] = AddEventHandler(eventName, ...) +end + +function Impl:RegisterNetEvent(eventName, ...) + self.eventHandlers[eventName] = RegisterNetEvent(eventName, ...) +end + if env == 'sv' then function Impl:Callback(impl, name, source, ...) if type(impl) == "object" then