Skip to content

LimbUtil

Kanisuko edited this page May 25, 2026 · 5 revisions

LimbUtil

Namespace: ScavLib.util

Safe wrappers around the player's Body.limbs[] array. All methods return safe defaults (null, false, 0) when no world is loaded or the requested limb does not exist — they will never throw a NullReferenceException.


LimbSlot Enum

Named indices for the three anatomically fixed limbs. Use these instead of raw integers for self-documenting code.

public enum LimbSlot
{
    Head   = 0,  // Jaw, brain, concussion checks
    Thorax = 1,  // Ribs, breathing, hemothorax
    Pelvis = 2,  // Base posture limb
}

Arms and legs occupy indices 3 and above in Body.limbs[]. Access them by raw index via GetLimb(int) or by name via GetLimbByName(string).


Limb Access

GetLimb(int index)

Returns the Limb at the given index, or null if the index is out of range or no world is loaded.

Limb head = LimbUtil.GetLimb(0);

GetLimb(LimbSlot slot)

Named overload for the three fixed limbs.

Limb thorax = LimbUtil.GetLimb(LimbSlot.Thorax);

GetLimbByName(string name)

Find a limb by its GameObject.name. Returns null if not found.

Limb rightArm = LimbUtil.GetLimbByName("RightArm");

GetAllLimbs()

Returns a List<Limb> of all limbs on the player's body. Returns an empty list if not in game.

foreach (var limb in LimbUtil.GetAllLimbs())
    GameUtil.Log($"{limb.name}: skin={limb.skinHealth:F0}");

Aggregate State Queries

These scan all limbs and return a summary result. Useful for condition checks without iterating manually.

Method Returns Description
HasBrokenBone() bool true if any non-dismembered limb is broken.
HasDislocation() bool true if any non-dismembered limb is dislocated.
HasInfection() bool true if any non-dismembered limb has an active infection.
HasDismemberment() bool true if any limb has been dismembered.
GetMaxInfection() float Highest infectionAmount across all non-dismembered limbs. 0 ~ 100.
GetAveragePain() float Mirrors Body.averagePain — highest limb pain after Resilience reduction.
GetTotalBleedSpeed() float Total bleed speed across all limbs minus blood regen speed.
if (LimbUtil.HasBrokenBone())
    GameUtil.Alert("You have a broken bone.", important: false);

if (LimbUtil.GetMaxInfection() > 50f)
    GameUtil.Alert("Infection is severe!", important: true);

float bleed = LimbUtil.GetTotalBleedSpeed();
if (bleed > PlayerUtil.Thresholds.BLEED_SPEED_HEAVY)
    GameUtil.Alert("Heavy bleeding!", important: true);

Per-Limb Manipulation

HealLimb(Limb limb)

Fully heal a single limb: restores skin and muscle health to 100, clears bleeding, pain, infection, and shrapnel, and calls MendBone() / UnDislocate() if needed. Does nothing if the limb is dismembered.

LimbUtil.HealLimb(LimbUtil.GetLimb(LimbSlot.Head));

HealLimb(int index)

Index overload — equivalent to HealLimb(GetLimb(index)).

LimbUtil.HealLimb(0); // Heal head

DamageSkin(Limb limb, float amount)

Reduce a limb's skinHealth by amount, clamped to 0 ~ 100.

LimbUtil.DamageSkin(LimbUtil.GetLimb(LimbSlot.Thorax), 30f);

DamageMuscle(Limb limb, float amount)

Reduce a limb's muscleHealth by amount, clamped to 0 ~ 100.


Per-Limb Raw Writes

Direct field assignments with clamping. Use when you need precise control over a single limb property.

Method Range Description
SetSkinHealthRaw(Limb, float) 0 ~ 100 Set skin health directly.
SetMuscleHealthRaw(Limb, float) 0 ~ 100 Set muscle health directly.
SetBleedRaw(Limb, float) 0 ~ 100 Set bleed amount directly.
SetPainRaw(Limb, float) 0 ~ 100 Set pain directly.
SetInfectionRaw(Limb, float) 0 ~ 100 Set infection amount. Auto-clears infected flag at 0; auto-sets it above 0.
Limb head = LimbUtil.GetLimb(LimbSlot.Head);

LimbUtil.SetSkinHealthRaw(head, 50f);
LimbUtil.SetBleedRaw(head, 0f);
LimbUtil.SetInfectionRaw(head, 0f); // also clears infected flag

Usage Example

using ScavLib.util;
using ScavLib.event_bus;
using ScavLib.event_bus.events;

[BepInDependency("com.kanisuko.scavlib", "0.4.0")]
[BepInPlugin("com.yourname.yourmod", "YourMod", "1.0.0")]
public class YourPlugin : BaseUnityPlugin
{
    private void Awake()
    {
        EventBus.Register(this);
    }

    [Subscribe]
    private void OnWorldLoaded(WorldLoadedEvent e)
    {
        // Heal every limb individually
        foreach (var limb in LimbUtil.GetAllLimbs())
            LimbUtil.HealLimb(limb);

        // Check for dangerous conditions
        if (LimbUtil.GetTotalBleedSpeed() > PlayerUtil.Thresholds.BLEED_SPEED_CRITICAL)
            GameUtil.Alert("Critical bleeding!", important: true);

        if (LimbUtil.HasInfection())
            GameUtil.Log($"Max infection: {LimbUtil.GetMaxInfection():F1}");
    }
}

Clone this wiki locally