<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.fightorder.net/wiki/index.php?action=history&amp;feed=atom&amp;title=AI%3ADevelopment%3ALang%3ALua</id>
	<title>AI:Development:Lang:Lua - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.fightorder.net/wiki/index.php?action=history&amp;feed=atom&amp;title=AI%3ADevelopment%3ALang%3ALua"/>
	<link rel="alternate" type="text/html" href="https://www.fightorder.net/wiki/index.php?title=AI:Development:Lang:Lua&amp;action=history"/>
	<updated>2026-04-21T04:27:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://www.fightorder.net/wiki/index.php?title=AI:Development:Lang:Lua&amp;diff=1562&amp;oldid=prev</id>
		<title>Qrow: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://www.fightorder.net/wiki/index.php?title=AI:Development:Lang:Lua&amp;diff=1562&amp;oldid=prev"/>
		<updated>2026-02-24T06:08:38Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 23:08, 23 February 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Qrow</name></author>
	</entry>
	<entry>
		<id>https://www.fightorder.net/wiki/index.php?title=AI:Development:Lang:Lua&amp;diff=1561&amp;oldid=prev</id>
		<title>interaidev&gt;Zwzsg: /* References */ adding Spring Tank AI</title>
		<link rel="alternate" type="text/html" href="https://www.fightorder.net/wiki/index.php?title=AI:Development:Lang:Lua&amp;diff=1561&amp;oldid=prev"/>
		<updated>2014-08-25T01:54:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;References: &lt;/span&gt; adding Spring Tank AI&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Engine_Development|Development]] &amp;lt; [[AI:Development|AI Development]] &amp;lt; Lua AI Development&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Writing a Lua AI&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Lua AIs are different ===&lt;br /&gt;
Lua for AIs is quite different from all the other AI languages supported by spring. Lua AIs use a completely different interface, and they can not be shipped separately, but only bundled with a mod.&lt;br /&gt;
&lt;br /&gt;
=== Things to know ===&lt;br /&gt;
* They have to be bundled with a mod. Therefore, you should consider contacting the mod developer(s) in question early, to see if they are at all interested in an AI.&lt;br /&gt;
* A Lua AI is actually a regular gadget. The difference is just that it is listed in the mods LuaAI.lua file. See [[Lua_Scripting|Lua Scripting]] for details.&lt;br /&gt;
* This brings up the problem that AIs can &amp;quot;accidentally&amp;quot; cheat or even move units of the enemy! It is up to the AI writer to avoid that. All AI players of the same type also share the same variables and tables. One way to avoid that is to put everything into a teamdata[teamID] table. Or the use of classes.&lt;br /&gt;
&lt;br /&gt;
== How to start ==&lt;br /&gt;
For a start, choose a single mod you want your AI to work with.&lt;br /&gt;
You will also want to contact the mods developer(s) before you start to code,&lt;br /&gt;
or soon thereafter.&lt;br /&gt;
&lt;br /&gt;
Things you need to get comfortable with:&lt;br /&gt;
* the Lua scripting language&lt;br /&gt;
* Lua scripting for spring (gadgets)&lt;br /&gt;
&lt;br /&gt;
You may combine learning Lua for spring with writing simplistic gadgets or widgets for spring, and publishing them [http://springrts.com/phpbb/viewforum.php?f=23 in the forum],&lt;br /&gt;
as this way you get practical training and feedback about your code from the pros, plus the community eventually gets a usefull addon.&lt;br /&gt;
When you start feeling comfortable, you should inspect the code of Lua AIs that are already available.&lt;br /&gt;
Source code of these AIs can be found in the mod archives, which you may open with 7zip, or it may be available separately (see [[#References|References]]).&lt;br /&gt;
&lt;br /&gt;
=== Integrating the AI Gadget ===&lt;br /&gt;
This section explains everything you have to do to integrate your Lua AI into a mod. Which at the same time is everything that separates a Lua AI form a gadget.&lt;br /&gt;
&lt;br /&gt;
In the root of the mods archive, you need the file &amp;#039;&amp;#039;LuaAI.lua&amp;#039;&amp;#039;,&lt;br /&gt;
which should look about like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 -- file: LuaAI.lua&lt;br /&gt;
 local listOfLuaAIs = {&lt;br /&gt;
     {&lt;br /&gt;
         name = &amp;quot;MyFirstAI&amp;quot;,&lt;br /&gt;
         desc = &amp;quot;Beats even the best players with Core, most others with Arm too&amp;quot;,&lt;br /&gt;
     },&lt;br /&gt;
 }&lt;br /&gt;
 return listOfLuaAIs&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Besides all the other stuff you need for a gadget (you should know this by now),&lt;br /&gt;
you will need something like this in your code (eg under &amp;#039;&amp;#039;{mod_root}/LuaRules/Gadgets/MyFirstAI_v01.lua&amp;#039;&amp;#039;):&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 function gadget:GetInfo()&lt;br /&gt;
     return {&lt;br /&gt;
         name    = &amp;quot;MyFirstAI&amp;quot;,&lt;br /&gt;
         desc    = &amp;quot;An AI that knows how to play Mod X&amp;quot;,&lt;br /&gt;
         author  = &amp;quot;John Doe&amp;quot;,&lt;br /&gt;
         date    = &amp;quot;2020-12-31&amp;quot;,&lt;br /&gt;
         license = &amp;quot;Public Domain&amp;quot;,&lt;br /&gt;
         layer   = 82,&lt;br /&gt;
         enabled = true&lt;br /&gt;
     }&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 function gadget:GameStart() &lt;br /&gt;
     -- Initialise AI for all teams that are set to use it&lt;br /&gt;
     for _,t in ipairs(Spring.GetTeamList()) do&lt;br /&gt;
         local _,_,_,isAI,side = Spring.GetTeamInfo(t)&lt;br /&gt;
         if Spring.GetTeamLuaAI(t) == gadget:GetInfo().name then&lt;br /&gt;
             Spring.Echo(&amp;quot;Team &amp;quot;..t..&amp;quot; assigned to &amp;quot;..gadget:GetInfo().name)&lt;br /&gt;
             local pos = {}&lt;br /&gt;
             local home_x,home_y,home_z = Spring.GetTeamStartPosition(t)&lt;br /&gt;
         end&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
The above example will not work if your AI controls multiple teams because &amp;#039;&amp;#039;home_x,home_y,home_z&amp;#039;&amp;#039; are not stored &amp;#039;&amp;#039;per team.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it, the rest of the game is using regular gadget functions, and in particular [http://springrts.com/wiki/Lua_SyncedCtrl#Give_Order Spring.GiveOrderToUnit()]. Now you should be able to use this AI when starting the modified mod in the lobby, when you click on the &amp;#039;&amp;#039;Add Bot&amp;#039;&amp;#039; button. From Spring 95.0 onwards, lua AIs can be selected from the Spring.exe menu.&lt;br /&gt;
&lt;br /&gt;
Enjoy!&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* NOE AI: http://springrts.com/phpbb/viewtopic.php?f=55&amp;amp;t=28259&lt;br /&gt;
* ST AI source: http://pastebin.com/v1kNRBDj&lt;br /&gt;
* KP AI source: http://pastebin.com/f771164a0&lt;br /&gt;
* CRAIG source:&lt;br /&gt;
** to browse: http://github.com/tvo/craig/tree/master&lt;br /&gt;
** for git: git://github.com/tvo/craig.git&lt;br /&gt;
* C.R.A.I.G. is inside S44 and SWIW&lt;br /&gt;
* forum thread: [http://springrts.com/phpbb/viewtopic.php?f=15&amp;amp;t=25639 LuaAI information] &lt;br /&gt;
* forum threads about an AI for the game Conflict Terra: [http://springrts.com/phpbb/viewtopic.php?f=63&amp;amp;t=26148] [http://springrts.com/phpbb/viewtopic.php?f=63&amp;amp;t=26214] [http://springrts.com/phpbb/viewtopic.php?f=15&amp;amp;t=26207] (among the OT, some more or less common LuaAI problems are discussed)&lt;br /&gt;
&lt;br /&gt;
[[Category: AI Dev]]&lt;/div&gt;</summary>
		<author><name>interaidev&gt;Zwzsg</name></author>
	</entry>
</feed>