RustTip

CanSetRelationship

OxideCarbonPlayer

Called to determine whether to set relationship.

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

object CanSetRelationship(BasePlayer player, BasePlayer otherPlayer, RelationshipManager.RelationshipType type, int weight)
Works — the game method in this build is the one the hook was written for.

Parameters

player
BasePlayer
otherPlayer
BasePlayer
type
RelationshipManager.RelationshipType
weight
int

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 CanSetRelationship(BasePlayer player, BasePlayer otherPlayer, RelationshipManager.RelationshipType type, int weight)
{
    Puts("CanSetRelationship");

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

Injection point

Rust.opj (Oxide)
void RelationshipManager.SetRelationship(BasePlayer, BasePlayer, RelationshipManager.RelationshipType, int, bool)

Passes: BasePlayer player, BasePlayer otherPlayer, RelationshipManager.RelationshipType type, int weight

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (a0, a1, a2, a3)Assembly-CSharp.dll

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

// …
	return;
}
ulong num = player.userID.Get();
ulong num2 = otherPlayer.userID.Get();
if (player == null || player == otherPlayer || player.IsNpc || (otherPlayer != null && otherPlayer.IsNpc))
{
	return;
}
if (Interface.CallHook("CanSetRelationship", player, otherPlayer, type, weight) != null)
{
	return;
}
PlayerRelationships playerRelationships = GetRelationships(num);
otherPlayer.requestingReputationUpdate = true;
if (!CleanupOldContacts(playerRelationships, num))
{
	CleanupOldContacts(playerRelationships, num, RelationshipType.Enemy);
// …

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.