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)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
- 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
Method changed — checkReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (this, a0)Assembly-CSharp.dll
Where it is called (this branch's game code)
// …
Debug.LogWarning("[BoatAI] Invalid target: " + ply.displayName + " is in ignore list");
}
return false;
}
if (_ignoredUntil.TryGetValue(ply.userID.Get(), out var value) && Time.time < value)
{
if (PRINT_DEBUGS)
{
object returnvar = Interface.CallHook("IOnNpcTarget", this, ply);
if (returnvar is bool)
{
return (bool)returnvar;
}
Debug.LogWarning("[BoatAI] Invalid target: " + ply.displayName + " was given up on recently");
}
return false;
}
// …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.