A Teleporter component usable as a paired teleport pad or as an extraction beacon. It moves players and rigidbodies to a target teleporter with a boost and cooldown, and in beacon mode tracks players inside a radius and shows a light plus box model.
using Sandbox;
using System.Collections.Generic;
using System.Linq;
public sealed class Teleporter : Component, Component.ITriggerListener
{
public static Teleporter ActiveExtractionBeacon { get; private set; }
[Property] public Teleporter TargetTeleporter { get; set; }
[Property] public float CooldownDuration { get; set; } = 1.5f;
[Property] public float ExitVelocityBoost { get; set; } = 1.2f;
// Extraction Beacon mode for Final 30s Apex Climax
[Property] public bool IsExtractionBeacon { get; set; } = false;
[Property] public float ExtractionRadius { get; set; } = 220f;
[Sync] public bool IsExtractionActive { get; set; } = false;
private TimeSince _timeSinceLastUse;
private readonly HashSet<GameObject> _insideExtraction = new();
private PointLight _beaconLight;
private ModelRenderer _beaconRenderer;
protected override void OnStart()
{
if ( IsExtractionBeacon )
{
ActiveExtractionBeacon = this;
EnsureBeaconVisuals();
SetExtractionActive( IsExtractionActive );
}
}
public void SetExtractionActive( bool active )
{
IsExtractionActive = active;
if ( active )
{
ActiveExtractionBeacon = this;
EnsureBeaconVisuals();
}
else
{
_insideExtraction.Clear();
if ( ActiveExtractionBeacon == this ) ActiveExtractionBeacon = null;
}
if ( _beaconLight.IsValid() ) _beaconLight.Enabled = active;
if ( _beaconRenderer.IsValid() ) _beaconRenderer.Enabled = active;
}
private void EnsureBeaconVisuals()
{
if ( !_beaconLight.IsValid() )
{
_beaconLight = Components.Get<PointLight>() ?? Components.Create<PointLight>();
_beaconLight.LightColor = Color.FromRgb( 0x10b981 );
_beaconLight.Radius = 620f;
_beaconLight.Intensity = 4.5f;
_beaconLight.Shadows = false;
_beaconLight.FogStrength = 2.5f;
_beaconLight.AnimationEnabled = true;
_beaconLight.AnimationPattern = LightAnimationPattern.SlowPulse;
}
if ( !_beaconRenderer.IsValid() )
{
_beaconRenderer = Components.Get<ModelRenderer>() ?? Components.Create<ModelRenderer>();
_beaconRenderer.Model = Model.Load( "models/dev/box.vmdl" );
_beaconRenderer.Tint = new Color( 0.06f, 0.85f, 0.55f, 0.45f );
}
}
public bool IsPlayerInsideExtraction( GameObject player )
{
if ( !IsExtractionBeacon || !IsExtractionActive || !player.IsValid() ) return false;
if ( _insideExtraction.Contains( player.Root ) ) return true;
return Vector3.DistanceBetween( WorldPosition, player.WorldPosition ) <= ExtractionRadius;
}
public void OnTriggerEnter( Collider other )
{
if ( !other.IsValid() || !other.GameObject.IsValid() ) return;
var rootObj = other.GameObject.Root;
if ( IsExtractionBeacon )
{
if ( IsExtractionActive && ( rootObj.Components.Get<PlayerHealth>().IsValid() || rootObj.Components.Get<PlayerController>().IsValid() ) )
{
_insideExtraction.Add( rootObj );
var p = rootObj.Components.Get<PlayerController>();
if ( p.IsValid() && !p.IsProxy )
{
Sound.Play( "music/buttonhover.sound", WorldPosition );
PushHud.LocalInstance?.ShowCloseCallNotification( "EXTRACTION ZONE SECURED (2X BONUS!)" );
}
}
return;
}
if ( _timeSinceLastUse < CooldownDuration || TargetTeleporter == null || !TargetTeleporter.IsValid() )
return;
// Multiplayer proxy safety: only local player controlling client executes teleport & camera juice
var player = rootObj.Components.Get<PlayerController>();
if ( player.IsValid() && player.IsProxy ) return;
var cc = rootObj.Components.Get<CharacterController>();
if ( cc.IsValid() )
{
rootObj.WorldPosition = TargetTeleporter.WorldPosition + Vector3.Up * 20f;
cc.Velocity *= ExitVelocityBoost;
TargetTeleporter.SetCooldown();
SetCooldown();
rootObj.Components.Get<PlayerAbilities>()?.RegisterFlowAction( "TELEPORT" );
CameraJuice.Instance?.Shake( 10f );
return;
}
var rb = rootObj.Components.Get<Rigidbody>();
if ( rb.IsValid() )
{
rootObj.WorldPosition = TargetTeleporter.WorldPosition + Vector3.Up * 20f;
rb.Velocity *= ExitVelocityBoost;
TargetTeleporter.SetCooldown();
SetCooldown();
}
}
public void OnTriggerExit( Collider other )
{
if ( IsExtractionBeacon && other.IsValid() && other.GameObject.IsValid() )
{
_insideExtraction.Remove( other.GameObject.Root );
}
}
public void SetCooldown()
{
_timeSinceLastUse = 0;
}
protected override void OnDestroy()
{
if ( ActiveExtractionBeacon == this )
{
ActiveExtractionBeacon = null;
}
_insideExtraction.Clear();
base.OnDestroy();
}
}