RustTip

OnItemPickup

OxideCarbonItem

Called when an item is picked up.

object OnItemPickup(Item item, BasePlayer player, WorldItem worldItem)
Works — the game method in this build is the one the hook was written for.

Parameters

item
Item
player
BasePlayer
worldItem
WorldItem

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 OnItemPickup(Item item, BasePlayer player, WorldItem worldItem)
{
    Puts("OnItemPickup");

    // 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 WorldItem.Pickup(BaseEntity.RPCMessage)

Passes: Item item, BasePlayer player, WorldItem worldItem

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

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

[RPC_Server]
[RPC_Server.IsVisible(3f)]
public void Pickup(RPCMessage msg)
{
	if (msg.player.CanInteract() && this.item != null && allowPickup && CanOpenInSafeZone(msg.player))
	{
		if (Interface.CallHook("OnItemPickup", this.item, msg.player, this) != null)
		{
			return;
		}
		ItemModContainer component = this.item.info.GetComponent<ItemModContainer>();
		if (!(component != null) || !component.canLootInWorld || !(component.pickupInWorldDelay > 0f) || !(Mathf.Abs(pickupStartTime + component.pickupInWorldDelay - UnityEngine.Time.realtimeSinceStartup) > ConVar.AntiHack.rpc_timer_forgiveness))
		{
			ClientRPC(RpcTarget.NetworkGroup("PickupSound"));
			Item item = this.item;
// …

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.