Hooks hooks
Part of D20
Hooks called by D20
Summary
Hooks
Hooks
Lets plugins change the armor class of a player or an NPC, which an attack roll against
them has to reach to hit. Called on either realm every time get_armor_class is called
on a player or an entity, after the armor class has been worked out: 10, plus the
reflexes of a player, plus 2 while they wear armor; the 'd20_npc_armor_class' config for
anything else. Every handler may change the table, so a handler should return nothing to
let the others run.
-- Riot shields make their bearer harder to hit.
function MyPlugin:AdjustArmorClass(target, info)
if target:IsPlayer() and target:has_item('riot_shield') then
info.value = info.value + 2
end
end
Parameters
- target Entity The player or NPC whose armor class is asked for
- info Map Modified in place: value (Number the armor class)
Called from
adjust_armor_class
Call sites
Lets plugins change an attack roll before it is made. Called on the server from
D20:attack_roll, after the formula and the armor class have been worked out. Every
handler may change the table, so a handler should return nothing to let the others
run.
-- Attacking from behind is easier.
function MyPlugin:AdjustAttackRoll(attacker, target, info)
if target:GetAimVector():Dot(attacker:GetAimVector()) > 0.5 then
info.formula = info.formula..' + 2'
end
end
Parameters
- attacker Entity The player or NPC making the attack
- target Entity The entity being attacked
- info Map Modified in place: formula (String the dice formula to roll, '1d20 + 5' for a modifier of 5), armor_class (Number what the total has to reach to hit), modifier (Number the attack modifier and bonus, already part of the formula), bonus (Number the bonus given to
D20:attack_roll, if any), variables (Map or function of the formula variables, if any)
Called from
Call sites
Lets plugins change the dice that a hit on a player or an NPC rolls. Called on the server for every hit that is rolled, after the formula has been picked and before the roll, while the 'd20_enabled' config is on. Not called for fall damage, drowning and the extra damage events of an attack that has already been rolled. Every handler may change the table, so a handler should return nothing to let the others run.
-- Hits from behind roll an extra die.
function MyPlugin:AdjustDamageDice(attacker, victim, damage_info, info)
if IsValid(attacker) and victim:GetAimVector():Dot(attacker:GetAimVector()) > 0.5 then
info.formula = '('..info.formula..') + 1d6'
end
end
Parameters
- attacker Entity The entity responsible for the damage
- victim Entity The player or NPC taking the damage
- damage_info CTakeDamageInfo The damage, still with the amount of the engine; changing the amount has no effect
- info Map Modified in place: formula (String the dice formula to roll), variables (Map the variables of the formula, see
D20:get_variables), source (String where the formula comes from, seeD20:get_damage_formula)
Called from
Call sites
PlayerDamageRolled(attacker, victim, damage_info, result, info)
server plugins/d20/plugin/sv_plugin.lua:420Called on the server after the damage of a hit on a player or an NPC has been rolled and set, before the damage is dealt. The damage can still be changed or blocked by the damage handlers that run afterwards. The return value is ignored: return nothing, so that other handlers run.
Parameters
- attacker Entity The entity responsible for the damage
- victim Entity The player or NPC taking the damage
- damage_info CTakeDamageInfo The damage, with the rolled amount times the hit location multiplier
- result Map The Dice result of the roll: total, formula, rolls, natural and critical, see
Dice.roll - info Map The formula, variables and source that were rolled, see AdjustDamageDice