RustTip

CanLock

OxideCarbonVehicle

Called to determine whether to lock.

Return true to allow the action and false to block it.

object CanLock(BasePlayer player, CodeLock codeLock)
object CanLock(BasePlayer player, KeyLock keyLock)
object CanLock(BasePlayer player, ModularCar owner, ModularCarCodeLock modularCarCodeLock)
Works — the game method in this build is the one the hook was written for.

Parameters

player
BasePlayer
codeLock
CodeLock

Return value

objectThe returned value replaces the game result; null lets the game decide.

Example

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

private object CanLock(BasePlayer player, CodeLock codeLock)
{
    Puts("CanLock");

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

    // to affect the game:
    // return false; // your value instead of the game result
}

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

Injection point 1

Rust.opj (Oxide)
void CodeLock.TryLock(BaseEntity.RPCMessage)

Passes: BasePlayer player, CodeLock codeLock

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

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

[RPC_Server]
[RPC_Server.MaxDistance(3f, CheckParent = true)]
private void TryLock(RPCMessage rpc)
{
	if (rpc.player.CanInteract() && !IsLocked() && code.Length == 4 && whitelistPlayers.Contains(rpc.player.userID))
	{
		if (Interface.CallHook("CanLock", rpc.player, this) != null)
		{
			return;
		}
		DoEffect(effectLocked.resourcePath);
		SetFlagLocal(Flags.Locked, b: true);
		SendNetworkUpdate();
	}
}

Injection point 2

Rust.opj (Oxide)
void KeyLock.Lock(BasePlayer)

Passes: BasePlayer player, KeyLock keyLock

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

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

private void Lock(BasePlayer player)
{
	if (!(player == null) && player.CanInteract() && !IsLocked() && HasLockPermission(player))
	{
		if (Interface.CallHook("CanLock", player, this) != null)
		{
			return;
		}
		LockLock(player);
		SendNetworkUpdate();
	}
}

Injection point 3

Rust.opj (Oxide)
bool ModularCarCodeLock.HasLockPermission(BasePlayer)

Passes: BasePlayer player, ModularCar owner, ModularCarCodeLock modularCarCodeLock

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

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

public bool HasLockPermission(BasePlayer player)
{
	if (!player.IsValid() || player.IsDead())
	{
		return false;
	}
	object returnvar = Interface.CallHook("CanLock", player, this.owner, this);
	if (returnvar is bool)
	{
		return (bool)returnvar;
	}
	return HasLockPermission(player.userID);
}

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.