RustTip

OnEntityLeave

OxideCarbonEntity

Called when an entity leaves.

object OnEntityLeave(TriggerBase triggerBase, BaseEntity ent)
object OnEntityLeave(TriggerComfort triggerComfort, BaseEntity ent)
Works — the game method in this build is the one the hook was written for.

Parameters

triggerBase
TriggerBase
ent
BaseEntity

Return value

objectReturn non-null to cancel the game action.

Example

object — you can affect the game: return a value to change or cancel the action.

private object OnEntityLeave(TriggerBase triggerBase, BaseEntity ent)
{
    Puts("OnEntityLeave");

    // change nothing — the game continues as usual
    return null;

    // to affect the game:
    // return false; // non-null cancels the game action
}

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

Injection point 1

Rust.opj (Oxide)
void TriggerBase.OnEntityLeave(BaseEntity)

Passes: TriggerBase triggerBase, BaseEntity ent

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll

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

internal virtual void OnEntityLeave(BaseEntity ent)
{
	if (entityContents != null)
	{
		if (Interface.CallHook("OnEntityLeave", this, ent) != null)
		{
			return;
		}
		entityContents.Remove(ent);
		OnEntityLeaveTrigger?.Invoke(ent);
	}
}

Injection point 2

Rust.opj (Oxide)
void TriggerComfort.OnEntityLeave(BaseEntity)

Passes: TriggerComfort triggerComfort, BaseEntity ent

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll

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

internal override void OnEntityLeave(BaseEntity ent)
{
	if (ent is BasePlayer || ent is RidableHorse || ent is RidableHorse)
	{
		if (Interface.CallHook("OnEntityLeave", this, ent) != null)
		{
			return;
		}
		_entities.Remove(ent);
	}
}

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.