<?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%2FExamples%2FTeam_Deathmatch</id>
	<title>Level Editor/Scripting/Examples/Team Deathmatch - 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%2FExamples%2FTeam_Deathmatch"/>
	<link rel="alternate" type="text/html" href="https://wiki.teamspec.net/index.php?title=Level_Editor/Scripting/Examples/Team_Deathmatch&amp;action=history"/>
	<updated>2026-10-29T03:56:15Z</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/Examples/Team_Deathmatch&amp;diff=57&amp;oldid=prev</id>
		<title>TeamSpecBot: Level Editor: Team Deathmatch example</title>
		<link rel="alternate" type="text/html" href="https://wiki.teamspec.net/index.php?title=Level_Editor/Scripting/Examples/Team_Deathmatch&amp;diff=57&amp;oldid=prev"/>
		<updated>2026-10-20T03:46:18Z</updated>

		<summary type="html">&lt;p&gt;Level Editor: Team Deathmatch example&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Every kill scores a point for the killer&amp;#039;s team. The first team to 25 wins, and when the 10-minute clock runs out the team ahead wins, or the round is a draw.&lt;br /&gt;
&lt;br /&gt;
== The map ==&lt;br /&gt;
&lt;br /&gt;
* Spawn points for team 1 and team 2.&lt;br /&gt;
* A &amp;#039;&amp;#039;&amp;#039;World Boundary&amp;#039;&amp;#039;&amp;#039; below the map.&lt;br /&gt;
&lt;br /&gt;
No zones are needed.&lt;br /&gt;
&lt;br /&gt;
== server.gd ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extends GamemodeServerScript&lt;br /&gt;
&lt;br /&gt;
const KILLS_TO_WIN := 25&lt;br /&gt;
const ROUND_SECONDS := 600&lt;br /&gt;
&lt;br /&gt;
var _clock: float = 0.0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
func _declare() -&amp;gt; void:&lt;br /&gt;
	api.declare_team_counter(&amp;amp;amp;&amp;quot;kills&amp;quot;, 0, 0, KILLS_TO_WIN)&lt;br /&gt;
	api.declare_global_counter(&amp;amp;amp;&amp;quot;time_left&amp;quot;, ROUND_SECONDS, 0, ROUND_SECONDS)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
func _player_died(entity_id: int, killer_id: int, default_seconds: float) -&amp;gt; void:&lt;br /&gt;
	api.respawn_in(entity_id, default_seconds)&lt;br /&gt;
	# -1 when nobody earned the kill: a suicide, a fall, the world boundary.&lt;br /&gt;
	if killer_id &amp;amp;lt; 0:&lt;br /&gt;
		return&lt;br /&gt;
	var team: int = api.team_of(killer_id)&lt;br /&gt;
	if team == 0 or team == api.team_of(entity_id):&lt;br /&gt;
		return&lt;br /&gt;
	if api.add_team(team, &amp;amp;amp;&amp;quot;kills&amp;quot;, 1) &amp;gt;= KILLS_TO_WIN:&lt;br /&gt;
		api.declare_winner(team, &amp;quot;first to %d kills&amp;quot; % KILLS_TO_WIN)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
func _tick(delta: float) -&amp;gt; void:&lt;br /&gt;
	_clock += delta&lt;br /&gt;
	while _clock &amp;gt;= 1.0:&lt;br /&gt;
		_clock -= 1.0&lt;br /&gt;
		if api.add_global(&amp;amp;amp;&amp;quot;time_left&amp;quot;, -1) == 0:&lt;br /&gt;
			_time_up()&lt;br /&gt;
			return&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
func _time_up() -&amp;gt; void:&lt;br /&gt;
	var one: int = api.get_team(1, &amp;amp;amp;&amp;quot;kills&amp;quot;)&lt;br /&gt;
	var two: int = api.get_team(2, &amp;amp;amp;&amp;quot;kills&amp;quot;)&lt;br /&gt;
	if one == two:&lt;br /&gt;
		api.declare_winner(0, &amp;quot;time ran out&amp;quot;)&lt;br /&gt;
	else:&lt;br /&gt;
		api.declare_winner(1 if one &amp;gt; two else 2, &amp;quot;time ran out&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What it uses:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;_player_died&amp;lt;/code&amp;gt; respawns everybody on their normal timer first, then scores. A kill on a teammate scores nothing. See [[Level Editor/Scripting/Server rules#Deaths and respawns|Deaths and respawns]].&lt;br /&gt;
* The clock is a global counter, so the HUD can show it. Its minimum is 0, so it stops there by itself.&lt;br /&gt;
* &amp;lt;code&amp;gt;declare_winner&amp;lt;/code&amp;gt; with team 0 is a draw.&lt;br /&gt;
&lt;br /&gt;
== client.gd ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extends GamemodeClientScript&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
func _start() -&amp;gt; void:&lt;br /&gt;
	api.show_widget(&amp;amp;amp;&amp;quot;team_score&amp;quot;, {&lt;br /&gt;
		&amp;quot;counter&amp;quot;: &amp;quot;kills&amp;quot;,&lt;br /&gt;
		&amp;quot;threshold&amp;quot;: api.counter_maximum(api.SCOPE_TEAM, &amp;amp;amp;&amp;quot;kills&amp;quot;),&lt;br /&gt;
		&amp;quot;warn_at&amp;quot;: api.counter_maximum(api.SCOPE_TEAM, &amp;amp;amp;&amp;quot;kills&amp;quot;) - 5,&lt;br /&gt;
	})&lt;br /&gt;
	api.show_widget(&amp;amp;amp;&amp;quot;round_timer&amp;quot;, {&lt;br /&gt;
		&amp;quot;counter&amp;quot;: &amp;quot;time_left&amp;quot;,&lt;br /&gt;
		&amp;quot;warn_at&amp;quot;: 60,&lt;br /&gt;
	})&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== bot.gd ==&lt;br /&gt;
&lt;br /&gt;
The starter bot script is enough: it sends every bot roaming, and a roaming bot hunts whoever is nearest, which is the whole of this mode. To make the bots easier instead, set their skill when they join; a bot with no orders roams anyway:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extends GamemodeBotScript&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
func _player_joined(entity_id: int) -&amp;gt; void:&lt;br /&gt;
	if api.is_bot(entity_id):&lt;br /&gt;
		api.bot_set_skill(entity_id, 0.4)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&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>