Skip to content

OnEntityTakeDamage

Alternatively, modify the HitInfo object to change the damage.
It should be okay to set the damage to 0, but if you don't return non-null, the player's client will receive a damage indicator (if entity is a BasePlayer).
HitInfo has all kinds of useful things in it, such as Weapon, damageProperties or damageTypes

Usage

  • Return a non-null value to override default behavior

Example Autogenerated

csharp
private void OnEntityTakeDamage( ResourceEntity instance, HitInfo info )
{
    Puts( "OnEntityTakeDamage works!" );
}
csharp
private object OnEntityTakeDamage( BaseCombatEntity entity, HitInfo hitInfo )
{
    Puts( "OnEntityTakeDamage works!" );
    return null;
}
csharp
private object OnEntityTakeDamage( BasePlayer basePlayer, HitInfo hitInfo )
{
    Puts( "OnEntityTakeDamage works!" );
    return null;
}

Location

  • ResourceEntity::OnAttacked(HitInfo info)
  • RustCore::IOnBaseCombatEntityHurt(BaseCombatEntity entity, HitInfo hitInfo)
  • RustCore::IOnBasePlayerAttacked(BasePlayer basePlayer, HitInfo hitInfo)
  • RustCore::IOnBasePlayerHurt(BasePlayer basePlayer, HitInfo hitInfo)
csharp
public override void OnAttacked(HitInfo info)
{
	if (base.isServer && !this.isKilled)
	{
		if (Interface.CallHook("OnEntityTakeDamage", this, info) != null)
		{
			return;
		}
		if (this.resourceDispenser != null)
		{
//---
csharp
private object IOnBaseCombatEntityHurt(BaseCombatEntity entity, HitInfo hitInfo)
{
	return entity is BasePlayer ? null : Interface.CallHook("OnEntityTakeDamage", entity, hitInfo);
}
csharp
private object IOnBasePlayerAttacked(BasePlayer basePlayer, HitInfo hitInfo)
{
	if (!serverInitialized || basePlayer == null || hitInfo == null || basePlayer.IsDead() || isPlayerTakingDamage || basePlayer is NPCPlayer)
	{
		return null;
	}

	if (Interface.CallHook("OnEntityTakeDamage", basePlayer, hitInfo) != null)
	{
		return true;
	}

	isPlayerTakingDamage = true;
	try
	{
		basePlayer.OnAttacked(hitInfo);
	}
	finally
	{
		isPlayerTakingDamage = false;
	}
	return true;
}
csharp
private object IOnBasePlayerHurt(BasePlayer basePlayer, HitInfo hitInfo)
{
	return isPlayerTakingDamage ? null : Interface.CallHook("OnEntityTakeDamage", basePlayer, hitInfo);
}

Released under the MIT License.