A trigger volume that acts as the map's kill plane. On enter it looks up the collider's root object, ignores arena tiles, then either kills the target through PlayerHealth and reports the elimination to ArenaRoundManager or RoundManager (with a killfeed announcement), or teleports non-player objects to a SpawnPoint and zeroes their CharacterController/Rigidbody velocity.
using Sandbox;
using System.Linq;
public sealed class KillZone : Component, Component.ITriggerListener
{
public void OnTriggerEnter( Collider other )
{
if ( !other.IsValid() || !other.GameObject.IsValid() ) return;
var targetObj = other.GameObject.Root;
if ( targetObj == GameObject ) return;
if ( targetObj.Components.Get<ArenaTile>( true ).IsValid() || other.GameObject.Components.Get<ArenaTile>( true ).IsValid() ) return;
var health = targetObj.Components.Get<PlayerHealth>( true ) ??
other.GameObject.Components.Get<PlayerHealth>( true );
if ( health.IsValid() )
{
Killfeed.Instance?.AnnouncePush( "ARENA", targetObj.Name );
var arenaRound = Scene.GetAllComponents<ArenaRoundManager>().FirstOrDefault();
if ( arenaRound.IsValid() && arenaRound.CurrentState == ArenaRoundState.InGame )
{
health.TakeDamage( health.CurrentHealth );
arenaRound.OnPlayerEliminated( targetObj );
return;
}
var roundManager = Scene.GetAllComponents<RoundManager>().FirstOrDefault();
if ( roundManager.IsValid() && roundManager.IsInRound )
{
health.TakeDamage( health.CurrentHealth );
roundManager.OnPlayerEliminated( targetObj );
return;
}
health.TakeDamage( health.CurrentHealth );
}
else
{
ScoreManager.Instance?.AddScore( 1 );
}
if ( health.IsValid() ) return;
var spawn = Scene.GetAllComponents<SpawnPoint>().FirstOrDefault();
Vector3 targetPosition = spawn.IsValid() ? spawn.WorldPosition : new Vector3( 0, 0, 250 );
targetObj.WorldPosition = targetPosition;
var character = targetObj.Components.Get<CharacterController>( true );
if ( character.IsValid() )
{
character.Velocity = Vector3.Zero;
}
var rb = targetObj.Components.Get<Rigidbody>( true );
if ( rb.IsValid() )
{
rb.Velocity = Vector3.Zero;
rb.AngularVelocity = Vector3.Zero;
}
Log.Info( $"Объект {targetObj.Name} упал в KillZone и телепортирован обратно!" );
}
public void OnTriggerExit( Collider other ) { }
}