Shared hooks of the Limbs plugin: the movement penalties of hurt legs. They are applied to the movement data of every command rather than to the run speed and the jump power of the player, so they stack with whatever other plugins set those to, and they run on the server and in the prediction of the owner, who is the only client that knows their limbs.
Summary
Hooks
ScalePlayerDamage has remembered.PostPlayerTakeDamage hook of the Damage plugin, which carries the hit location.Methods
Hooks
Makes the aim of the local player drift while they hold a weapon with a hurt arm. The
view is moved along a slow, repeating path of up to Limbs.sway_angle degrees for a
crippled arm; only the difference to the previous frame is added, so the player keeps
control of their aim and the view returns to where it was once the drift stops. The
strength comes from the last LazyTick.
Parameters
- user_cmd CUserCmd
Resets the limbs of a player who dies, before their character is saved.
Parameters
- victim Player
- _attacker Entity
- _damage_info CTakeDamageInfo
Remembers the health of a player who is about to take damage, so that the health they actually lose is known once the damage has been dealt. The damage is left as it is.
Parameters
- entity Entity the entity that is about to take damage
- _damage_info CTakeDamageInfo
Lowers the jump of a player with hurt legs: when the command has taken the player off the ground with a jump, the upward speed they have gained is cut, down to half for a crippled leg.
Parameters
- actor Player
- move_data CMoveData
Implements hook FLHUDPaint
Draws the body diagram in the bottom right corner of the HUD. It fades in while a limb
of the local player is hurt (or always, or never, as the 'limbs_hud' client setting says)
and is hidden while limb damage is disabled or cinematic bars are on screen. The theme
options 'limbs_diagram_x', 'limbs_diagram_y' and 'limbs_diagram_height' move and resize
it, and a theme that has a DrawLimbDiagram(x, y, height, alpha) method draws it instead
of Limbs:draw_diagram, unless that method returns nil.
Parameters
- _cur_time Number current CurTime()
- scrw Number screen width
- scrh Number screen height
Implements hook LazyTick
Looks up how strongly the aim of the local player should drift: the 'aim' effect of their limbs while they are alive, on foot and holding a weapon they could aim.
Slows a player with hurt legs down while they run: the speed limit of the command is lowered from the run speed towards the walk speed, down to half of the run speed for a crippled leg, but never below the walk speed. Also notes whether the command starts a jump for the FinishMove handler.
Parameters
- actor Player
- move_data CMoveData
Implements hook OnThemeLoaded
Forgets the colors of the diagram when a theme is loaded, so that they come from the new theme.
Parameters
- _current_theme Theme the theme that has been loaded
Implements hook PlayerOneMinute
Lets the hurt limbs of a living player recover by the 'limbs_recovery' config once a minute.
Parameters
- actor Player
Hurts the limbs of a player who has taken damage, with the hit location that
ScalePlayerDamage has remembered. Only used without the Damage plugin.
Parameters
- victim Entity the entity that has taken damage
- damage_info CTakeDamageInfo
- took Boolean whether the damage was actually dealt
Limbs:PostPlayerTakeDamage(victim, damage_info, took, hitgroup)
server plugins/limbs/plugin/sv_hooks.lua:42Implements hook PostPlayerTakeDamage
Hurts the limbs of a player who has taken damage, from the PostPlayerTakeDamage hook
of the Damage plugin, which carries the hit location.
Parameters
- victim Player the player who has taken damage
- damage_info CTakeDamageInfo
- took Boolean whether the damage was actually dealt
- hitgroup Number HITGROUP_ enum of the hit location
Implements hook RegisterClientSettings
Registers the 'limbs_hud' client setting, which decides when the body diagram is shown.
Remembers the body part that an attack on a player was traced to, for the damage that
follows in the same tick. The damage is left as it is. Not needed while the Damage
plugin is loaded, which passes the location to PostPlayerTakeDamage.
Parameters
- victim Player
- hitgroup Number HITGROUP_ enum of the body part that was hit
- _damage_info CTakeDamageInfo
Methods
Returns the IDs of all limbs, from the head down.
Returns
- List<String> 'head', 'chest', 'stomach', 'left_arm', 'right_arm', 'left_leg' and 'right_leg'; do not modify the list
Hurts one limb of a player. The damage is added to what the limb already has, up to 100, saved with the active character of the player and sent to them. Nothing happens while limb damage is disabled, or when the player has no active character.
-- A bear trap.
Limbs:damage(activator, 'left_leg', 60)
Parameters
- target Player
- limb String limb ID
- amount Number damage to add, rounded up to a whole point
Returns
- Number the damage that was added, 0 if the limb did not change
Hurts several limbs of a player at once, which saves and sends the limbs only once. Nothing happens while limb damage is disabled.
Limbs:damage_limbs(target, { left_leg = 20, right_leg = 20 })
Parameters
- target Player
- hits Map damage to add by limb ID; amounts that are not positive are skipped
Returns
- Map the damage that was added by limb ID, limbs that did not change left out
Draws the body diagram: a figure seen from behind, so its left limbs are on the left, on a dark background ('limbs_background' color of the theme), with every limb in the color of its damage. The figure is half as wide as it is tall.
-- The limbs of the local player, 256 pixels tall.
Limbs:draw_diagram(32, 32, 256)
-- Any other set of limbs.
Limbs:draw_diagram(32, 32, 256, 1, { head = 20, left_leg = 80 })
Parameters
- x Number left edge of the figure
- y Number top edge of the figure
- height Number height of the figure in pixels
- alpha Number optional, defaults to
1opacity from 0 to 1 - limbs Map optional, defaults to
nildamage by limb ID; the limbs of the local player when omitted, whose colors are kept between frames
See also
Finds the limb of a fallen player that is closest to a position, by looking for the nearest physics bone of their ragdoll. Needs the Ragdoll plugin.
Parameters
- target Player
- position Vector world position, e.g. where the damage was dealt
Returns
- String limb ID, or nil if the player has no ragdoll, the position is not set or the nearest bone is not a known part of a limb
Returns the limb that a bone of the ValveBiped skeleton belongs to.
Parameters
- bone_name String name of the bone, e.g. 'ValveBiped.Bip01_L_Calf'
Returns
- String limb ID, or nil if the bone is not a known part of a limb
Returns the limb that a hit group belongs to.
Limbs:from_hitgroup(HITGROUP_LEFTLEG) -- 'left_leg'
Limbs:from_hitgroup(HITGROUP_GENERIC) -- nil
Parameters
- hitgroup Number HITGROUP_ enum
Returns
- String limb ID, or nil for HITGROUP_GENERIC and unknown hit groups; HITGROUP_GEAR counts as the stomach
Returns the damage of every hurt limb of a player. On the client only the limbs of the local player are known.
Parameters
- target Player
Returns
- Map damage (1 to 100) by limb ID, healthy limbs left out; empty when limb damage is disabled
Returns the color that stands for an amount of limb damage: it goes from the 'limb_healthy' color of the theme through 'limb_hurt' at half damage to 'limb_critical'. The plugin has defaults for all three (green, yellow and red).
Parameters
- damage Number limb damage from 0 to 100
Returns
- Color
Returns the damage of one limb of a player. On the client only the limbs of the local player are known; those of other players read as healthy.
if Limbs:get_damage(target, 'right_arm') >= 75 then
target:notify('my_schema.cannot_lift')
end
Parameters
- target Player
- limb String limb ID
Returns
- Number damage from 0 (healthy) to 100 (crippled); 0 when limb damage is disabled
Returns how strongly an effect of limb damage applies to a player. The plugin itself uses 'run' (hurt legs slow running down), 'jump' (hurt legs lower jumps) and 'aim' (hurt arms make the aim drift); the first two follow the 'limbs_legs_slow' config and the worse leg, the third follows the 'limbs_arms_sway' config and the worse arm. Other plugins can use the same values for their own penalties.
-- Picking a lock takes up to twice as long with a hurt arm.
local duration = 10 * (1 + (Limbs and Limbs:get_effect(actor, 'aim') or 0))
Parameters
- target Player on the client only the local player has effects
- effect String 'run', 'jump' or 'aim'
Returns
- Number strength from 0 (no effect) to 1 (the limb is crippled)
Returns how healthy one limb of a player is: 100 minus its damage.
Parameters
- target Player
- limb String limb ID
Returns
- Number health of the limb from 0 (crippled) to 100 (healthy)
See also
Works out which limbs a hit has landed on and how much damage each of them takes, before the AdjustLimbHits hook has its say. The limb damage is the share of the maximum health of the player that the hit has taken, as a percentage, times the 'limbs_damage_scale' config: losing a quarter of the maximum health deals 25 limb damage at a scale of 1, whatever the maximum health is. Fall damage is split between the legs when the 'limbs_fall_damage' config is on; other damage goes to the limb of the hit group, or, for a fallen player, to the limb of their ragdoll that is closest to the hit.
-- A player with 20 maximum health loses 5 health to a shot in the arm.
Limbs:get_hits(victim, damage_info, 5, HITGROUP_LEFTARM)
-- { left_arm = 25 }
Parameters
- victim Player
- damage_info CTakeDamageInfo the damage that was dealt
- amount Number health that the player has lost
- hitgroup Number optional, defaults to
nilHITGROUP_ enum of the body part the hit was traced to, nil if it was not traced
Returns
- Map limb damage by limb ID; empty if the hit has no location
Returns when the local player wants to see the body diagram on the HUD: the value of the 'limbs_hud' client setting, or 'hurt' when the Settings plugin is not loaded.
Returns
- String 'hurt' (while any limb is hurt), 'always' or 'never'
Returns the language phrase of the name of a limb.
target:notify('my_schema.bandaged', { limb = t(Limbs:get_limb_name('left_arm')) })
Parameters
- limb String limb ID
Returns
- String phrase, e.g. 'ui.limbs.left_arm'
Internal
This function is internal. It is not part of the public API and may change without notice.
Read limb damage with Limbs:get_damage and Limbs:get_all_damage.
Returns the table that holds the limb damage of a player's active character, as it is kept in the character data, whether limb damage is enabled or not.
Parameters
- target Player
Returns
- Map damage by limb ID, healthy limbs left out; nil if nothing is stored, the player has no active character, or, on the client, the player is not the local player
Returns the damage of the most hurt limb among the given ones.
local leg_damage = Limbs:get_worst_damage(target, { 'left_leg', 'right_leg' })
Parameters
- target Player
- limbs List<String> optional, defaults to
nillimb IDs to look at; all limbs when omitted
Returns
- Number damage from 0 to 100
Limbs:handle_damage(victim, damage_info, took, hitgroup)
server plugins/limbs/plugin/sv_hooks.lua:75Hurts the limbs of a player who has taken damage. This runs after the damage has been
dealt, so damage that was blocked hurts nothing and damage that other handlers have scaled
counts as it was dealt. Limb damage is worked out from the health the player has lost,
which leaves out what their armor has absorbed, as a share of their maximum health, see
Limbs:get_hits.
Parameters
- victim Player the player who has taken damage
- damage_info CTakeDamageInfo
- took Boolean whether the damage was actually dealt
- hitgroup Number optional, defaults to
nilHITGROUP_ enum of the hit location; nil or HITGROUP_GENERIC for damage without one
Heals one limb of a player. Works whether limb damage is enabled or not.
-- A splint takes half of the damage off a leg.
Limbs:heal(actor, 'right_leg', 50)
Parameters
- target Player
- limb String limb ID
- amount Number optional, defaults to
100damage to take off, rounded up to a whole point; heals the limb completely when omitted
Returns
- Number the damage that was taken off, 0 if the limb did not change
Heals every hurt limb of a player by the same amount. Works whether limb damage is enabled or not. This is what medical items should call: healing the health of a player does not heal their limbs.
Limbs:heal_all(actor, 25)
Parameters
- target Player
- amount Number optional, defaults to
100damage to take off each limb, rounded up to a whole point; heals the limbs completely when omitted
Returns
- Number the damage that was taken off all limbs together
Checks whether any limb of a player is hurt.
Parameters
- target Player
Returns
- Boolean false when limb damage is disabled
Checks whether limb damage is turned on by the 'limbs_enabled' config.
Returns
- Boolean
Checks whether a value is the ID of a limb.
Parameters
- limb Any
Returns
- Boolean
Clears the damage of all limbs of a player at once. The plugin does this when a player dies. Works whether limb damage is enabled or not.
Parameters
- target Player
Returns
- Boolean true if any limb was hurt and has been cleared, false otherwise
Forgets the colors the diagram of the local player was last drawn with, so that they are worked out again from the theme on the next frame.
Sets the damage of one limb of a player to a value, hurting or healing it as needed. Raising the damage does nothing while limb damage is disabled.
Parameters
- target Player
- limb String limb ID
- value Number new damage, kept between 0 and 100
Returns
- Number the change that was applied: positive if the limb was hurt, negative if it was healed, 0 if it did not change