Skip to content

IOnNpcTarget ​

WARNING

This is an internal hook and will not be called in plugins. See Internal Hooks for more information.

Usage ​

  • Return a float value to override default behavior

Example Autogenerated ​

csharp
private float? IOnNpcTarget( BaseNpc instance, BaseEntity target )
{
    Puts( "IOnNpcTarget works!" );
    return null;
}
csharp
private bool? IOnNpcTarget( BoatAI instance, BasePlayer ply )
{
    Puts( "IOnNpcTarget works!" );
    return null;
}
csharp
private bool? IOnNpcTarget( Rust.Ai.Gen2.SenseComponent instance, BaseEntity entity )
{
    Puts( "IOnNpcTarget works!" );
    return null;
}
csharp
private bool? IOnNpcTarget( WildlifeHazard instance, BasePlayer player )
{
    Puts( "IOnNpcTarget works!" );
    return null;
}

Location ​

  • BaseNpc::GetWantsToAttack(BaseEntity target)
  • BoatAI::IsPlayerTargetValid(BasePlayer ply)
  • Rust.Ai.Gen2.SenseComponent::CanTarget(BaseEntity entity)
  • WildlifeHazard::ShouldStartHazard(BasePlayer player)
csharp
public float GetWantsToAttack(BaseEntity target)
{
	object obj = Interface.CallHook("IOnNpcTarget", this, target);
	if (obj is float)
	{
		return (float)obj;
	}
	return WantsToAttack(target);
//---
csharp
//---
		{
			Debug.LogWarning("[BoatAI] Invalid target: " + ply.displayName + " not valid attack target");
		}
		return false;
	}
	object obj = Interface.CallHook("IOnNpcTarget", this, ply);
	if (obj is bool)
	{
		return (bool)obj;
	}
	if (Check.SimplyOnTerrainAt(ply.transform.position))
//---
csharp
//---
		if (SimpleAIMemory.PlayerIgnoreList.Contains(item))
		{
			return false;
		}
	}
	object obj = Interface.CallHook("IOnNpcTarget", this, entity);
	if (obj is bool)
	{
		return (bool)obj;
	}
	if (Observer != null && Observer.RefusesToTarget(entity))
//---
csharp
//---
	}
	if (SingularInteraction && SingularInteractionPlayer != null)
	{
		return false;
	}
	object obj = Interface.CallHook("IOnNpcTarget", this, player);
	if (obj is bool)
	{
		return (bool)obj;
	}
	if (!CanSeeTarget(player.transform))
//---

Released under the MIT License.