Damage adds configurable rules to the damage players take, and to how they recover.
Everything is set through the config keys of the damage category, and with the default
values the plugin changes nothing about the game.
Hits are multiplied by hit location (damage_scale_head, damage_scale_chest,
damage_scale_stomach, damage_scale_arms, damage_scale_legs) and falls by
damage_scale_fall. The multipliers are applied to the damage in place, on top of whatever
the gamemode, the schema and other plugins do in their own ScalePlayerDamage,
FLGetFallDamage and EntityTakeDamage handlers: the handlers of the plugin return
nothing, so the others still run. health_regen slowly heals hurt players, drowning
hurts players who stay under water for too long with damage rolled from the
drowning_damage dice formula (1d4 by default), damage_view_punch jolts the view of a
player who is hurt, and log_damage and log_kills write the damage players take and
their deaths to the log; staff with the 'view_damage_logs' permission see these entries in
their console.
Other plugins take part through hooks. ResolvePlayerDamage lets a plugin replace the
amount of any damage to a player before the fall damage multiplier and the other hooks see
it (the D20 plugin rolls dice there), PrePlayerTakeDamage runs before a player takes
damage and can change or cancel it, and PostPlayerTakeDamage runs once the damage has
been dealt. PlayerCanRegenerateHealth and GetHealthRegeneration control the health
regeneration of a player, and PlayerCanDrown exempts a player from drowning.
Summary
Hooks
FLGetFallDamage hook or the formula of the gamemode), and lets the PrePlayerTakeDamage hook change or cancel any damage to a player.Methods
Damage:write_log has queued to the logs table, in the order they were written.Log:colored followed by Log:replicate would, except that the entry is not saved right away: it is printed to the server console in its color, sent to the players who view the damage logs, and queued for Damage:flush_logs.Hooks
Lets the ResolvePlayerDamage hook work out the amount of any damage to a player,
multiplies the fall damage of a player by the 'damage_scale_fall' config, whichever way
the amount was worked out (the FLGetFallDamage hook or the formula of the gamemode), and
lets the PrePlayerTakeDamage hook change or cancel any damage to a player.
Parameters
- entity Entity the entity taking damage
- damage_info CTakeDamageInfo
Returns
- Boolean true to block damage that one of the hooks has blocked, nil otherwise
Implements hook OneSecond
Saves the log entries that were written during the last second.
Clears what the plugin tracks about the player who died, writes the kill log entry if the 'log_kills' config is on and saves the queued log entries, so that the hits that led to the death are in the database together with it.
Parameters
- victim Player the player who died
- inflictor Entity entity that has dealt the fatal damage
- attacker Entity entity responsible for the death
Implements hook PlayerOneSecond
Regenerates the health of the player while the 'health_regen' config is on.
Parameters
- actor Player
- cur_time Number CurTime() of the tick
Clears what the plugin tracks about the player when they spawn.
Parameters
- actor Player
Implements hook PlayerThink
Tracks how long the player has been under water and deals the drowning damage while the 'drowning' config is on.
Parameters
- actor Player
- cur_time Number CurTime() of the tick
Handles damage that has been dealt to a player: restarts the wait for their health regeneration, punches their view if the 'damage_view_punch' config is on, writes the damage log entry if the 'log_damage' config is on and runs the PostPlayerTakeDamage hook.
Parameters
- entity Entity the entity that was attacked
- damage_info CTakeDamageInfo
- took Boolean whether the entity has actually taken the damage
Implements hook RegisterPermissions
Registers the 'view_damage_logs' permission, which sends the damage and kill log entries to the console of the player.
Damage:ScalePlayerDamage(victim, hitgroup, damage_info)
server plugins/damage/plugin/sv_hooks.lua:16Remembers the location of a bullet or melee hit on a player and multiplies its damage by the 'damage_scale_' config of that location.
Parameters
- victim Player
- hitgroup Number HITGROUP_ enum of the hit location
- damage_info CTakeDamageInfo
Saves the log entries that are still queued when the server shuts down.
Methods
Deals drowning damage to a player. The damage is of the DMG_DROWN type with the world as
its attacker, ignores armor, and goes through the usual damage hooks. A dice formula is
rolled once for this bit of damage, see Damage:get_drowning_amount. Serverside only.
Damage:deal_drowning_damage(target, '2d4')
Parameters
- target Player
- amount Number/String damage to deal, or a dice formula to roll it from; 1 when the formula cannot be rolled
Saves the log entries that Damage:write_log has queued to the logs table, in the order
they were written. Serverside only.
Returns
- Number how many entries were saved
Works out the amount of drowning damage from a number or a dice formula. A formula is
rolled with Dice.roll; one that cannot be rolled, or a value that is neither, comes out
as 1. Serverside only.
Damage:get_drowning_amount('1d4')
-- 3
Parameters
- amount Number/String damage, or a dice formula such as '1d4'
Returns
- Number damage, never below 0
Returns the location of the hit behind the damage a player is taking right now.
Only meaningful while that damage is being processed, that is inside of
PrePlayerTakeDamage, EntityTakeDamage and PostPlayerTakeDamage handlers.
Serverside only.
Parameters
- victim Player
Returns
- Number HITGROUP_ enum; HITGROUP_GENERIC when the damage does not come from a bullet or melee hit, e.g. a fall, an explosion or drowning
Returns the damage multiplier set in the config for a hit location. Serverside only.
Parameters
- hitgroup Number HITGROUP_ enum
Returns
- Number multiplier: the 'damage_scale_' config of the location, or 1 for HITGROUP_GENERIC
- HITGROUP_GEAR and anything else that has no config
Returns the name an entity is given in the damage and kill logs. Serverside only.
Parameters
- entity Entity
Returns
- String name of a player, followed by their Steam name in brackets if it differs; 'the world' for the world; the class of any other entity; 'an unknown source' if the entity is not valid
Returns the players who receive the replicated damage and kill log entries: those with the 'view_damage_logs' permission. The list is worked out at most once a second, not on every hit. Serverside only.
Returns
- List<Player> do not modify the list
Returns how long a player waits for their next bit of regenerated health: the 'health_regen_fast_interval' config when their health is at or above the 'health_regen_fast_share' percentage of their maximum health, the 'health_regen_interval' config otherwise. Serverside only.
Parameters
- target Player
Returns
- Number seconds
Returns how long a player has been completely under water without surfacing. It is only tracked while the 'drowning' config is on. Serverside only.
Parameters
- target Player
Returns
- Number seconds; 0 if the player is not submerged
Returns how deep a player is in water. For a ragdolled player this is the water level of their ragdoll, which is where their body is. Serverside only.
Parameters
- target Player
Returns
- Number 0 when not in water, 1 slightly submerged, 2 mostly submerged, 3 completely submerged
Returns the class of what an attacker has dealt damage with: the inflictor if it is an entity of its own (a prop, a grenade), otherwise the weapon a player or an NPC is holding. The held weapon is not named for damage the victim has dealt to themselves. Serverside only.
Parameters
- attacker Entity entity responsible for the damage
- inflictor Entity entity that has dealt the damage
- victim Entity optional, defaults to
nilentity that has taken the damage
Returns
- String entity class, or nil if there is nothing to name
Writes a damage log entry: who has taken how much damage, where, from whom and with
what, and the health and armor they are left with. The entry is written with the
'player_damage' action and replicated to the players who have the 'view_damage_logs'
permission; it is saved by Damage:flush_logs. Does not check the 'log_damage' config.
Serverside only.
Parameters
- victim Player player who has taken the damage
- damage_info CTakeDamageInfo the damage
- hitgroup Number optional, defaults to
HITGROUP_GENERICHITGROUP_ enum of the hit location
Writes a kill log entry: who has died, who or what has killed them and with what. The
entry is written with the 'player_death' action and replicated to the players who have
the 'view_damage_logs' permission; it is saved by Damage:flush_logs. Does not check
the 'log_kills' config. Serverside only.
Parameters
- victim Player player who has died
- inflictor Entity entity that has dealt the fatal damage
- attacker Entity entity responsible for the death
Punches the view of a player by a random angle that grows with the damage: the damage times the 'damage_view_punch_scale' config in degrees at most, and never more than 30 degrees. Serverside only.
Parameters
- target Player
- damage Number damage the player has taken
Runs the health regeneration of a player: heals them by the 'health_regen_amount' config once their waiting time has passed, never above their maximum health. The waiting time starts when the player is first found hurt and starts over whenever they take damage. Dead players and players at full health do not regenerate. Does not check the 'health_regen' config. Serverside only.
Parameters
- target Player
- cur_time Number optional, defaults to
CurTime()current time
Returns
- Boolean whether the player was healed by this call
Forgets what the plugin tracks about a player over time: the time of their next health regeneration and the time they have spent under water. Serverside only.
Parameters
- target Player
Remembers the location of the hit a player is about to take damage from. The engine only
reports it to ScalePlayerDamage, so it is kept for the EntityTakeDamage and
PostEntityTakeDamage handlers that follow in the same tick. Serverside only.
Parameters
- victim Player
- hitgroup Number HITGROUP_ enum
Runs the drowning of a player: keeps track of how long they have been completely under water and, once that exceeds the 'drowning_time' config, deals damage rolled from the 'drowning_damage' dice formula to them every 'drowning_interval' seconds until they surface. Dead and noclipping players are left alone. Does not check the 'drowning' config. Serverside only.
Parameters
- target Player
- cur_time Number optional, defaults to
CurTime()current time
Damage:write_log(color, message, action, object, subject)
server plugins/damage/plugin/sv_plugin.lua:423Writes a log entry the way Log:colored followed by Log:replicate would, except that
the entry is not saved right away: it is printed to the server console in its color, sent
to the players who view the damage logs, and queued for Damage:flush_logs.
Serverside only.
Parameters
- color Color console color of the entry
- message String text of the entry
- action String type of the logged event, in snake_case
- object String/Number optional, defaults to
nilwho or what performed the action - subject String/Number optional, defaults to
nilwho or what the action was performed on