<?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%2FKing_of_the_Hill</id>
	<title>Level Editor/Scripting/Examples/King of the Hill - 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%2FKing_of_the_Hill"/>
	<link rel="alternate" type="text/html" href="https://wiki.teamspec.net/index.php?title=Level_Editor/Scripting/Examples/King_of_the_Hill&amp;action=history"/>
	<updated>2026-10-28T21:45:04Z</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/King_of_the_Hill&amp;diff=476&amp;oldid=prev</id>
		<title>TeamSpecBot: American spelling</title>
		<link rel="alternate" type="text/html" href="https://wiki.teamspec.net/index.php?title=Level_Editor/Scripting/Examples/King_of_the_Hill&amp;diff=476&amp;oldid=prev"/>
		<updated>2026-10-20T04:44:45Z</updated>

		<summary type="html">&lt;p&gt;American spelling&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:44, 20 October 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l26&quot;&gt;Line 26:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 26:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;func _start() -&amp;gt; void:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;func _start() -&amp;gt; void:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	if api.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;zones_labelled&lt;/del&gt;(HILL).is_empty():&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	if api.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;zones_labeled&lt;/ins&gt;(HILL).is_empty():&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;		api.log(&amp;quot;no zone named Hill in this map&amp;quot;)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;		api.log(&amp;quot;no zone named Hill in this map&amp;quot;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l94&quot;&gt;Line 94:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 94:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;func _start() -&amp;gt; void:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;func _start() -&amp;gt; void:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	var hills: Array = api.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;zones_labelled&lt;/del&gt;(HILL)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	var hills: Array = api.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;zones_labeled&lt;/ins&gt;(HILL)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	if not hills.is_empty():&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	if not hills.is_empty():&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;		_hill = hills[0]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;		_hill = hills[0]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki:diff:1.41:old-56:rev-476:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>TeamSpecBot</name></author>
	</entry>
	<entry>
		<id>https://wiki.teamspec.net/index.php?title=Level_Editor/Scripting/Examples/King_of_the_Hill&amp;diff=56&amp;oldid=prev</id>
		<title>TeamSpecBot: Level Editor: King of the Hill example</title>
		<link rel="alternate" type="text/html" href="https://wiki.teamspec.net/index.php?title=Level_Editor/Scripting/Examples/King_of_the_Hill&amp;diff=56&amp;oldid=prev"/>
		<updated>2026-10-20T03:46:17Z</updated>

		<summary type="html">&lt;p&gt;Level Editor: King of the Hill example&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;One zone in the middle of the map. A team scores a point for every second it holds the hill with nobody from the other team on it, and the first team to 60 wins.&lt;br /&gt;
&lt;br /&gt;
== The map ==&lt;br /&gt;
&lt;br /&gt;
* A brush over the hill with &amp;#039;&amp;#039;&amp;#039;Is Area&amp;#039;&amp;#039;&amp;#039; ticked and &amp;#039;&amp;#039;&amp;#039;Trigger Name&amp;#039;&amp;#039;&amp;#039; set to &amp;lt;code&amp;gt;Hill&amp;lt;/code&amp;gt;. Leave &amp;#039;&amp;#039;&amp;#039;Zone Team&amp;#039;&amp;#039;&amp;#039; at 0.&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;
== 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 HILL := &amp;amp;amp;&amp;quot;Hill&amp;quot;&lt;br /&gt;
const WIN_SCORE := 60&lt;br /&gt;
&lt;br /&gt;
## Seconds held towards the next point.&lt;br /&gt;
var _held: 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;score&amp;quot;, 0, 0, WIN_SCORE)&lt;br /&gt;
	# Who holds the hill right now: 0 for nobody, or when it is contested.&lt;br /&gt;
	api.declare_global_counter(&amp;amp;amp;&amp;quot;holder&amp;quot;, 0, 0, 2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
func _start() -&amp;gt; void:&lt;br /&gt;
	if api.zones_labelled(HILL).is_empty():&lt;br /&gt;
		api.log(&amp;quot;no zone named Hill in this map&amp;quot;)&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;
&lt;br /&gt;
&lt;br /&gt;
func _zone_tick(zone: StringName, occupants: Array, delta: float) -&amp;gt; void:&lt;br /&gt;
	if api.zone_label(zone) != HILL:&lt;br /&gt;
		return&lt;br /&gt;
	var holder: int = 0&lt;br /&gt;
	for entity_id in occupants:&lt;br /&gt;
		var team: int = api.team_of(entity_id)&lt;br /&gt;
		if holder == 0:&lt;br /&gt;
			holder = team&lt;br /&gt;
		elif team != holder:&lt;br /&gt;
			holder = 0&lt;br /&gt;
			break&lt;br /&gt;
	if holder != api.get_global(&amp;amp;amp;&amp;quot;holder&amp;quot;):&lt;br /&gt;
		api.set_global(&amp;amp;amp;&amp;quot;holder&amp;quot;, holder)&lt;br /&gt;
		if holder != 0:&lt;br /&gt;
			api.notify_all(&amp;quot;%s took the hill&amp;quot; % api.team_name(holder))&lt;br /&gt;
	if holder == 0:&lt;br /&gt;
		_held = 0.0&lt;br /&gt;
		return&lt;br /&gt;
	_held += delta&lt;br /&gt;
	while _held &amp;gt;= 1.0:&lt;br /&gt;
		_held -= 1.0&lt;br /&gt;
		if api.add_team(holder, &amp;amp;amp;&amp;quot;score&amp;quot;, 1) &amp;gt;= WIN_SCORE:&lt;br /&gt;
			api.declare_winner(holder, &amp;quot;held the hill for %d seconds&amp;quot; % WIN_SCORE)&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;_zone_tick&amp;lt;/code&amp;gt; runs for the hill every tick, empty or not, so the timer resets the moment the hill is empty or contested. See [[Level Editor/Scripting/Zones#Zone hooks|Zones and area triggers]].&lt;br /&gt;
* The &amp;lt;code&amp;gt;holder&amp;lt;/code&amp;gt; counter only changes when control changes, so the message goes out once per change rather than every tick.&lt;br /&gt;
* &amp;lt;code&amp;gt;add_team&amp;lt;/code&amp;gt; returns the new score, which is all the win check needs. [[Level Editor/Scripting/Reference/GamemodeServerApi#declare_winner|api.declare_winner]] ends the round; the game does the rest.&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;score&amp;quot;,&lt;br /&gt;
		&amp;quot;threshold&amp;quot;: api.counter_maximum(api.SCOPE_TEAM, &amp;amp;amp;&amp;quot;score&amp;quot;),&lt;br /&gt;
		&amp;quot;warn_at&amp;quot;: api.counter_maximum(api.SCOPE_TEAM, &amp;amp;amp;&amp;quot;score&amp;quot;) - 10,&lt;br /&gt;
	})&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The client script reads the winning score from the counter&amp;#039;s declared maximum, so changing &amp;lt;code&amp;gt;WIN_SCORE&amp;lt;/code&amp;gt; in the server script is the only edit a different target needs.&lt;br /&gt;
&lt;br /&gt;
== bot.gd ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extends GamemodeBotScript&lt;br /&gt;
&lt;br /&gt;
const HILL := &amp;amp;amp;&amp;quot;Hill&amp;quot;&lt;br /&gt;
const REVIEW_SECONDS := 1.0&lt;br /&gt;
&lt;br /&gt;
var _hill: StringName = &amp;amp;amp;&amp;quot;&amp;quot;&lt;br /&gt;
var _review: float = 0.0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
func _start() -&amp;gt; void:&lt;br /&gt;
	var hills: Array = api.zones_labelled(HILL)&lt;br /&gt;
	if not hills.is_empty():&lt;br /&gt;
		_hill = hills[0]&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.5)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
func _tick(delta: float) -&amp;gt; void:&lt;br /&gt;
	_review -= delta&lt;br /&gt;
	if _review &amp;gt; 0.0 or _hill == &amp;amp;amp;&amp;quot;&amp;quot;:&lt;br /&gt;
		return&lt;br /&gt;
	_review = REVIEW_SECONDS&lt;br /&gt;
	var at: Vector3 = api.zone_position(_hill)&lt;br /&gt;
	for entity_id in api.bots():&lt;br /&gt;
		if api.is_alive(entity_id):&lt;br /&gt;
			api.bot_defend(entity_id, at, 8.0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every bot is told to hold the hill once a second. Orders do not expire, so giving the same one again is the normal way to keep it; see [[Level Editor/Scripting/Bots|Bots]].&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>