RustTip

OnLoseCondition

OxideCarbonGlobal

Called when an item's condition is reduced or it breaks.

void OnLoseCondition(Item item, ref float amount)
Works — the game method in this build is the one the hook was written for.

Parameters

item
Item
amount
ref float

Return value

voidThe return value is ignored — the hook only notifies.

Example

private void OnLoseCondition(Item item, ref float amount)
{
    Puts("OnLoseCondition");
}

Works in both Oxide and Carbon: Carbon loads Oxide plugins as is.

Where it is called

Oxide core (Oxide.Rust)
RustCore::IOnLoseCondition(Item item, float amount)

Oxide core code — the hook is called from here

private object IOnLoseCondition(Item item, float amount)
{
    object[] arguments = { item, amount };
    Interface.CallHook("OnLoseCondition", arguments);
    amount = (float)arguments[1];
    float condition = item.condition;
    item.condition -= amount;
    if (item.condition <= 0f && item.condition < condition)
    {
        item.OnBroken();
    }

// …

Injection point

Rust.opj (Oxide)
void Item.LoseCondition(float)

Injected internal hook IOnLoseCondition — this hook is called by its handler in the Oxide/Carbon core

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll

Where it is called (this branch's game code)

public void LoseCondition(float amount)
{
	if (hasCondition && !Debugging.disablecondition)
	{
		if (Interface.CallHook("IOnLoseCondition", this, amount) != null)
		{
			return;
		}
		float num = condition;
		condition -= amount;
		if (Global.developer > 0)
		{
			Debug.Log(info.shortname + " was damaged by: " + amount + "cond is: " + condition + "/" + maxCondition);
// …

Sources: Rust.opj from OxideMod/Oxide.Rust (MIT) and hook metadata of the Carbon documentation (MIT). Method code is decompiled from this branch's server.