RustTip

OnMessagePlayer

OxideCarbonServer

Called when a server console command is executed.

Useful for auditing or overriding server-side console commands.

object OnMessagePlayer(string msg, BasePlayer basePlayer)
Works — the game method in this build is the one the hook was written for.

Parameters

msg
string
basePlayer
BasePlayer

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 OnMessagePlayer(string msg, BasePlayer basePlayer)
{
    Puts("OnMessagePlayer");

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

Where it is called

Oxide core (Oxide.Rust)
Player::Message(BasePlayer player, string message, string prefix, ulong userId = 0, params object[] args)

Oxide core code — the hook is called from here

// …
{
    if (string.IsNullOrEmpty(message))
    {
        return;
    }

    message = args.Length > 0 ? string.Format(Formatter.ToUnity(message), args) : Formatter.ToUnity(message);
    string formatted = prefix != null ? $"{prefix} {message}" : message;
    if (Interface.CallHook("OnMessagePlayer", formatted, player, userId) != null)
    {
        return;
    }
    player.SendConsoleCommand("chat.add", 2, userId, formatted);
}

Injection point

Rust.opj (Oxide)
void BasePlayer.ChatMessage(string)

Passes: string msg, BasePlayer basePlayer

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

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

public void ChatMessage(string msg)
{
	if (isServer)
	{
		if (Interface.CallHook("OnMessagePlayer", msg, this) != null)
		{
			return;
		}
		SendConsoleCommand("chat.add", 2, 0, msg);
	}
}

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.