How you want to set up your new onTakeHit will kind of depend on what you want it do differently from the original. Basically, you will want to run the values through the original onTakeHit, making changes either before or after doing so (or both before and after, in some cases), and then return your new result.
Here are a couple examples from HousePet's Midnight and Verdant addons, respectively:
Code: Select all
local basetakeHit = _M.takeHit
function _M:takeHit(value, src, death_note)
-- Do stuff "before" loading the original file
local dead, val = basetakeHit(self, value, src, death_note) -- Loads the original file
-- Do stuff "after" loading the original file
if val and self:isTalentActive(self.T_HP_BLOOD_OF_THE_HEAVENS) then
self:incNegative(math.floor(val/10))
end
if dead and src then
if src:getEntityKind() == "actor" then
if src:knowTalent(src.T_HP_DISCIPLE_OF_DUSK) and src:isTalentActive(src.T_HP_DISCIPLE_OF_DUSK) then
local t = src:getTalentFromId(src.T_HP_DISCIPLE_OF_DUSK)
src:incNegative(t.getNegativeRegen(self, t))
end
end
end
return dead, val
end
and
Code: Select all
local basetakeHit = _M.takeHit
function _M:takeHit(value, src, death_note)
-- Do stuff "before" loading the original file
local dead, val = basetakeHit(self, value, src, death_note) -- Loads the original file
-- Do stuff "after" loading the original file
if dead and src then
if src:getEntityKind() == "actor" then
local summoner = src.summoner
if src:knowTalent(src.T_HP_FERTILIZE) then
local t = src:getTalentFromId(src.T_HP_FERTILIZE)
t.doFertilize(src, t, self)
elseif summoner then
if summoner:knowTalent(summoner.T_HP_FERTILIZE) then
local t = summoner:getTalentFromId(summoner.T_HP_FERTILIZE)
t.doFertilize(summoner, t, self)
end
end
end
end
return dead, val
end
Looks like you would want to use "local dead, val = onTakeHit(self, value, src, death_note)" to get your original return value (or, in this case, values, as it looks like it returns two). So, in your case:
Code: Select all
local onTakeHit = _M.onTakeHit
function _M:onTakeHit(value, src, death_note)
local dead, val = onTakeHit(self, value, src, death_note)
...
return dead, val
The "src = src or {}" and "if value <=0 then return 0 end" are in the original onTakeHit, so you don't really need to have this in your new onTakeHit, unless you want to change how that part of the function works. If you do want to change that, you should drop that above HP's note of "do stuff 'before' loading the original file" (neither of these examples actually makes changes before loading the original, only after).
Whenever I get into this stuff, I basically rip open other mods until I find one that does something similar to what I'm trying to do, copy and change it, then proceed with trial and error until I get it to do what I want it to.
And when that fails, turn to #tome on rizon IRC. Put your question out there and idle, odds are someone will be able to help you out.
Hopefully that was more helpful than confusing
