RustTip

OnNpcEquipWeapon

OxideNPC
object OnNpcEquipWeapon(NPCPlayer nPCPlayer, Item item)
object OnNpcEquipWeapon(ScientistNPC scientistNPC, Item item)
Works — the game method in this build is the one the hook was written for.

Parameters

nPCPlayer
NPCPlayer
item
Item

Return value

objectReturn a value of the method's result type and the game returns it immediately; null continues as usual.

Example

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

private object OnNpcEquipWeapon(NPCPlayer nPCPlayer, Item item)
{
    Puts("OnNpcEquipWeapon");

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

    // to affect the game:
    // return null; // null — the game continues as usual
}

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

Injection point 1

Rust.opj (Oxide)
void NPCPlayer.EquipWeapon(bool)

Passes: NPCPlayer nPCPlayer, Item item

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

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

public virtual void EquipWeapon(bool skipDeployDelay = false)
{
	if (inventory == null || inventory.containerBelt == null)
	{
		return;
	}
	Item slot = inventory.containerBelt.GetSlot(0);
	if (Interface.CallHook("OnNpcEquipWeapon", this, slot) != null)
	{
		return;
	}
	if (slot == null)
	{
		return;
	}
	UpdateActiveItem(inventory.containerBelt.GetSlot(0).uid);
// …

Injection point 2

Rust.opj (Oxide)
void ScientistNPC.EquipWeapon(bool)

Passes: ScientistNPC scientistNPC, Item item

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

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

// …
{
	return;
}
Item item = heldEntity.GetItem();
if (item == null || item.contents == null)
{
	return;
}
if (Interface.CallHook("OnNpcEquipWeapon", this, item) != null)
{
	return;
}
if (Random.Range(0, 3) == 0)
{
	Item item2 = ItemManager.CreateByName("weapon.mod.flashlight", 1, 0uL);
	if (!item2.MoveToContainer(item.contents))
	{
// …

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.