RustTip

OnSwitchToggle

OxideEntity
object OnSwitchToggle(ElectricSwitch electricSwitch, BasePlayer player)
object OnSwitchToggle(FuelGenerator fuelGenerator, BasePlayer player)
object OnSwitchToggle(IndustrialConveyor industrialConveyor, BasePlayer player)
Works — the game method in this build is the one the hook was written for.

Parameters

electricSwitch
ElectricSwitch
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 OnSwitchToggle(ElectricSwitch electricSwitch, BasePlayer player)
{
    Puts("OnSwitchToggle");

    // 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 ElectricSwitch.RPC_Switch(BaseEntity.RPCMessage)

Passes: ElectricSwitch electricSwitch, 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)]
public void RPC_Switch(RPCMessage msg)
{
	if (Interface.CallHook("OnSwitchToggle", this, msg.player) != null)
	{
		return;
	}
	bool flag = msg.read.Bool();
	SetSwitch(flag);
}

Injection point 2

Rust.opj (Oxide)
void FuelGenerator.RPC_EngineSwitch(BaseEntity.RPCMessage)

Passes: FuelGenerator fuelGenerator, 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)]
public void RPC_EngineSwitch(RPCMessage msg)
{
	if (Interface.CallHook("OnSwitchToggle", this, msg.player) != null)
	{
		return;
	}
	bool generatorState = msg.read.Bit();
	SetGeneratorState(generatorState);
}

Injection point 3

Rust.opj (Oxide)
void IndustrialConveyor.SvSwitch(BaseEntity.RPCMessage)

Passes: IndustrialConveyor industrialConveyor, BasePlayer player

WorksReturnBehavior: ExitWhenNonNullArgumentBehavior: 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(2uL)]
private void SvSwitch(RPCMessage msg)
{
	if (Interface.CallHook("OnSwitchToggle", this, msg.player) != null)
	{
		return;
	}
	SetSwitch(!IsOn());
}

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.