Hooks called by Damage

Summary

Hooks

Lets plugins change how much health a player regenerates at once.
Asks whether a player who has run out of breath takes drowning damage.
Asks whether a player may regenerate health right now.
Called on the server after damage to a player has been processed by the engine, from the Damage plugin's PostEntityTakeDamage handler.
Called on the server when a player is about to take damage, before it is applied.
Lets a plugin work out the amount of damage a player is about to take from scratch, such as by rolling dice for it.

Hooks

GetHealthRegeneration(target, amount)

server plugins/damage/plugin/sv_plugin.lua:186

Lets plugins change how much health a player regenerates at once. Called on the server right before the player is healed, after PlayerCanRegenerateHealth.

Parameters

  • target Player The player about to be healed
  • amount Number Health the player would gain: the 'health_regen_amount' config

Returns

  • Number Health to give instead, rounded to a whole number; 0 or less gives none. Return nothing to keep the amount and let other handlers run

Called from

Call sites

PlayerCanDrown(target)

server plugins/damage/plugin/sv_plugin.lua:317

Asks whether a player who has run out of breath takes drowning damage. Called on the server each time the damage is due, that is every 'drowning_interval' seconds while the player has been completely under water for longer than the 'drowning_time' config. Only runs while the 'drowning' config is on.

Parameters

  • target Player The player who is drowning

Returns

  • Boolean Return false to spare the player this time, e.g. for a breathing apparatus. Return nothing to let other handlers decide

Called from

Call sites

PlayerCanRegenerateHealth(target)

server plugins/damage/plugin/sv_plugin.lua:174

Asks whether a player may regenerate health right now. Called on the server each time a hurt, living player is due to be healed by the health regeneration, which only runs while the 'health_regen' config is on.

Parameters

  • target Player The player about to be healed

Returns

  • Boolean Return false to skip this heal; the player waits a full interval for the next one. Return nothing to let other handlers decide

Called from

Call sites

PostPlayerTakeDamage(entity, damage_info, took, hitgroup)

server plugins/damage/plugin/sv_hooks.lua:131

Called on the server after damage to a player has been processed by the engine, from the Damage plugin's PostEntityTakeDamage handler. By now every handler has had its say about the damage and the health of the player is already reduced; a player killed by the damage is dead. The return value is ignored: return nothing, so that other handlers run.

Parameters

  • victim Player The player who was attacked
  • damage_info CTakeDamageInfo The damage that was dealt, with the changes every handler has made to it
  • took Boolean Whether the player has actually taken the damage, as the engine reports it to PostEntityTakeDamage
  • hitgroup Number HITGROUP_ enum of the hit location; HITGROUP_GENERIC when the damage does not come from a bullet or melee hit

Called from

Call sites

PrePlayerTakeDamage(entity, damage_info, hitgroup)

server plugins/damage/plugin/sv_hooks.lua:86

Called on the server when a player is about to take damage, before it is applied. Change damage_info in place to adjust the damage, or return false to cancel it. Runs from the Damage plugin's EntityTakeDamage handler, after ResolvePlayerDamage and the hit location and fall damage multipliers. The EntityTakeDamage handlers of the schema and of the plugins loaded after this one run later and may still change or block the damage; use PostPlayerTakeDamage for what was dealt in the end.

Parameters

  • victim Player The player about to take the damage
  • damage_info CTakeDamageInfo The damage being dealt
  • hitgroup Number HITGROUP_ enum of the hit location; HITGROUP_GENERIC when the damage does not come from a bullet or melee hit

Returns

  • Boolean Return false to cancel the damage: nothing is dealt and no further handler runs. Return nothing to let other handlers run

Called from

Call sites

ResolvePlayerDamage(entity, damage_info, hitgroup)

server plugins/damage/plugin/sv_hooks.lua:60

Lets a plugin work out the amount of damage a player is about to take from scratch, such as by rolling dice for it. Called on the server from the Damage plugin's EntityTakeDamage handler for every damage to a player, before the fall damage multiplier and before PrePlayerTakeDamage, so that both of them, and every EntityTakeDamage handler after the plugin, see the amount that was set here. The hit location multiplier of a bullet or melee hit has already been applied to the damage by then; a handler that replaces the amount applies Damage:get_hitgroup_scale(hitgroup) to it again.

-- Every hit deals exactly 10 damage before the multipliers.
function MyPlugin:ResolvePlayerDamage(victim, damage_info, hitgroup)
  if !damage_info:IsFallDamage() then
    damage_info:SetDamage(10 * Damage:get_hitgroup_scale(hitgroup))
  end
end

Parameters

  • victim Player The player about to take the damage
  • damage_info CTakeDamageInfo The damage being dealt, changed in place
  • hitgroup Number HITGROUP_ enum of the hit location; HITGROUP_GENERIC when the damage does not come from a bullet or melee hit

Returns

  • Boolean Return true to block the damage: nothing is dealt and no further handler runs. Return nothing to let other handlers run

Called from

Call sites

Defined in