Trying to set up a template for adding new talents on birth, so that I can play around with stuff. Have got this working with superloading, of which I'm proud (and grateful for help from this forum). I imagine that I could be doing the same thing with hooks instead. Would that be preferable? If so, I might need a little bit of help with it
Here's my superloaded code in mod/class/player.lua
Code: Select all
local _M = loadPrevious(...)
local base_onBirth = _M.onBirth
function _M:onBirth(birther)
if not game.player:knowTalent(T_NEW_TALENT) then
game.logSeen(self, "Player does not know new talent, adding.")
game.player:learnTalent(game.player.T_NEW_TALENT, true, 1, {no_unlearn=true})
else
game.logSeen(self, "Player already knows new talent.")
end
return base_onBirth(self, birther)
end
return _M
Like I was saying, this works fine. It's just that I imagine I could hook it onto onBirth instead. Would that be preferable? Why or why not? Can I hook off of any function, or only special, hookable functions?