<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://chronocrash.com/openbor/wiki/index.php?action=history&amp;feed=atom&amp;title=Spawnscript</id>
	<title>Spawnscript - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://chronocrash.com/openbor/wiki/index.php?action=history&amp;feed=atom&amp;title=Spawnscript"/>
	<link rel="alternate" type="text/html" href="https://chronocrash.com/openbor/wiki/index.php?title=Spawnscript&amp;action=history"/>
	<updated>2026-09-15T09:09:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://chronocrash.com/openbor/wiki/index.php?title=Spawnscript&amp;diff=1020&amp;oldid=prev</id>
		<title>Dcurrent at 22:37, 20 August 2026</title>
		<link rel="alternate" type="text/html" href="https://chronocrash.com/openbor/wiki/index.php?title=Spawnscript&amp;diff=1020&amp;oldid=prev"/>
		<updated>2026-08-20T22:37:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&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 18:37, 20 August 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-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&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;[[Category:Level]]&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;[[Category:Level]]&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;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Script]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&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;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Script Events]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&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;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&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;&amp;#039;&amp;#039;&amp;#039;spawnscript&amp;#039;&amp;#039;&amp;#039; is a level spawn-entry event hook. It executes when its specific spawn entry creates an entity, after OpenBOR has applied the entry&amp;#039;s spawn properties and executed the entity&amp;#039;s applicable [[Onspawnscript|onspawnscript]].&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;&amp;#039;&amp;#039;&amp;#039;spawnscript&amp;#039;&amp;#039;&amp;#039; is a level spawn-entry event hook. It executes when its specific spawn entry creates an entity, after OpenBOR has applied the entry&amp;#039;s spawn properties and executed the entity&amp;#039;s applicable [[Onspawnscript|onspawnscript]].&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-l230&quot;&gt;Line 230:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 227:&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;* [[Thinkscript]]&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;* [[Thinkscript]]&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;* [[Script Overview]]&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;* [[Script Overview]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:OpenBOR Index]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&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;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Script Events]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Dcurrent</name></author>
	</entry>
	<entry>
		<id>https://chronocrash.com/openbor/wiki/index.php?title=Spawnscript&amp;diff=1019&amp;oldid=prev</id>
		<title>Dcurrent: Created page with &quot;Category:Level Category:Script Category:Script Events  &#039;&#039;&#039;spawnscript&#039;&#039;&#039; is a level spawn-entry event hook. It executes when its specific spawn entry creates an entity, after OpenBOR has applied the entry&#039;s spawn properties and executed the entity&#039;s applicable onspawnscript.  Unlike &lt;code&gt;onspawnscript&lt;/code&gt;, which belongs to a model, &lt;code&gt;spawnscript&lt;/code&gt; belongs to an individual entry in a level. Separate instances of the same model ca...&quot;</title>
		<link rel="alternate" type="text/html" href="https://chronocrash.com/openbor/wiki/index.php?title=Spawnscript&amp;diff=1019&amp;oldid=prev"/>
		<updated>2026-08-20T22:35:00Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/openbor/wiki/index.php/Category:Level&quot; title=&quot;Category:Level&quot;&gt;Category:Level&lt;/a&gt; &lt;a href=&quot;/openbor/wiki/index.php/Category:Script&quot; title=&quot;Category:Script&quot;&gt;Category:Script&lt;/a&gt; &lt;a href=&quot;/openbor/wiki/index.php/Category:Script_Events&quot; title=&quot;Category:Script Events&quot;&gt;Category:Script Events&lt;/a&gt;  &amp;#039;&amp;#039;&amp;#039;spawnscript&amp;#039;&amp;#039;&amp;#039; is a level spawn-entry event hook. It executes when its specific spawn entry creates an entity, after OpenBOR has applied the entry&amp;#039;s spawn properties and executed the entity&amp;#039;s applicable &lt;a href=&quot;/openbor/wiki/index.php/Onspawnscript&quot; title=&quot;Onspawnscript&quot;&gt;onspawnscript&lt;/a&gt;.  Unlike &amp;lt;code&amp;gt;onspawnscript&amp;lt;/code&amp;gt;, which belongs to a model, &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; belongs to an individual entry in a level. Separate instances of the same model ca...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Level]]&lt;br /&gt;
[[Category:Script]]&lt;br /&gt;
[[Category:Script Events]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;spawnscript&amp;#039;&amp;#039;&amp;#039; is a level spawn-entry event hook. It executes when its specific spawn entry creates an entity, after OpenBOR has applied the entry&amp;#039;s spawn properties and executed the entity&amp;#039;s applicable [[Onspawnscript|onspawnscript]].&lt;br /&gt;
&lt;br /&gt;
Unlike &amp;lt;code&amp;gt;onspawnscript&amp;lt;/code&amp;gt;, which belongs to a model, &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; belongs to an individual entry in a level. Separate instances of the same model can therefore receive different roles, objectives, relationships, controller data, or custom behavior without creating additional models. This makes &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; especially useful for encounter construction and other sequence-heavy level design.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
Add &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; to a level spawn entry and provide the path to the script file. The command must appear before the entry&amp;#039;s &amp;lt;code&amp;gt;at&amp;lt;/code&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
spawn dock_thug&lt;br /&gt;
coords 520 230 0&lt;br /&gt;
spawnscript data/scripts/spawns/dock_flanker.c&lt;br /&gt;
at 400&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The referenced script uses a &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; entry point. OpenBOR populates the event variables immediately before calling it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    void self = getlocalvar(&amp;quot;self&amp;quot;);&lt;br /&gt;
    float spawn_x = getlocalvar(&amp;quot;spawnx&amp;quot;);&lt;br /&gt;
    float spawn_z = getlocalvar(&amp;quot;spawnz&amp;quot;);&lt;br /&gt;
    float spawn_y = getlocalvar(&amp;quot;spawny&amp;quot;);&lt;br /&gt;
    int spawn_at = getlocalvar(&amp;quot;spawnat&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    // Configure this specific spawn instance here.&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each spawn entry owns its own &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt;. Reusing the same script file across several entries provides common behavior, while assigning different files allows each entry to perform unique setup.&lt;br /&gt;
&lt;br /&gt;
== Inline Script ==&lt;br /&gt;
&lt;br /&gt;
Spawn entries also support inline script blocks. Place the block before &amp;lt;code&amp;gt;at&amp;lt;/code&amp;gt;, just like an external &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
spawn dock_thug&lt;br /&gt;
coords 520 230 0&lt;br /&gt;
&lt;br /&gt;
@script&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    void self = getlocalvar(&amp;quot;self&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    setentityvar(self, &amp;quot;encounter_role&amp;quot;, &amp;quot;dock_flanker&amp;quot;);&lt;br /&gt;
    setentityvar(self, &amp;quot;encounter_wave&amp;quot;, 2);&lt;br /&gt;
}&lt;br /&gt;
@end_script&lt;br /&gt;
&lt;br /&gt;
at 400&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inline form is convenient for concise entry-specific setup. External files are generally easier to reuse when several entries share behavior or the setup requires multiple functions.&lt;br /&gt;
&lt;br /&gt;
== Execution ==&lt;br /&gt;
&lt;br /&gt;
The relevant spawn sequence is:&lt;br /&gt;
&lt;br /&gt;
# A level spawn entry reaches its configured &amp;lt;code&amp;gt;at&amp;lt;/code&amp;gt; condition.&lt;br /&gt;
# OpenBOR creates the entity and applies the entry&amp;#039;s model, alias, palette, health, coordinates, item, weapon, parent, and other configured spawn properties.&lt;br /&gt;
# The applicable global model &amp;lt;code&amp;gt;onspawnscript&amp;lt;/code&amp;gt; executes when present.&lt;br /&gt;
# The entity model&amp;#039;s [[Onspawnscript|onspawnscript]] executes when present.&lt;br /&gt;
# The level entry&amp;#039;s &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; executes when present.&lt;br /&gt;
# OpenBOR returns the completed entity to normal level processing.&lt;br /&gt;
&lt;br /&gt;
The entity is fully available through &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; when &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; runs. Entry-specific setup can therefore inspect or modify the entity, establish references to other objects, initialize custom variables, select an animation or action, create supporting objects, or communicate with encounter controllers.&lt;br /&gt;
&lt;br /&gt;
Since &amp;lt;code&amp;gt;onspawnscript&amp;lt;/code&amp;gt; executes first, &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; can build on or specialize the model&amp;#039;s normal initialization. This ordering supports a useful division of responsibility: let the model establish what every instance needs, then let the level entry establish what this particular instance should do.&lt;br /&gt;
&lt;br /&gt;
== Event Data ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable sortable&amp;quot;&lt;br /&gt;
! Variable&lt;br /&gt;
! Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt;&lt;br /&gt;
| Object pointer&lt;br /&gt;
| Entity created by the spawn entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spawnx&amp;lt;/code&amp;gt;&lt;br /&gt;
| Decimal&lt;br /&gt;
| X coordinate supplied by the spawn entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spawnz&amp;lt;/code&amp;gt;&lt;br /&gt;
| Decimal&lt;br /&gt;
| Z coordinate supplied by the spawn entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spawny&amp;lt;/code&amp;gt;&lt;br /&gt;
| Decimal&lt;br /&gt;
| Y coordinate supplied by the spawn entry. This is the third value of &amp;lt;code&amp;gt;coords&amp;lt;/code&amp;gt; and represents vertical altitude.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spawnat&amp;lt;/code&amp;gt;&lt;br /&gt;
| Integer&lt;br /&gt;
| Trigger value supplied by the spawn entry&amp;#039;s &amp;lt;code&amp;gt;at&amp;lt;/code&amp;gt; command.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The coordinate variables describe the level entry&amp;#039;s configured spawn point. They do not dynamically follow later movement or changes made to the entity&amp;#039;s position. Read the applicable entity properties from &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; when the current position is required.&lt;br /&gt;
&lt;br /&gt;
== Spawnscript and Onspawnscript ==&lt;br /&gt;
&lt;br /&gt;
The two hooks execute in the same creation sequence but serve different scopes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Property&lt;br /&gt;
! spawnscript&lt;br /&gt;
! onspawnscript&lt;br /&gt;
|-&lt;br /&gt;
| Owner&lt;br /&gt;
| Individual level spawn entry&lt;br /&gt;
| Model&lt;br /&gt;
|-&lt;br /&gt;
| Coverage&lt;br /&gt;
| Only the entry containing the script&lt;br /&gt;
| Applicable instances of the model&lt;br /&gt;
|-&lt;br /&gt;
| Setup location&lt;br /&gt;
| Level definition, before &amp;lt;code&amp;gt;at&amp;lt;/code&amp;gt;&lt;br /&gt;
| Model definition&lt;br /&gt;
|-&lt;br /&gt;
| Execution order&lt;br /&gt;
| After &amp;lt;code&amp;gt;onspawnscript&amp;lt;/code&amp;gt;&lt;br /&gt;
| Before &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Event data&lt;br /&gt;
| Created entity, entry coordinates, and &amp;lt;code&amp;gt;at&amp;lt;/code&amp;gt; value&lt;br /&gt;
| Created entity&lt;br /&gt;
|-&lt;br /&gt;
| Typical responsibility&lt;br /&gt;
| Encounter-specific role and level context&lt;br /&gt;
| Universal model initialization&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Neither hook replaces the other. Models can use &amp;lt;code&amp;gt;onspawnscript&amp;lt;/code&amp;gt; for reliable baseline setup while levels use &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; to turn individual instances into guards, flankers, escorts, leaders, targets, hazards, controllers, or any other role required by the encounter.&lt;br /&gt;
&lt;br /&gt;
== Example: Assign an Encounter Role ==&lt;br /&gt;
&lt;br /&gt;
The following compact script marks the spawned entity as a flanker and preserves its entry coordinates as a formation anchor:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    void self = getlocalvar(&amp;quot;self&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    setentityvar(self, &amp;quot;encounter_role&amp;quot;, &amp;quot;flanker&amp;quot;);&lt;br /&gt;
    setentityvar(self, &amp;quot;encounter_wave&amp;quot;, 2);&lt;br /&gt;
&lt;br /&gt;
    setentityvar(&lt;br /&gt;
        self,&lt;br /&gt;
        &amp;quot;formation_anchor_x&amp;quot;,&lt;br /&gt;
        getlocalvar(&amp;quot;spawnx&amp;quot;)&lt;br /&gt;
    );&lt;br /&gt;
&lt;br /&gt;
    setentityvar(&lt;br /&gt;
        self,&lt;br /&gt;
        &amp;quot;formation_anchor_z&amp;quot;,&lt;br /&gt;
        getlocalvar(&amp;quot;spawnz&amp;quot;)&lt;br /&gt;
    );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The model&amp;#039;s update, think, animation, or key scripts can consume these values later. Another entry using the same model can assign a different role and parameters, allowing one model to participate in several coordinated behaviors within the same encounter.&lt;br /&gt;
&lt;br /&gt;
== Example: Register With a Wave Controller ==&lt;br /&gt;
&lt;br /&gt;
Spawn scripts can also publish entry-specific information for a shared controller:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
    void self = getlocalvar(&amp;quot;self&amp;quot;);&lt;br /&gt;
    int wave_count = getglobalvar(&amp;quot;dock_wave_2_count&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    setentityvar(self, &amp;quot;wave_id&amp;quot;, 2);&lt;br /&gt;
    setentityvar(self, &amp;quot;spawn_trigger&amp;quot;, getlocalvar(&amp;quot;spawnat&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
    setglobalvar(&amp;quot;dock_wave_2_count&amp;quot;, wave_count + 1);&lt;br /&gt;
    setglobalvar(&amp;quot;dock_wave_2_last_member&amp;quot;, self);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This small handshake is enough for other scripts to track arrivals, wait for a group to be defeated, release reinforcements, update an objective, or coordinate a multi-part encounter. The controller design remains creator-defined; &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; supplies a precise event for registering each member as it enters play.&lt;br /&gt;
&lt;br /&gt;
== Other Uses ==&lt;br /&gt;
&lt;br /&gt;
Quick applications include:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Encounter roles&amp;#039;&amp;#039;&amp;#039; - Mark identical model instances as leaders, guards, flankers, escorts, reinforcements, targets, or support units.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Formation data&amp;#039;&amp;#039;&amp;#039; - Preserve spawn coordinates as patrol anchors, defensive positions, retreat points, or movement boundaries.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Wave management&amp;#039;&amp;#039;&amp;#039; - Register members with shared controllers, update counters, identify groups, or release later sequences.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Entry-specific behavior&amp;#039;&amp;#039;&amp;#039; - Select custom AI modes, aggression rules, dialogue, objectives, relationships, or reactions for one appearance of a model.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Randomization&amp;#039;&amp;#039;&amp;#039; - Choose equipment, palettes, resources, movement patterns, or encounter roles when the entity enters play.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Object relationships&amp;#039;&amp;#039;&amp;#039; - Connect the new entity to leaders, escorts, targets, hazards, switches, or other level objects.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Presentation&amp;#039;&amp;#039;&amp;#039; - Trigger entry effects, labels, sounds, camera responses, or custom introductions associated with a specific spawn.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Debugging and analytics&amp;#039;&amp;#039;&amp;#039; - Record which entry created an entity, its configured coordinates, and the point in the level where it appeared.&lt;br /&gt;
&lt;br /&gt;
== Related Scripts ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Script&lt;br /&gt;
! Relationship&lt;br /&gt;
|-&lt;br /&gt;
| [[Onspawnscript|onspawnscript]]&lt;br /&gt;
| Model hook that executes before &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt; and provides universal initialization for applicable model instances.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;spawnscript&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| Level entry hook that specializes the newly created entity for one particular spawn.&lt;br /&gt;
|-&lt;br /&gt;
| [[Levelscript|levelscript]]&lt;br /&gt;
| Executes once when the level begins and can prepare shared encounter state before spawn entries activate.&lt;br /&gt;
|-&lt;br /&gt;
| [[Updateentityscript|updateentityscript]]&lt;br /&gt;
| Recurring model hook that can consume roles and parameters assigned by &amp;lt;code&amp;gt;spawnscript&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| [[Thinkscript|thinkscript]]&lt;br /&gt;
| Model decision hook that can use entry-specific state when selecting behavior.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Level]]&lt;br /&gt;
* [[Onspawnscript]]&lt;br /&gt;
* [[Levelscript]]&lt;br /&gt;
* [[Updateentityscript]]&lt;br /&gt;
* [[Thinkscript]]&lt;br /&gt;
* [[Script Overview]]&lt;/div&gt;</summary>
		<author><name>Dcurrent</name></author>
	</entry>
</feed>