
I want to convert the code for a skill in Dekar's Ranger addon into a hook. Here's the stuff I stripped out of Dekar's edited Actor.lua file with (what I think) is all the relevant code for the skill that tells the pet to defend the ranger at certain times.
Code: Select all
function _M:onTakeHit(value, src)
if self:attr("protect") then
if rng.percent(self.protect_chance) and not (self.ranger_pet==nil or self.ranger_pet.dead)then
local distance = core.fov.distance(self.x, self.y, self.ranger_pet.x, self.ranger_pet.y )
if (distance < 2) then
game.logSeen(self, "%s protects %s!", self.ranger_pet.name, self.name)
self.ranger_pet:takeHit(value, src)
value = 0
end
end
end
end
Code: Select all
class:bindHook("Actor:takeHit", function(self, data)
if self:hasEffect(self.EFF_DIPLOMATIC_IMMUNITY) then data.value = 0 return true end
end)
Code: Select all
local takeHit_hook = function(self, data)
-- Ki Shield
if self.isTalentActive and
self:knowTalent(self.T_KI_SHIELD) and
self:isTalentActive(self.T_KI_SHIELD)
then
local t = self:getTalentFromId(self.T_KI_SHIELD)
local pct = t.getPercent(self, t)
local absorb = math.min(data.value * 0.5, self:getStamina() / pct)
self:incStamina(-absorb * pct)
data.value = data.value - absorb
end
return true
end
class:bindHook("Actor:takeHit", takeHit_hook)