Skip to content

Instantly share code, notes, and snippets.

@irfan-dahir
Last active February 20, 2018 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irfan-dahir/9404a96d24c2c52ed2b496f835b4857e to your computer and use it in GitHub Desktop.
Save irfan-dahir/9404a96d24c2c52ed2b496f835b4857e to your computer and use it in GitHub Desktop.
--[[
Hook Management API
v0.0.0 - major.minor.patch
]]
Hook = {}
Hook.__index = Hook
HookCallable = {}
HookEvent = {}
--__addhook = addhook
function Hook:New()
local self = setmetatable({}, Hook)
return self
end
function Hook:Create(hookName, args)
loadstring('HookCallable.'..hookName..' = function('..args..') self.Event('..args..') end')(unpack(args:split(",")))
addhook(hookName, "HookCallable."..hookName)
end
-- thanks to http://www.unrealsoftware.de/forum_posts.php?post=419447&start=0#post419482
function string:split(m)
local tbl = {}
for w in self:gmatch("[^" .. (m or "%s") .. "]+") do
table.insert(tbl, w)
end
return tbl
end
@irfan-dahir
Copy link
Author

irfan-dahir commented Feb 20, 2018

Using it:

hook:Create('join', 'id', id)
hook:Create('die', 'victim, killer, wep, x, y, kObjID', victim, killer, wep, x, y, kObjID)

@irfan-dahir
Copy link
Author

Can be used like this now, thanks to http://www.unrealsoftware.de/forum_posts.php?post=419447&start=0#post419482

hook:Create('join', 'id')
hook:Create('die', 'victim, killer, wep, x, y, kObjID')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment