OnWildlifeTrap
OxideCarbonTrapsCalled when wildlife trap occurs.
object OnWildlifeTrap(WildlifeTrap wildlifeTrap, TrappableWildlife trapped)
object OnWildlifeTrap(SurvivalFishTrap survivalFishTrap, ItemDefinition itemDefinition)Works — the game method in this build is the one the hook was written for.
Parameters
- wildlifeTrap
- WildlifeTrap
- trapped
- TrappableWildlife
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 OnWildlifeTrap(WildlifeTrap wildlifeTrap, TrappableWildlife trapped)
{
Puts("OnWildlifeTrap");
// 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 1
Rust.opj (Oxide)
void WildlifeTrap.TrapWildlife(TrappableWildlife)
Passes: WildlifeTrap wildlifeTrap, TrappableWildlife trapped
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this, a0)Assembly-CSharp.dll
Where it is called (this branch's game code)
public void TrapWildlife(TrappableWildlife trapped)
{
if (Interface.CallHook("OnWildlifeTrap", this, trapped) != null)
{
return;
}
Item item = ItemManager.Create(trapped.inventoryObject, Random.Range(trapped.minToCatch, trapped.maxToCatch + 1), 0uL, isServerSide: true, 0uL);
if (LastLootedByPlayer != null)
{
item.SetItemOwnership(LastLootedByPlayer, ItemOwnershipPhrases.SurvivalTrap);
}
// …Injection point 2
Rust.opj (Oxide)
void SurvivalFishTrap.TrapThink()
Passes: SurvivalFishTrap survivalFishTrap, ItemDefinition itemDefinition
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this, l0)Assembly-CSharp.dll
Where it is called (this branch's game code)
// …
item?.UseItem(usedLureAmount);
if (Random.Range(0f, 1f) <= trapSuccessRate || !(itemDefinition != null))
{
return;
}
try
{
bypassItemFilter = true;
if (Interface.CallHook("OnWildlifeTrap", this, itemDefinition) != null)
{
return;
}
Item item2 = ItemManager.Create(itemDefinition, 1, 0uL, isServerSide: true, 0uL);
if (LastLootedByPlayer != null)
{
item2.SetItemOwnership(LastLootedByPlayer, ItemOwnershipPhrases.SurvivalTrap);
}
// …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.