RustTip

OnEngineStop

OxideCarbonVehicle

Called when an engine stops.

object OnEngineStop(SmallEngine smallEngine, BasePlayer player)
object OnEngineStop(TOwner owner)
Works — the game method in this build is the one the hook was written for.

Parameters

smallEngine
SmallEngine
player
BasePlayer

Return value

objectReturn a value of the method's result type and the game returns it immediately; null continues as usual.

Example

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

private object OnEngineStop(SmallEngine smallEngine, BasePlayer player)
{
    Puts("OnEngineStop");

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

    // to affect the game:
    // return null; // null — the game continues as usual
}

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

Injection point 1

Rust.opj (Oxide)
void SmallEngine.TurnOff(BaseEntity.RPCMessage)

Passes: SmallEngine smallEngine, BasePlayer player

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this,a0.player)Assembly-CSharp.dll

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

[RPC_Server]
[RPC_Server.IsVisible(3f)]
[RPC_Server.CallsPerSecond(5uL)]
public void TurnOff(RPCMessage msg)
{
	if (Interface.CallHook("OnEngineStop", this, msg.player) != null)
	{
		return;
	}
	if (PlayerBoat.IsPlayerAuthedOnChildEntity(this, msg.player, authedIfNoPrivOrLock: true))
	{
		TurnOff();
	}
}

Injection point 2

Rust.opj (Oxide)
void VehicleEngineController`1.StopEngine()

Passes: TOwner owner

WorksReturnBehavior: CustomAssembly-CSharp.dll

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

public void StopEngine()
{
	if (!isServer || IsOff)
	{
		return;
	}
	object result = Interface.CallHook("OnEngineStop", this.owner);
	// … проверка результата (Modify-хук, см. Rust.opj)
	CancelEngineStart();
	using BaseEntity.FlagsUpdateScope flagsUpdateScope = owner.StartSetFlags(BaseEntity.FlagsUpdateMode.SendNetworkUpdate);
	flagsUpdateScope.Set(BaseEntity.Flags.On, b: false);
	flagsUpdateScope.Set(engineStartingFlag, b: false);
}

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.