RustTip

OnItemUse

OxideCarbonItem

Called when an item uses.

object OnItemUse(Item item, object a0 => a0)
Method changed — check — the game method differs from the one the hook is recorded for in Oxide. The hook is still called, but its place may have shifted — worth checking after an update.

Parameters

item
Item
a0 => a0
object

Return value

objectThe returned value modifies the result, the game continues.

Example

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

private object OnItemUse(Item item, object a0 => a0)
{
    Puts("OnItemUse");

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

    // to affect the game:
    // return default(int); // your value instead of the game result
}

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

Injection point

Rust.opj (Oxide)
void Item.UseItem(int)

Passes: Item item, object a0 => a0

Method changed — checkReturnBehavior: UseArgumentStringArgumentBehavior: UseArgumentString (this, a0 => a0)Assembly-CSharp.dll

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

public void UseItem(int amountToConsume = 1)
{
	if (amountToConsume > 0)
	{
		Interface.CallHook("OnItemUse", this, a0 => a0);
		amount -= amountToConsume;
		ReduceItemOwnership(amountToConsume);
		if (amount <= 0)
		{
			amount = 0;
			Remove();
		}
		else
// …

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.