Skip to content

Instantly share code, notes, and snippets.

@zach2good
Last active December 14, 2020 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zach2good/3a2d6973be2454760f30eeea78121abf to your computer and use it in GitHub Desktop.
Save zach2good/3a2d6973be2454760f30eeea78121abf to your computer and use it in GitHub Desktop.
-- Original code
tpz = {}
tpz.mob = {}
tpz.mob.onAttack = function(amount)
return amount
end
print('Original call: ', tpz.mob.onAttack(100))
-- Prints 100
-- 'Module' helper
module = {}
module.override = function(base_table, name, func)
local old = base_table[name]
local thisenv = getfenv(old)
local env = { super = old }
setmetatable(env, { __index = thisenv })
setfenv(func, env)
base_table[name] = func
end
-- Module content
module.override(tpz.mob, "onAttack", function(amount)
return super(amount) * 1.5
end)
-- Runtime call
print('Call after module applied: ', tpz.mob.onAttack(100))
-- Prints 150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment