Module spectate

Multiplayer Spectator System

Client-side spectating logic for multiplayer.

Spectate mode will be enabled when the local player dies.

Provides:

  • Third-person camera when local player is dead
  • Smooth transitions into spectate mode
  • Mouse-based camera orbit and zoom
  • Player cycling with mouse buttons
  • Optional map handling and outlines for spectated player/vehicle

All functions in this module are intended to run on the client.

Example usage:

function client.tick()
    spectateTick(GetAllPlayers())
 end

function client.draw()
    spectateDraw()
end

function client.render(dt)
    spectateRender(dt)
end

Functions

spectateTick (playerList) Update spectate state and current target based on player health and events (client).
spectateDraw () Draw spectate HUD elements and handle player switching (client).
spectateRender (dt) Update and render the spectator camera (client).


Functions

spectateTick (playerList)

Update spectate state and current target based on player health and events (client).

Spectate mode is automatically enabled when the local player dies. Call this once per frame from your main tick function on the client.

Responsibilities:

  • Enable/disable spectate mode when the local player dies or respawns
  • Track the attacker when the local player is killed
  • Filter and store a clean list of valid spectatable players
  • Ensure current spectated player remains valid, or select a new one

Parameters:

  • playerList table List of player IDs to consider for spectating

Usage:

    -- Example usage in client tick function
    spectateTick({}) -- pass an empy list to only allow spectating the local player
    spectateTick(GetAllPlayers()) -- will be able to spectate all players
    specateTick(teamsGetLocalTeamPlayers()) -- will spectate all players in the local team
spectateDraw ()

Draw spectate HUD elements and handle player switching (client).

Call this from your UI/draw loop when spectate mode should be active.

Responsibilities:

  • Cycle between available players using:
    • Left mouse button -> next player
    • Right mouse button -> previous player
  • Draw a label with the current spectated player's name, if enabled
spectateRender (dt)

Update and render the spectator camera (client).

Call this once per frame from your client render loop.

Responsibilities:

  • Handle map state integration (disabling map, blending from map camera)
  • Smoothly interpolate into spectate camera transform
  • Position camera behind spectated target (player or vehicle)
  • Avoid clipping into world geometry using raycasts and occlusion checks
  • Draw outlines around the spectated player/vehicle and temporary outline around the attacker (if any)

Parameters:

  • dt number Delta time in seconds
generated by LDoc 1.5.0 Last updated 2025-12-09 10:41:23