RustTip

OnNpcEquipWeapon

OxideNPC
object OnNpcEquipWeapon(NPCPlayer nPCPlayer, Item item)
object OnNpcEquipWeapon(ScientistNPC scientistNPC, Item item)
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

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

Method changed — checkReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this, l0)Assembly-CSharp.dll

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

// …
{
	return;
}
Item slot = inventory.containerBelt.GetSlot(0);
if (slot == null)
{
	return;
}
if (Interface.CallHook("OnNpcEquipWeapon", this, slot) != null)
{
	return;
}
UpdateActiveItem(inventory.containerBelt.GetSlot(0).uid);
BaseEntity heldEntity = slot.GetHeldEntity();
if (!(heldEntity != null))
{
	return;
// …

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.