IOnNpcTarget
OxideNPCobject IOnNpcTarget(BaseNpc baseNpc, BaseEntity target)
object IOnNpcTarget(Rust.Ai.Gen2.SenseComponent senseComponent, BaseEntity entity)
object IOnNpcTarget(WildlifeHazard wildlifeHazard, BasePlayer player)
object IOnNpcTarget(BoatAI boatAI, BasePlayer ply)Works — the game method in this build is the one the hook was written for.
Parameters
- baseNpc
- BaseNpc
- target
- BaseEntity
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 IOnNpcTarget(BaseNpc baseNpc, BaseEntity target)
{
Puts("IOnNpcTarget");
// 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)
float BaseNpc.GetWantsToAttack(BaseEntity)
Passes: BaseNpc baseNpc, BaseEntity target
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll
Where it is called (this branch's game code)
public float GetWantsToAttack(BaseEntity target)
{
object returnvar = Interface.CallHook("IOnNpcTarget", this, target);
if (returnvar is float)
{
return (float)returnvar;
}
return WantsToAttack(target);
}Injection point 2
Rust.opj (Oxide)
bool Rust.Ai.Gen2.SenseComponent.CanTarget(BaseEntity)
Passes: Rust.Ai.Gen2.SenseComponent senseComponent, BaseEntity entity
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll
Where it is called (this branch's game code)
// …
{
return false;
}
if (SimpleAIMemory.PlayerIgnoreList.Contains(item))
{
return false;
}
}
object returnvar = Interface.CallHook("IOnNpcTarget", this, entity);
if (returnvar is bool)
{
return (bool)returnvar;
}
if (Observer != null && Observer.RefusesToTarget(entity))
{
return false;
}
// …Injection point 3
Rust.opj (Oxide)
bool WildlifeHazard.ShouldStartHazard(BasePlayer)
Passes: WildlifeHazard wildlifeHazard, BasePlayer player
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this, a0)Assembly-CSharp.dll
Where it is called (this branch's game code)
// …
if (IsInvoking(FailHazardDelayed))
{
return false;
}
if (SingularInteraction && SingularInteractionPlayer != null)
{
return false;
}
object returnvar = Interface.CallHook("IOnNpcTarget", this, player);
if (returnvar is bool)
{
return (bool)returnvar;
}
if (!CanSeeTarget(player.transform))
{
return false;
}
// …Injection point 4
Rust.opj (Oxide)
bool BoatAI.IsPlayerTargetValid(BasePlayer)
Passes: BoatAI boatAI, BasePlayer ply
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this, a0)Assembly-CSharp.dll
Where it is called (this branch's game code)
// …
if (!Check.IsValidAttackTarget(ply))
{
if (PRINT_DEBUGS)
{
Debug.LogWarning("[BoatAI] Invalid target: " + ply.displayName + " not valid attack target");
}
return false;
}
object returnvar = Interface.CallHook("IOnNpcTarget", this, ply);
if (returnvar is bool)
{
return (bool)returnvar;
}
if (Check.SimplyOnTerrainAt(ply.transform.position))
{
if (PRINT_DEBUGS)
{
// …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.