Level Editor/Scripting/Reference/GamemodeServerScript

From TeamSpec Wiki
Jump to navigation Jump to search

The base class of server.gd: the script starts with extends GamemodeServerScript.

The base class of a map's server.gd: the rules of its gamemode.

Override the hooks your mode needs and leave the rest; each one already does something sensible. Everything the script can do goes through api.

This script runs only on the server, so it is the one place that can change the match: counters, teams, respawns, pickups and the winner.

See Level Editor/Scripting/Reference for every class, and Level Editor/Scripting/Reference/Sandbox for the rest of GDScript a script may use.

Properties

api

api: GamemodeServerApi
Property · Available to server.gd

Everything this script can do goes through api. See GamemodeServerApi.

Everything this script can do, as a GamemodeServerApi.

Hooks

_declare

_declare() -> void
Hook · Available to server.gd

Declare every counter and team the mode uses. Runs once, before anything else, and is the only place declarations work.

Returns: void

_start

_start() -> void
Hook · Available to server.gd

The map is live. Set up the round here. The level's supply packs are already out.

Returns: void

_player_joined

_player_joined(entity_id: int) -> void
Hook · Available to server.gd

A player joined. Give them a team here with api.set_team_of; the default puts them on the smallest team. Once this returns, the game places them at _spawn_position. Their first spawn is observed here: _player_spawned runs only when they come back after dying.

Parameters
  • entity_id: int
    Returns: void

_assign_to_smaller_team

_assign_to_smaller_team(entity_id: int) -> void
Hook · Available to server.gd

Puts the player with their Steam party when it is already playing and its team has room, otherwise on whichever declared team has the fewest players, the lowest team on a tie. A player who already has a team is left where they are. Call it from your own _player_joined to keep the default for some players.

Parameters
  • entity_id: int
    Returns: void

_can_join_team

_can_join_team(_entity_id: int, _team: int) -> bool
Hook · Available to server.gd

May this player change to this team? Return false to refuse. Asked only after the game has checked that the team exists and is not full. The default allows everything.

Not asked when a player leaves to spectate: that is always allowed.

Parameters
  • entity_id: int
  • team: int
    Returns: bool

_player_spawned

_player_spawned(_entity_id: int) -> void
Hook · Available to server.gd

A player came back to life after dying, at the position _spawn_position chose. Not called for the first spawn after joining; that is _player_joined.

Parameters
  • entity_id: int
    Returns: void

_player_died

_player_died(_entity_id: int, _killer_id: int, _default_seconds: float) -> void
Hook · Available to server.gd

A player died. They stay dead until you call api.respawn_in: pass default_seconds, the player's normal respawn time, or a different number, or nothing at all for an elimination round.

killer_id is the player who gets the kill, or -1 when nobody earned it. api.death_position() is where they died.

Parameters
  • entity_id: int
  • killer_id: int
  • default_seconds: float
    Returns: void

_player_left

_player_left(_entity_id: int) -> void
Hook · Available to server.gd

A player left the match for good. Forget anything you kept about them.

Parameters
  • entity_id: int
    Returns: void

_spawn_position

_spawn_position(entity_id: int) -> Vector3
Hook · Available to server.gd

Where this player should appear, on joining and on every respawn. The default picks one of their team's spawn points at random.

Runs while the player is being placed, apart from the other hooks: only read through api here, change nothing, and always return a position.

Parameters
  • entity_id: int
    Returns: Vector3

_zone_entered

_zone_entered(_zone: StringName, _entity_id: int) -> void
Hook · Available to server.gd

A living player walked into a zone. Compare api.zone_label(zone) with the name you gave it in the editor.

Parameters
  • zone: StringName
  • entity_id: int
    Returns: void

_zone_exited

_zone_exited(_zone: StringName, _entity_id: int) -> void
Hook · Available to server.gd

A player is no longer in a zone: they walked out, died or left the match. Do not assume they are alive somewhere else.

Parameters
  • zone: StringName
  • entity_id: int
    Returns: void

_zone_used

_zone_used(_zone: StringName, _entity_id: int) -> void
Hook · Available to server.gd

A player standing in a usable zone pressed the use key. A zone is usable when its Area Trigger has a Use Prompt, which the HUD shows to anyone inside it.

Parameters
  • zone: StringName
  • entity_id: int
    Returns: void

_form_submitted

_form_submitted(_entity_id: int, _form: StringName, _values: PackedInt32Array) -> void
Hook · Available to server.gd

A player applied a tile map you opened on them with api.open_tile_map. form is the name you gave it, and values holds one option index per tile, in the order you sent them. The game has already checked that the answer fits the map you sent, but a player can apply the same map again, so make applying it twice harmless.

Parameters
  • entity_id: int
  • form: StringName
  • values: PackedInt32Array
    Returns: void

_left_world

_left_world(entity_id: int) -> void
Hook · Available to server.gd

A player fell out of the world: they went below the map's World Boundary. The default kills them, with nobody credited. Override it to do something else, such as putting them back.

Parameters
  • entity_id: int
    Returns: void

_zone_tick

_zone_tick(_zone: StringName, _occupants: Array, _delta: float) -> void
Hook · Available to server.gd

Every server tick, for every zone, including empty ones, so a capture meter can drain when nobody is on the point. occupants are the living players inside, sorted. delta is the seconds since the last tick.

Parameters
  • zone: StringName
  • occupants: Array
  • delta: float
    Returns: void

_track_marker

_track_marker(_track: StringName, _marker: StringName, _forward: bool) -> void
Hook · Available to server.gd

The cart on track passed one of its markers (see api.track_markers). forward is true when it reached the marker going forward, and false when it rolled back past it. A cart standing exactly on a marker has reached it. Several markers passed in one tick arrive in the order the cart passed them. Called before _tick, so _tick already sees what you set here. A marker the cart starts the round on or behind is not passed.

Parameters
  • track: StringName
  • marker: StringName
  • forward: bool
    Returns: void

_can_collect

_can_collect(_handle: int, _entity_id: int) -> bool
Hook · Available to server.gd

May this player take this pickup? Return false to refuse. Asked when they come close enough, and again when it reaches them. The default lets anybody take anything.

Parameters
  • handle: int
  • entity_id: int
    Returns: bool

_pickup_collected

_pickup_collected(_handle: int, _entity_id: int) -> void
Hook · Available to server.gd

A player took a pickup. The handle still answers api.pickup_kind, api.pickup_team and api.pickup_position during this hook; afterwards it is gone. Health and ammo packs refill the player by themselves.

Parameters
  • handle: int
  • entity_id: int
    Returns: void

_pickup_expired

_pickup_expired(_handle: int) -> void
Hook · Available to server.gd

A pickup ran out of lifetime and vanished untaken.

Parameters
  • handle: int
    Returns: void

_entity_damaged

_entity_damaged(_entity: int, _amount: float, _attacker: int) -> void
Hook · Available to server.gd

A boss took damage. entity is its entity id (see api.bosses), amount the health it lost, and attacker the player who dealt it, or -1 for nobody. api.entity_health already reads what it has left.

Parameters
  • entity: int
  • amount: float
  • attacker: int
    Returns: void

_entity_died

_entity_died(_entity: int, _killer: int) -> void
Hook · Available to server.gd

A boss died. killer is the player who landed the last blow, or -1 for nobody. It sinks into its pool and stays dead; what that means for the match, killing the enemy's boss wins, say, is the mode's to decide.

Parameters
  • entity: int
  • killer: int
    Returns: void

_door_changed

_door_changed(_door: StringName, _state: int) -> void
Hook · Available to server.gd

A door moved to a new state: api.DOOR_OPENING when it starts to open, api.DOOR_OPEN once it is open, api.DOOR_CLOSING and api.DOOR_CLOSED the same way back. Whoever moved it, a player walking up, its own wait running out, or this script, the hook is the same.

Parameters
  • door: StringName
  • state: int
    Returns: void

_logic_event

_logic_event(_entity: StringName, _event: StringName, _activator: int) -> void
Hook · Available to server.gd

A logic entity the map places (a relay, timer, counter or button, by its name in the level editor) raised event: "OnTrigger", "OnTimer", "OutValue", "OnHitMin", "OnHitMax", "OnPressed" or "OnUseLocked". activator is the player who set it off, 0 for nobody. Its outputs fire whatever this does; this is where a mode reacts to a button press or a counter filling up.

Parameters
  • entity: StringName
  • event: StringName
  • activator: int
    Returns: void

_tick

_tick(_delta: float) -> void
Hook · Available to server.gd

Every server tick, after the zone and pickup hooks. delta is the seconds since the last tick. Timers and win checks go here. Stops once a winner is declared.

Parameters
  • delta: float
    Returns: void
TeamSpec Level Editor
Basics Getting started · Interface · Viewport and camera · Selecting and hiding · Keyboard shortcuts · Settings · Map Config · Troubleshooting
Menus File · Edit · View · Tools · Functional
Panels Scene tree · Inspector · Materials · Props · Snapping · UV editor · Displacement · Terrain
Tools Move, Rotate and Scale · Box · Sphere · Cylinder · Prism · Stairs · Spiral Stairs · Spiral Tower · Arch · Path Brush · Plane · Terrain · Clip · Duplicate · Ruler and Cordon · Edit Vertex and Edge · Edit Face · Loop Cut · Material Brush · Vertex Color Brush · Displacement · Prop Path
Entities Brush · Zone · Group · Mirror Node · Prop · Spawn Point · Supply Pickup · World Boundary · Lights · Water · Sounds · Anchor Platform · Payload Track · Boss Spawn · Map Marker · World Text · Decal · Door · Button · Logic entities · 3D Skybox · Nav Region
Workflows Your first map · Brushes and CSG · Materials and UVs · Lighting and lightmaps · Bots and navigation · Mirrored maps · Outputs and logic · Custom assets · Playtesting · Exporting and publishing · Importing Source maps
Scripting Overview · Server rules · Client HUD · Bots · Teams and spawning · Zones · Pickups · Payload tracks · Map entities · Sandbox limits · Testing · King of the Hill · Team Deathmatch · API reference · What a script may use