Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local class = {}
- local events = {}
- local mt = {
- __index = function(t, i)
- for name,func in pairs(t) do
- if name:lower() == i:lower() then
- return func
- end
- end
- end
- }
- function class:GetEvents()
- return events
- end
- function class:GetEvent(id)
- return self[id] or nil
- end
- function class:CreateEvent(id)
- local event = {}
- local connections = {}
- function event:Connect(func)
- local connection = {}
- connection['func'] = func
- connection['enabled'] = true
- function connection:Disconnect()
- connection['func'] = nil
- connection['enabled'] = false
- connection = nil
- end
- setmetatable(connection, mt)
- table.insert(connections, connection)
- return connection
- end
- function event:DisconnectAll()
- connections = {}
- end
- function event:Fire(...)
- for i,connection in pairs(connections) do
- if connection and table.find(connections, connection) and connection.func and connection.enabled == true then
- connection.func(...)
- end
- end
- end
- setmetatable(event, mt)
- local ID = id or #self
- self[ID] = event
- return event
- end
- setmetatable(class, mt)
- return class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement