<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.teamspec.net/index.php?action=history&amp;feed=atom&amp;title=Level_Editor%2FScripting</id>
	<title>Level Editor/Scripting - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.teamspec.net/index.php?action=history&amp;feed=atom&amp;title=Level_Editor%2FScripting"/>
	<link rel="alternate" type="text/html" href="https://wiki.teamspec.net/index.php?title=Level_Editor/Scripting&amp;action=history"/>
	<updated>2026-10-29T03:56:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.teamspec.net/index.php?title=Level_Editor/Scripting&amp;diff=59&amp;oldid=prev</id>
		<title>TeamSpecBot: Level Editor: scripting a gamemode overview</title>
		<link rel="alternate" type="text/html" href="https://wiki.teamspec.net/index.php?title=Level_Editor/Scripting&amp;diff=59&amp;oldid=prev"/>
		<updated>2026-10-20T03:46:19Z</updated>

		<summary type="html">&lt;p&gt;Level Editor: scripting a gamemode overview&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;A map&amp;#039;s &amp;#039;&amp;#039;&amp;#039;gamemode&amp;#039;&amp;#039;&amp;#039; is its rules, its HUD and what its bots do. It is up to three small GDScript files that belong to your map. You write them inside the editor: click &amp;#039;&amp;#039;&amp;#039;Map Config&amp;#039;&amp;#039;&amp;#039; in the top bar, open the &amp;#039;&amp;#039;&amp;#039;Gamemode&amp;#039;&amp;#039;&amp;#039; tab, and pick &amp;#039;&amp;#039;&amp;#039;Server&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;Client&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;Bot&amp;#039;&amp;#039;&amp;#039;. The &amp;#039;&amp;#039;&amp;#039;Scripting Docs&amp;#039;&amp;#039;&amp;#039; button there opens the guide for the tab you are on.&lt;br /&gt;
&lt;br /&gt;
Many maps need no scripting at all beyond the starter scripts: doors, buttons, relays, timers and counters can be wired up with [[Level Editor/Workflows/Outputs and logic|outputs]] instead.&lt;br /&gt;
&lt;br /&gt;
== Guides ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Page !! Covers&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Server rules|Server rules]] || &amp;lt;code&amp;gt;server.gd&amp;lt;/code&amp;gt;: counters, deaths and respawns, winning, messages, acting on players.&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Client HUD|Client HUD]] || &amp;lt;code&amp;gt;client.gd&amp;lt;/code&amp;gt;: reading counters and the HUD widgets.&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Bots|Bots]] || &amp;lt;code&amp;gt;bot.gd&amp;lt;/code&amp;gt;: giving bots their jobs.&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Teams and spawning|Teams and spawning]] || Declaring teams, choosing players&amp;#039; teams, spawn points and spawn rooms.&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Zones|Zones]] || Zone hooks, names and labels, the world boundary.&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Pickups|Pickups]] || Supply stations and dropping pickups from a script.&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Payload tracks|Payload tracks]] || Driving the cart, markers, the push zone and dispenser.&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Map entities|Map entities]] || Doors, logic, markers, switchable parts, bosses, buildings and map bots.&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Sandbox limits|Sandbox limits]] || What a map script cannot do.&lt;br /&gt;
|-&lt;br /&gt;
| [[Level Editor/Scripting/Testing|Testing a mode]] || Running the map and reading what scripts print.&lt;br /&gt;
|-&lt;br /&gt;
| Examples || [[Level Editor/Scripting/Examples/King of the Hill|King of the Hill]], [[Level Editor/Scripting/Examples/Team Deathmatch|Team Deathmatch]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Reference:&amp;#039;&amp;#039;&amp;#039; [[Level Editor/Scripting/Reference/GamemodeServerScript|GamemodeServerScript]] (server hooks), [[Level Editor/Scripting/Reference/GamemodeServerApi|GamemodeServerApi]] (the server &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt;), [[Level Editor/Scripting/Reference/GamemodeClientScript|GamemodeClientScript]], [[Level Editor/Scripting/Reference/GamemodeClientApi|GamemodeClientApi]], [[Level Editor/Scripting/Reference/GamemodeBotScript|GamemodeBotScript]], and [[Level Editor/Scripting/Reference/Sandbox|what a script may use]]. The reference comes from the same description the script editor&amp;#039;s autocomplete uses, so every signature on it is the one the game expects.&lt;br /&gt;
&lt;br /&gt;
== The three scripts ==&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Server&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;server.gd&amp;lt;/code&amp;gt;, starts with &amp;lt;code&amp;gt;extends GamemodeServerScript&amp;lt;/code&amp;gt;): the rules. It runs only on the server and it is the only script that can change the match: counters, teams, respawns, pickups and the winner. Its &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is a [[Level Editor/Scripting/Reference/GamemodeServerApi|GamemodeServerApi]]. See [[Level Editor/Scripting/Server rules|Server rules]].&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Client&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;client.gd&amp;lt;/code&amp;gt;, starts with &amp;lt;code&amp;gt;extends GamemodeClientScript&amp;lt;/code&amp;gt;): the HUD. It runs on every player&amp;#039;s machine and can only read. It puts widgets on screen that show the counters the server keeps. Its &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; is a [[Level Editor/Scripting/Reference/GamemodeClientApi|GamemodeClientApi]]. See [[Level Editor/Scripting/Client HUD|Client HUD]].&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Bot&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;bot.gd&amp;lt;/code&amp;gt;, starts with &amp;lt;code&amp;gt;extends GamemodeBotScript&amp;lt;/code&amp;gt;): what the bots should be doing. It runs on the server next to &amp;lt;code&amp;gt;server.gd&amp;lt;/code&amp;gt; and works through the very same &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; object, so it sees exactly what the rules see. Keep the rules out of it; it is for orders. See [[Level Editor/Scripting/Bots|Bots]].&lt;br /&gt;
&lt;br /&gt;
Each pane completes as you type against its own API: type &amp;lt;code&amp;gt;api.&amp;lt;/code&amp;gt; to see everything that script may call, and {{Key|Ctrl}}+click a name to read its documentation. A client pane never offers a server call.&lt;br /&gt;
&lt;br /&gt;
Your code overrides &amp;#039;&amp;#039;&amp;#039;hooks&amp;#039;&amp;#039;&amp;#039;: functions such as &amp;lt;code&amp;gt;_tick&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;_player_died&amp;lt;/code&amp;gt; that the game calls at the right moment. Override only the ones you need. Every hook and every &amp;lt;code&amp;gt;api&amp;lt;/code&amp;gt; call is listed in the reference pages above.&lt;br /&gt;
&lt;br /&gt;
== Where the scripts are kept ==&lt;br /&gt;
&lt;br /&gt;
The scripts are saved in your map&amp;#039;s folder as &amp;lt;code&amp;gt;server.gd&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;client.gd&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;bot.gd&amp;lt;/code&amp;gt;, and they go into the map whenever you export it or run it.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;An empty pane is replaced by the starter script&amp;#039;&amp;#039;&amp;#039; when you export or run. To have a script that does nothing, leave only its &amp;lt;code&amp;gt;extends&amp;lt;/code&amp;gt; line.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Reset to Default&amp;#039;&amp;#039;&amp;#039; under each pane puts the starter script back (after asking).&lt;br /&gt;
* If you edit a script file in another program while the editor has unsaved edits to it, the editor asks which version to keep (&amp;#039;&amp;#039;Script Changed on Disk&amp;#039;&amp;#039;).&lt;br /&gt;
&lt;br /&gt;
== The starter scripts ==&lt;br /&gt;
&lt;br /&gt;
A new map starts with a small working mode: the server script scores a point for your team each time you walk into a zone named &amp;lt;code&amp;gt;CapturePoint&amp;lt;/code&amp;gt;, declares a winner at 10, and brings the dead back on their normal timer; the client script shows the team score; and the bot script sets every bot&amp;#039;s skill to 0.6 and sends every bot roaming.&lt;br /&gt;
&lt;br /&gt;
A player who dies stays dead until a script calls [[Level Editor/Scripting/Reference/GamemodeServerApi#respawn_in|api.respawn_in]], so keep a &amp;lt;code&amp;gt;_player_died&amp;lt;/code&amp;gt; hook like the starter&amp;#039;s unless your mode is an elimination round. See [[Level Editor/Scripting/Server rules#Deaths and respawns|Server rules]].&lt;br /&gt;
&lt;br /&gt;
== When things happen ==&lt;br /&gt;
&lt;br /&gt;
On the server, for every match:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;code&amp;gt;_declare()&amp;lt;/code&amp;gt; runs once, before anything else. Declare every counter and team here; nothing can be declared later.&lt;br /&gt;
# &amp;lt;code&amp;gt;_start()&amp;lt;/code&amp;gt; runs when the map is live. The level&amp;#039;s supply packs are already out. Then the bot script&amp;#039;s &amp;lt;code&amp;gt;_start()&amp;lt;/code&amp;gt; runs.&lt;br /&gt;
# When a player joins, &amp;lt;code&amp;gt;_player_joined(entity_id)&amp;lt;/code&amp;gt; gives them a team (by default, the team with the fewest players) and the bot script&amp;#039;s &amp;lt;code&amp;gt;_player_joined&amp;lt;/code&amp;gt; runs; then the game places them at &amp;lt;code&amp;gt;_spawn_position(entity_id)&amp;lt;/code&amp;gt; and they enter the match.&lt;br /&gt;
# Every server tick, in this order: &amp;lt;code&amp;gt;_track_marker&amp;lt;/code&amp;gt; for each marker a payload cart passed, the zone hooks (&amp;lt;code&amp;gt;_zone_entered&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;_zone_exited&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;_left_world&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;_zone_tick&amp;lt;/code&amp;gt;), the pickup hooks (&amp;lt;code&amp;gt;_pickup_expired&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;_can_collect&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;_pickup_collected&amp;lt;/code&amp;gt;), then &amp;lt;code&amp;gt;_tick(delta)&amp;lt;/code&amp;gt;, then the bot script&amp;#039;s &amp;lt;code&amp;gt;_tick(delta)&amp;lt;/code&amp;gt;.&lt;br /&gt;
# When a player dies, &amp;lt;code&amp;gt;_player_died(entity_id, killer_id, default_seconds)&amp;lt;/code&amp;gt; runs. They stay dead until the script calls &amp;lt;code&amp;gt;api.respawn_in&amp;lt;/code&amp;gt;. When they come back, &amp;lt;code&amp;gt;_player_spawned(entity_id)&amp;lt;/code&amp;gt; runs.&lt;br /&gt;
# When a player leaves, &amp;lt;code&amp;gt;_player_left(entity_id)&amp;lt;/code&amp;gt; runs.&lt;br /&gt;
# When the script calls &amp;lt;code&amp;gt;api.declare_winner&amp;lt;/code&amp;gt;, the round is decided. The game shows the result and players vote for the next map. From then on no zone, pickup or tick hook runs and deaths are no longer reported to the script.&lt;br /&gt;
&lt;br /&gt;
On every player&amp;#039;s machine, the client script&amp;#039;s &amp;lt;code&amp;gt;_start()&amp;lt;/code&amp;gt; runs once the server&amp;#039;s counters have arrived, &amp;lt;code&amp;gt;_counter_changed&amp;lt;/code&amp;gt; runs whenever a counter changes, and &amp;lt;code&amp;gt;_match_ended(team)&amp;lt;/code&amp;gt; runs when the round is decided.&lt;br /&gt;
&lt;br /&gt;
== Next ==&lt;br /&gt;
&lt;br /&gt;
* Read [[Level Editor/Scripting/Server rules|Server rules]], then try a worked example: [[Level Editor/Scripting/Examples/King of the Hill|King of the Hill]] or [[Level Editor/Scripting/Examples/Team Deathmatch|Team Deathmatch]].&lt;br /&gt;
* [[Level Editor/Scripting/Testing|Testing a mode]] shows how to run your map and read what the scripts print.&lt;br /&gt;
* [[Level Editor/Scripting/Sandbox limits|Sandbox limits]] lists what a map script cannot do.&lt;br /&gt;
&lt;br /&gt;
{{Level Editor nav}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Level Editor]]&lt;br /&gt;
[[Category:Gamemode scripting]]&lt;/div&gt;</summary>
		<author><name>TeamSpecBot</name></author>
	</entry>
</feed>