RustTip

OnEntityEnter

OxideCarbonEntity

Called when an entity enters.

object OnEntityEnter(TriggerBase triggerBase, BaseEntity ent)
object OnEntityEnter(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 OnEntityEnter(TriggerBase triggerBase, BaseEntity ent)
{
    Puts("OnEntityEnter");

    // 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.OnEntityEnter(BaseEntity)

Passes: TriggerBase triggerBase, BaseEntity ent

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll

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

internal virtual void OnEntityEnter(BaseEntity ent)
{
	if (!(ent == null))
	{
		if (entityContents == null)
		{
			entityContents = new HashSet<BaseEntity>();
		}
		if (Interface.CallHook("OnEntityEnter", this, ent) != null)
		{
			return;
		}
		entityContents.Add(ent);
		OnEntityEnterTrigger?.Invoke(ent);
	}
}

Injection point 2

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

Passes: TriggerComfort triggerComfort, BaseEntity ent

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll

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

internal override void OnEntityEnter(BaseEntity ent)
{
	if (ent is BasePlayer || ent is RidableHorse || ent is RidableHorse)
	{
		if (Interface.CallHook("OnEntityEnter", this, ent) != null)
		{
			return;
		}
		_entities.Add(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.