RustTip

OnCounterTargetChange

OxideCarbonElectronic

Called when a counter target is changed.

object OnCounterTargetChange(object arg0)
Works — the game method in this build is the one the hook was written for.

Parameters

arg0
object

Return value

objectThe result is checked in a special way — see the call code below.

Example

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

private object OnCounterTargetChange(object arg0)
{
    Puts("OnCounterTargetChange");

    // 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

Rust.opj (Oxide)
void PowerCounter.SERVER_SetTarget(BaseEntity.RPCMessage)

Passes: object arg0

WorksReturnBehavior: CustomAssembly-CSharp.dll

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

[RPC_Server]
[RPC_Server.IsVisible(3f)]
public void SERVER_SetTarget(RPCMessage msg)
{
	object result = Interface.CallHook("OnCounterTargetChange", msg.read.Int32());
	// … проверка результата (Modify-хук, см. Rust.opj)
	if (CanPlayerAdmin(msg.player))
	{
		targetCounterNumber = msg.read.Int32();
		resetTargetNumber = msg.read.Int32();
		targetCounterNumber = Mathf.Clamp(targetCounterNumber, 1, 999);
		resetTargetNumber = Mathf.Clamp(resetTargetNumber, 0, 999);
		MarkDirty();
// …

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.