<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://springrts-wiki.p2004a.com/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Autowar</id>
	<title>Spring - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://springrts-wiki.p2004a.com/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Autowar"/>
	<link rel="alternate" type="text/html" href="https://springrts-wiki.p2004a.com/wiki/Special:Contributions/Autowar"/>
	<updated>2026-11-08T18:36:10Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://springrts-wiki.p2004a.com/mediawiki/index.php?title=Lua_CMDs&amp;diff=11171</id>
		<title>Lua CMDs</title>
		<link rel="alternate" type="text/html" href="https://springrts-wiki.p2004a.com/mediawiki/index.php?title=Lua_CMDs&amp;diff=11171"/>
		<updated>2015-09-25T05:56:09Z</updated>

		<summary type="html">&lt;p&gt;Autowar: /* Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Engine_Development|Development]] &amp;lt; [[Lua_Scripting|Lua Scripting]] &amp;lt; {{FULLPAGENAME}}&lt;br /&gt;
&lt;br /&gt;
== Options ==&lt;br /&gt;
&amp;lt;b id=CMD.OPT_ALT&amp;gt;CMD.OPT_ALT&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_CTRL&amp;gt;CMD.OPT_CTRL&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_SHIFT&amp;gt;CMD.OPT_SHIFT&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_RIGHT&amp;gt;CMD.OPT_RIGHT&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_INTERNAL&amp;gt;CMD.OPT_INTERNAL&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_META&amp;gt;CMD.OPT_META&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Waitcodes ==&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_TIME&amp;gt;CMD.WAITCODE_TIME&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_DEATH&amp;gt;CMD.WAITCODE_DEATH&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_SQUAD&amp;gt;CMD.WAITCODE_SQUAD&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_GATHER&amp;gt;CMD.WAITCODE_GATHER&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Insert/Remove Commands ==&lt;br /&gt;
To get the commandqueue use the following lua-call&lt;br /&gt;
&lt;br /&gt;
=== CommandQueues ===&lt;br /&gt;
&#039;&#039;&#039;Spring.GetUnitCommands&#039;&#039;&#039; &amp;lt;br/&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Spring.GetCommandQueue&#039;&#039;&#039; &amp;lt;span class=&amp;quot;note&amp;quot;&amp;gt;(Alias)&amp;lt;/span&amp;gt;&lt;br /&gt;
  ( number unitID, number count = 0 ) -&amp;gt; nil | number commandQueueSize {{new|96}}&lt;br /&gt;
  ( number unitID [, number count = -1] ) &lt;br /&gt;
  -&amp;gt; nil | table commandQueueTable = {&lt;br /&gt;
     [1] = {&lt;br /&gt;
       &amp;quot;id&amp;quot;      = number,&lt;br /&gt;
       &amp;quot;params&amp;quot;  = { [1] = number, ...},&lt;br /&gt;
       &amp;quot;options&amp;quot; = {&lt;br /&gt;
         &amp;quot;coded&amp;quot;    = number,&lt;br /&gt;
         &amp;quot;alt&amp;quot;      = boolean,&lt;br /&gt;
         &amp;quot;ctrl&amp;quot;     = boolean,&lt;br /&gt;
         &amp;quot;shift&amp;quot;    = boolean,&lt;br /&gt;
         &amp;quot;right&amp;quot;    = boolean,&lt;br /&gt;
         &amp;quot;internal&amp;quot; = boolean,&lt;br /&gt;
         &amp;quot;meta&amp;quot;    = boolean&lt;br /&gt;
       }&lt;br /&gt;
     }, ...&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=note&amp;gt;First, said &amp;quot;tags&amp;quot; aka &amp;quot;id&amp;quot; are unique command identifiers, so each command that gets inserted into a unit&#039;s command &lt;br /&gt;
queue gets its unique &amp;quot;tag&amp;quot; number. (It is used to &#039;&#039;sync&#039;&#039; command queue operations, also it makes things much easier.)&lt;br /&gt;
Editors Note: I fucking hate it when open source devs use the word easy. It is a clear indicator that someone spends a whole day finding out about a well hidden simple concept. Well at least we are on this journey together :)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
To look at those &amp;quot;tags&amp;quot; you can do the following:&lt;br /&gt;
   local cmdQueue = Spring.GetUnitCommands(unitID);&lt;br /&gt;
   if (#cmdQueue&amp;gt;0) then &lt;br /&gt;
      local cmdTag = cmdQueue[1].tag&lt;br /&gt;
      Spring.Echo(cmdTag)&lt;br /&gt;
      ..&lt;br /&gt;
   end&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMD.INSERT&amp;gt;CMD.INSERT&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  options.ALT     -&amp;gt; treat param0 as a position instead of a tag &lt;br /&gt;
  options.CONTROL -&amp;gt; use the build queue for factories &lt;br /&gt;
  params[0] = command tag or position (negative numbers to reference&lt;br /&gt;
  the back of the queue and 0 the first)&lt;br /&gt;
  params[1] = insertCmd id &lt;br /&gt;
  params[2] = insertCmd options (shift,alt,right click,etc.)&lt;br /&gt;
  params[3 ... N+2] = insertCmd params[0 ... N-1]&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;example:&lt;br /&gt;
    Spring.GiveOrderToUnit(unitID,&lt;br /&gt;
      CMD.INSERT,&lt;br /&gt;
      {-1,CMD.ATTACK,&#039;&#039;CMD.OPT_SHIFT&#039;&#039;,&#039;&#039;unitID2&#039;&#039;},&lt;br /&gt;
      {&amp;quot;alt&amp;quot;}&lt;br /&gt;
    );&lt;br /&gt;
	Command structure dissection:&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;What to do with the command - in our case insert:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;CMD.INSERT&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;Place in the queue to insert:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;-1&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;Type of command to insert:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;CMD.ATTACK&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;Additional Information:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
	If the unit is working down a shift queue, add it seemless into it&lt;br /&gt;
&lt;br /&gt;
		&#039;CMD.OPT_SHIFT&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;TargetID or Position:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;unitID2&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;The &#039;-1&#039; is the queue position and not a tag:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;{&amp;quot;alt&amp;quot;}&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if you insert cmd in pos 2 for example the rest of commands starting&lt;br /&gt;
  from 2 will be pushed back. &lt;br /&gt;
  Ilustration: {cmdA, cmdB, cmdC, cmdD} =&amp;gt; {cmdA, cmdB, NewCmd, cmdC, cmdD}&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;
  Note: If you didn&#039;t already notice, the command params and&lt;br /&gt;
        the command options are twisted in the array (compared to GiveOrder)!&lt;br /&gt;
  &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;
  Note2: The command options in the array/table is a number value!&lt;br /&gt;
         You have to use CMD.OPT_* in this case.&lt;br /&gt;
  &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;
  Note3: The inserted command doesn&#039;t go through allowcommand callins, only CMD.INSERT does.&lt;br /&gt;
  &amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.REMOVE&amp;gt;CMD.REMOVE&amp;lt;/b&amp;gt;&lt;br /&gt;
  options.ALT     -&amp;gt; use the parameters as commandIDs &lt;br /&gt;
  options.CONTROL -&amp;gt; use the build queue for factories &lt;br /&gt;
  params[0 ... N-1] = tags or commandIDs to remove&lt;br /&gt;
&lt;br /&gt;
No clues what the above mean translated, but here is a working example of how to delete a buildorder from a factory:  &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;     &lt;br /&gt;
 local facCmds = Spring.GetFactoryCommands(factoryID)&lt;br /&gt;
 &lt;br /&gt;
      if facCmds then -- nil check&lt;br /&gt;
		local cmd = facCmds[1]&lt;br /&gt;
         Spring.GiveOrderToUnit(factoryID, CMD.REMOVE, {i,cmd.tag}, {&amp;quot;ctrl&amp;quot;})&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
 &amp;lt;/font color=&amp;quot;#55ee99&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
&amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Note, the CMD[] table is bidirectional. That means: CMD[CMD.STOP] := &amp;quot;CMD_STOP&amp;quot;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMD.STOP&amp;gt;CMD.STOP&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.WAIT&amp;gt;CMD.WAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.TIMEWAIT&amp;gt;CMD.TIMEWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.NUMBER|CMDTYPE.NUMBER]]&lt;br /&gt;
&amp;lt;b id=CMD.DEATHWAIT&amp;gt;CMD.DEATHWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_RECTANGLE|CMDTYPE.ICON_UNIT_OR_RECTANGLE]]&lt;br /&gt;
&amp;lt;b id=CMD.SQUADWAIT&amp;gt;CMD.SQUADWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.NUMBER|CMDTYPE.NUMBER]]&lt;br /&gt;
&amp;lt;b id=CMD.GATHERWAIT&amp;gt;CMD.GATHERWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.MOVE&amp;gt;CMD.MOVE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.PATROL&amp;gt;CMD.PATROL&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.FIGHT&amp;gt;CMD.FIGHT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.ATTACK&amp;gt;CMD.ATTACK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_MAP|CMDTYPE.ICON_UNIT_OR_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.AREA_ATTACK&amp;gt;CMD.AREA_ATTACK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_AREA|CMDTYPE.ICON_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.GUARD&amp;gt;CMD.GUARD&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT|CMDTYPE.ICON_UNIT]]&lt;br /&gt;
&amp;lt;b id=CMD.AISELECT&amp;gt;CMD.AISELECT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.COMBO_BOX|CMDTYPE.COMBO_BOX]]&lt;br /&gt;
&amp;lt;b id=CMD.GROUPSELECT&amp;gt;CMD.GROUPSELECT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.GROUPADD&amp;gt;CMD.GROUPADD&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.GROUPCLEAR&amp;gt;CMD.GROUPCLEAR&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.REPAIR&amp;gt;CMD.REPAIR&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.FIRE_STATE&amp;gt;CMD.FIRE_STATE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.MOVE_STATE&amp;gt;CMD.MOVE_STATE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.SELFD&amp;gt;CMD.SELFD&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.LOAD_UNITS&amp;gt;CMD.LOAD_UNITS&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.LOAD_ONTO&amp;gt;CMD.LOAD_ONTO&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT|CMDTYPE.ICON_UNIT]]&lt;br /&gt;
&amp;lt;b id=CMD.UNLOAD_UNITS&amp;gt;CMD.UNLOAD_UNITS&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.UNLOAD_UNIT&amp;gt;CMD.UNLOAD_UNIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.ONOFF&amp;gt;CMD.ONOFF&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.RECLAIM&amp;gt;CMD.RECLAIM&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_FEATURE_OR_AREA|CMDTYPE.ICON_UNIT_FEATURE_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.CLOAK&amp;gt;CMD.CLOAK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.STOCKPILE&amp;gt;CMD.STOCKPILE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.DGUN&amp;gt;CMD.DGUN&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.RESTORE&amp;gt;CMD.RESTORE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_AREA|CMDTYPE.ICON_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.REPEAT&amp;gt;CMD.REPEAT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.TRAJECTORY&amp;gt;CMD.TRAJECTORY&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.RESURRECT&amp;gt;CMD.RESURRECT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_FEATURE_OR_AREA|CMDTYPE.ICON_UNIT_FEATURE_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.CAPTURE&amp;gt;CMD.CAPTURE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.AUTOREPAIRLEVEL&amp;gt;CMD.AUTOREPAIRLEVEL&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.LOOPBACKATTACK&amp;gt;CMD.LOOPBACKATTACK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.IDLEMODE&amp;gt;CMD.IDLEMODE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.SET_WANTED_MAX_SPEED&amp;gt;CMD.SET_WANTED_MAX_SPEED&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.NUMBER|CMDTYPE.NUMBER]]&lt;br /&gt;
&amp;lt;b id=CMD.SETBASE&amp;gt;CMD.SETBASE&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMD.INTERNAL&amp;gt;CMD.INTERNAL&amp;lt;/b&amp;gt;&lt;br /&gt;
  used in different ways&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;A negative number means build command&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The number is -unitDefID of the unittype that this command orders to be built.&lt;br /&gt;
   This means that build orders have no convenient CMD._____ string.&lt;br /&gt;
      The command id for build orders must always be a &amp;quot;minus&amp;quot; sign &amp;lt;i&amp;gt;appended to an integer value&amp;lt;/i&amp;gt;.&lt;br /&gt;
   &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Spring.GiveOrderToUnit(unitID, &amp;lt;b&amp;gt;-(unitDefID)&amp;lt;/b&amp;gt;, {x,y,z(,facing)}, {&amp;quot;shift&amp;quot;})&amp;lt;/font&amp;gt;&lt;br /&gt;
      alternatively:&lt;br /&gt;
   &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Spring.GiveOrderToUnit(unitID, &amp;lt;b&amp;gt;-UnitDefNames[&amp;quot;unitname&amp;quot;].id&amp;lt;/b&amp;gt;, {x,y,z(,facing)}, {&amp;quot;shift&amp;quot;})&amp;lt;/font&amp;gt;&lt;br /&gt;
     &amp;lt;b&amp;gt;&#039;facing&#039;&amp;lt;/b&amp;gt; is an optional integer parameter that controls unit&#039;s facing when placed.&lt;br /&gt;
      The values of (x,y,z) must &amp;lt;i&amp;gt;all&amp;lt;/i&amp;gt; be number values (like the number &amp;quot;0&amp;quot;), or the build order will break.&lt;br /&gt;
&lt;br /&gt;
== CommandTypes ==&lt;br /&gt;
&amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Note, the CMDTYPE[] table is bidirectional. That means: CMDTYPE[CMDTYPE.ICON] := &amp;quot;CMDTYPE_ICON&amp;quot;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON&amp;gt;CMDTYPE.ICON&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 0 parameters in return&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_MODE&amp;gt;CMDTYPE.ICON_MODE&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (number selected mode)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_MAP&amp;gt;CMDTYPE.ICON_MAP&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 3 parameters in return (mappos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_AREA&amp;gt;CMDTYPE.ICON_AREA&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 4 parameters in return (mappos+radius)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT&amp;gt;CMDTYPE.ICON_UNIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameters in return (unitid)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_OR_MAP&amp;gt;CMDTYPE.ICON_UNIT_OR_MAP&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameters in return (unitid) or 3 parameters in return (mappos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_FRONT&amp;gt;CMDTYPE.ICON_FRONT&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 3 or 6 parameters in return (middle and right side of front if a front was defined)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.COMBO_BOX&amp;gt;CMDTYPE.COMBO_BOX&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (number selected option)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_OR_AREA&amp;gt;CMDTYPE.ICON_UNIT_OR_AREA&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (unitid) or 4 parameters in return (mappos+radius)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_FEATURE_OR_AREA&amp;gt;CMDTYPE.ICON_UNIT_FEATURE_OR_AREA&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (unitid or [[Lua_ConstGame#Engine|Game.maxUnits]]+featureid)&lt;br /&gt;
      or 4 parameters in return (mappos+radius)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_BUILDING&amp;gt;CMDTYPE.ICON_BUILDING&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 3 parameters in return (mappos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_OR_RECTANGLE&amp;gt;CMDTYPE.ICON_UNIT_OR_RECTANGLE&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (unitid)&lt;br /&gt;
      or 3 parameters in return (mappos)&lt;br /&gt;
      or 6 parameters in return (startpos+endpos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.NUMBER&amp;gt;CMDTYPE.NUMBER&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (number)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMDTYPE.CUSTOM&amp;gt;CMDTYPE.CUSTOM&amp;lt;/b&amp;gt;&lt;br /&gt;
  used with CMD_INTERNAL&lt;br /&gt;
&amp;lt;b id=CMDTYPE.NEXT&amp;gt;CMDTYPE.NEXT&amp;lt;/b&amp;gt; &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;next command page&amp;lt;/font&amp;gt;&lt;br /&gt;
  used with CMD_INTERNAL&lt;br /&gt;
&amp;lt;b id=CMDTYPE.PREV&amp;gt;CMDTYPE.PREV&amp;lt;/b&amp;gt; &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;previous command page&amp;lt;/font&amp;gt;&lt;br /&gt;
  used with CMD_INTERNAL&lt;br /&gt;
&lt;br /&gt;
[[category: Lua]]&lt;/div&gt;</summary>
		<author><name>Autowar</name></author>
	</entry>
	<entry>
		<id>https://springrts-wiki.p2004a.com/mediawiki/index.php?title=Lua_CMDs&amp;diff=11170</id>
		<title>Lua CMDs</title>
		<link rel="alternate" type="text/html" href="https://springrts-wiki.p2004a.com/mediawiki/index.php?title=Lua_CMDs&amp;diff=11170"/>
		<updated>2015-09-25T05:54:30Z</updated>

		<summary type="html">&lt;p&gt;Autowar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Engine_Development|Development]] &amp;lt; [[Lua_Scripting|Lua Scripting]] &amp;lt; {{FULLPAGENAME}}&lt;br /&gt;
&lt;br /&gt;
== Options ==&lt;br /&gt;
&amp;lt;b id=CMD.OPT_ALT&amp;gt;CMD.OPT_ALT&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_CTRL&amp;gt;CMD.OPT_CTRL&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_SHIFT&amp;gt;CMD.OPT_SHIFT&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_RIGHT&amp;gt;CMD.OPT_RIGHT&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_INTERNAL&amp;gt;CMD.OPT_INTERNAL&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_META&amp;gt;CMD.OPT_META&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Waitcodes ==&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_TIME&amp;gt;CMD.WAITCODE_TIME&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_DEATH&amp;gt;CMD.WAITCODE_DEATH&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_SQUAD&amp;gt;CMD.WAITCODE_SQUAD&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_GATHER&amp;gt;CMD.WAITCODE_GATHER&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Insert/Remove Commands ==&lt;br /&gt;
To get the commandqueue use the following lua-call&lt;br /&gt;
&lt;br /&gt;
=== CommandQueues ===&lt;br /&gt;
&#039;&#039;&#039;Spring.GetUnitCommands&#039;&#039;&#039; &amp;lt;br/&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Spring.GetCommandQueue&#039;&#039;&#039; &amp;lt;span class=&amp;quot;note&amp;quot;&amp;gt;(Alias)&amp;lt;/span&amp;gt;&lt;br /&gt;
  ( number unitID, number count = 0 ) -&amp;gt; nil | number commandQueueSize {{new|96}}&lt;br /&gt;
  ( number unitID [, number count = -1] ) &lt;br /&gt;
  -&amp;gt; nil | table commandQueueTable = {&lt;br /&gt;
     [1] = {&lt;br /&gt;
       &amp;quot;id&amp;quot;      = number,&lt;br /&gt;
       &amp;quot;params&amp;quot;  = { [1] = number, ...},&lt;br /&gt;
       &amp;quot;options&amp;quot; = {&lt;br /&gt;
         &amp;quot;coded&amp;quot;    = number,&lt;br /&gt;
         &amp;quot;alt&amp;quot;      = boolean,&lt;br /&gt;
         &amp;quot;ctrl&amp;quot;     = boolean,&lt;br /&gt;
         &amp;quot;shift&amp;quot;    = boolean,&lt;br /&gt;
         &amp;quot;right&amp;quot;    = boolean,&lt;br /&gt;
         &amp;quot;internal&amp;quot; = boolean,&lt;br /&gt;
         &amp;quot;meta&amp;quot;    = boolean&lt;br /&gt;
       }&lt;br /&gt;
     }, ...&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=note&amp;gt;First, said &amp;quot;tags&amp;quot; aka &amp;quot;id&amp;quot; are unique command identifiers, so each command that gets inserted into a unit&#039;s command &lt;br /&gt;
queue gets its unique &amp;quot;tag&amp;quot; number. (It is used to &#039;&#039;sync&#039;&#039; command queue operations, also it makes things much easier.)&lt;br /&gt;
Editors Note: I fucking hate it when open source devs use the word easy. It is a clear indicator that someone spends a whole day finding out about a well hidden simple concept. Well at least we are on this journey together :)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
To look at those &amp;quot;tags&amp;quot; you can do the following:&lt;br /&gt;
   local cmdQueue = Spring.GetUnitCommands(unitID);&lt;br /&gt;
   if (#cmdQueue&amp;gt;0) then &lt;br /&gt;
      local cmdTag = cmdQueue[1].tag&lt;br /&gt;
      Spring.Echo(cmdTag)&lt;br /&gt;
      ..&lt;br /&gt;
   end&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMD.INSERT&amp;gt;CMD.INSERT&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  options.ALT     -&amp;gt; treat param0 as a position instead of a tag &lt;br /&gt;
  options.CONTROL -&amp;gt; use the build queue for factories &lt;br /&gt;
  params[0] = command tag or position (negative numbers to reference&lt;br /&gt;
  the back of the queue and 0 the first)&lt;br /&gt;
  params[1] = insertCmd id &lt;br /&gt;
  params[2] = insertCmd options (shift,alt,right click,etc.)&lt;br /&gt;
  params[3 ... N+2] = insertCmd params[0 ... N-1]&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;example:&lt;br /&gt;
    Spring.GiveOrderToUnit(unitID,&lt;br /&gt;
      CMD.INSERT,&lt;br /&gt;
      {-1,CMD.ATTACK,&#039;&#039;CMD.OPT_SHIFT&#039;&#039;,&#039;&#039;unitID2&#039;&#039;},&lt;br /&gt;
      {&amp;quot;alt&amp;quot;}&lt;br /&gt;
    );&lt;br /&gt;
	Command structure dissection:&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;What to do with the command - in our case insert:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;CMD.INSERT&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;Place in the queue to insert:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;-1&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;Type of command to insert:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;CMD.ATTACK&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;Additional Information:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
	If the unit is working down a shift queue, add it seemless into it&lt;br /&gt;
&lt;br /&gt;
		&#039;CMD.OPT_SHIFT&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;TargetID or Position:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;unitID2&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;The &#039;-1&#039; is the queue position and not a tag:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;{&amp;quot;alt&amp;quot;}&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if you insert cmd in pos 2 for example the rest of commands starting&lt;br /&gt;
  from 2 will be pushed back. &lt;br /&gt;
  Ilustration: {cmdA, cmdB, cmdC, cmdD} =&amp;gt; {cmdA, cmdB, NewCmd, cmdC, cmdD}&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;
  Note: If you didn&#039;t already notice, the command params and&lt;br /&gt;
        the command options are twisted in the array (compared to GiveOrder)!&lt;br /&gt;
  &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;
  Note2: The command options in the array/table is a number value!&lt;br /&gt;
         You have to use CMD.OPT_* in this case.&lt;br /&gt;
  &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;
  Note3: The inserted command doesn&#039;t go through allowcommand callins, only CMD.INSERT does.&lt;br /&gt;
  &amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.REMOVE&amp;gt;CMD.REMOVE&amp;lt;/b&amp;gt;&lt;br /&gt;
  options.ALT     -&amp;gt; use the parameters as commandIDs &lt;br /&gt;
  options.CONTROL -&amp;gt; use the build queue for factories &lt;br /&gt;
  params[0 ... N-1] = tags or commandIDs to remove&lt;br /&gt;
&lt;br /&gt;
No clues what the above mean translated, but here is a working example of how to delete a buildorder from a factory:  &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;     &lt;br /&gt;
 local facCmds = Spring.GetFactoryCommands(factoryID)&lt;br /&gt;
 &lt;br /&gt;
      if facCmds then -- nil check&lt;br /&gt;
		local cmd = facCmds[1]&lt;br /&gt;
         Spring.GiveOrderToUnit(factoryID, CMD.REMOVE, {i,cmd.tag}, {&amp;quot;ctrl&amp;quot;})&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
 &amp;lt;/font color=&amp;quot;#55ee99&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
&amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Note, the CMD[] table is bidirectional. That means: CMD[CMD.STOP] := &amp;quot;CMD_STOP&amp;quot;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMD.STOP&amp;gt;CMD.STOP&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.WAIT&amp;gt;CMD.WAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.TIMEWAIT&amp;gt;CMD.TIMEWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.NUMBER|CMDTYPE.NUMBER]]&lt;br /&gt;
&amp;lt;b id=CMD.DEATHWAIT&amp;gt;CMD.DEATHWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_RECTANGLE|CMDTYPE.ICON_UNIT_OR_RECTANGLE]]&lt;br /&gt;
&amp;lt;b id=CMD.SQUADWAIT&amp;gt;CMD.SQUADWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.NUMBER|CMDTYPE.NUMBER]]&lt;br /&gt;
&amp;lt;b id=CMD.GATHERWAIT&amp;gt;CMD.GATHERWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.MOVE&amp;gt;CMD.MOVE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.PATROL&amp;gt;CMD.PATROL&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.FIGHT&amp;gt;CMD.FIGHT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.ATTACK&amp;gt;CMD.ATTACK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_MAP|CMDTYPE.ICON_UNIT_OR_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.AREA_ATTACK&amp;gt;CMD.AREA_ATTACK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_AREA|CMDTYPE.ICON_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.GUARD&amp;gt;CMD.GUARD&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT|CMDTYPE.ICON_UNIT]]&lt;br /&gt;
&amp;lt;b id=CMD.AISELECT&amp;gt;CMD.AISELECT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.COMBO_BOX|CMDTYPE.COMBO_BOX]]&lt;br /&gt;
&amp;lt;b id=CMD.GROUPSELECT&amp;gt;CMD.GROUPSELECT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.GROUPADD&amp;gt;CMD.GROUPADD&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.GROUPCLEAR&amp;gt;CMD.GROUPCLEAR&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.REPAIR&amp;gt;CMD.REPAIR&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.FIRE_STATE&amp;gt;CMD.FIRE_STATE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.MOVE_STATE&amp;gt;CMD.MOVE_STATE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.SELFD&amp;gt;CMD.SELFD&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.LOAD_UNITS&amp;gt;CMD.LOAD_UNITS&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.LOAD_ONTO&amp;gt;CMD.LOAD_ONTO&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT|CMDTYPE.ICON_UNIT]]&lt;br /&gt;
&amp;lt;b id=CMD.UNLOAD_UNITS&amp;gt;CMD.UNLOAD_UNITS&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.UNLOAD_UNIT&amp;gt;CMD.UNLOAD_UNIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.ONOFF&amp;gt;CMD.ONOFF&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.RECLAIM&amp;gt;CMD.RECLAIM&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_FEATURE_OR_AREA|CMDTYPE.ICON_UNIT_FEATURE_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.CLOAK&amp;gt;CMD.CLOAK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.STOCKPILE&amp;gt;CMD.STOCKPILE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.DGUN&amp;gt;CMD.DGUN&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.RESTORE&amp;gt;CMD.RESTORE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_AREA|CMDTYPE.ICON_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.REPEAT&amp;gt;CMD.REPEAT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.TRAJECTORY&amp;gt;CMD.TRAJECTORY&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.RESURRECT&amp;gt;CMD.RESURRECT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_FEATURE_OR_AREA|CMDTYPE.ICON_UNIT_FEATURE_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.CAPTURE&amp;gt;CMD.CAPTURE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.AUTOREPAIRLEVEL&amp;gt;CMD.AUTOREPAIRLEVEL&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.LOOPBACKATTACK&amp;gt;CMD.LOOPBACKATTACK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.IDLEMODE&amp;gt;CMD.IDLEMODE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.SET_WANTED_MAX_SPEED&amp;gt;CMD.SET_WANTED_MAX_SPEED&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.NUMBER|CMDTYPE.NUMBER]]&lt;br /&gt;
&amp;lt;b id=CMD.SETBASE&amp;gt;CMD.SETBASE&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMD.INTERNAL&amp;gt;CMD.INTERNAL&amp;lt;/b&amp;gt;&lt;br /&gt;
  used in different ways&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;A negative number means build command&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The number is -unitDefID of the unittype that this command orders to be built.&lt;br /&gt;
   This means that build orders have no convenient CMD._____ string.&lt;br /&gt;
      The command id for build orders must always be a &amp;quot;minus&amp;quot; sign &amp;lt;i&amp;gt;appended to an integer value&amp;lt;/i&amp;gt;.&lt;br /&gt;
   &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Spring.GiveOrderToUnit(unitID, &amp;lt;b&amp;gt;-(unitDefID)&amp;lt;/b&amp;gt;, {x,y,z(,facing)}, {&amp;quot;shift&amp;quot;})&amp;lt;/font&amp;gt;&lt;br /&gt;
      alternatively:&lt;br /&gt;
   &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Spring.GiveOrderToUnit(unitID, &amp;lt;b&amp;gt;-UnitDefNames[&amp;quot;unitname&amp;quot;].id&amp;lt;/b&amp;gt;, {x,y,z(,facing)}, {&amp;quot;shift&amp;quot;})&amp;lt;/font&amp;gt;&lt;br /&gt;
     &amp;lt;b&amp;gt;&#039;facing&#039;&amp;lt;/b&amp;gt; is an optional integer parameter that controls unit&#039;s facing when placed.&lt;br /&gt;
      The values of (x,y,z) must &amp;lt;i&amp;gt;all&amp;lt;/i&amp;gt; be number values (like &amp;quot;0&amp;quot;), placeholder symbols such as &amp;quot;_&amp;quot; will break the build order.&lt;br /&gt;
&lt;br /&gt;
== CommandTypes ==&lt;br /&gt;
&amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Note, the CMDTYPE[] table is bidirectional. That means: CMDTYPE[CMDTYPE.ICON] := &amp;quot;CMDTYPE_ICON&amp;quot;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON&amp;gt;CMDTYPE.ICON&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 0 parameters in return&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_MODE&amp;gt;CMDTYPE.ICON_MODE&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (number selected mode)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_MAP&amp;gt;CMDTYPE.ICON_MAP&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 3 parameters in return (mappos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_AREA&amp;gt;CMDTYPE.ICON_AREA&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 4 parameters in return (mappos+radius)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT&amp;gt;CMDTYPE.ICON_UNIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameters in return (unitid)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_OR_MAP&amp;gt;CMDTYPE.ICON_UNIT_OR_MAP&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameters in return (unitid) or 3 parameters in return (mappos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_FRONT&amp;gt;CMDTYPE.ICON_FRONT&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 3 or 6 parameters in return (middle and right side of front if a front was defined)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.COMBO_BOX&amp;gt;CMDTYPE.COMBO_BOX&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (number selected option)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_OR_AREA&amp;gt;CMDTYPE.ICON_UNIT_OR_AREA&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (unitid) or 4 parameters in return (mappos+radius)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_FEATURE_OR_AREA&amp;gt;CMDTYPE.ICON_UNIT_FEATURE_OR_AREA&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (unitid or [[Lua_ConstGame#Engine|Game.maxUnits]]+featureid)&lt;br /&gt;
      or 4 parameters in return (mappos+radius)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_BUILDING&amp;gt;CMDTYPE.ICON_BUILDING&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 3 parameters in return (mappos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_OR_RECTANGLE&amp;gt;CMDTYPE.ICON_UNIT_OR_RECTANGLE&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (unitid)&lt;br /&gt;
      or 3 parameters in return (mappos)&lt;br /&gt;
      or 6 parameters in return (startpos+endpos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.NUMBER&amp;gt;CMDTYPE.NUMBER&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (number)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMDTYPE.CUSTOM&amp;gt;CMDTYPE.CUSTOM&amp;lt;/b&amp;gt;&lt;br /&gt;
  used with CMD_INTERNAL&lt;br /&gt;
&amp;lt;b id=CMDTYPE.NEXT&amp;gt;CMDTYPE.NEXT&amp;lt;/b&amp;gt; &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;next command page&amp;lt;/font&amp;gt;&lt;br /&gt;
  used with CMD_INTERNAL&lt;br /&gt;
&amp;lt;b id=CMDTYPE.PREV&amp;gt;CMDTYPE.PREV&amp;lt;/b&amp;gt; &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;previous command page&amp;lt;/font&amp;gt;&lt;br /&gt;
  used with CMD_INTERNAL&lt;br /&gt;
&lt;br /&gt;
[[category: Lua]]&lt;/div&gt;</summary>
		<author><name>Autowar</name></author>
	</entry>
	<entry>
		<id>https://springrts-wiki.p2004a.com/mediawiki/index.php?title=Lua_CMDs&amp;diff=11169</id>
		<title>Lua CMDs</title>
		<link rel="alternate" type="text/html" href="https://springrts-wiki.p2004a.com/mediawiki/index.php?title=Lua_CMDs&amp;diff=11169"/>
		<updated>2015-09-25T05:09:17Z</updated>

		<summary type="html">&lt;p&gt;Autowar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Engine_Development|Development]] &amp;lt; [[Lua_Scripting|Lua Scripting]] &amp;lt; {{FULLPAGENAME}}&lt;br /&gt;
&lt;br /&gt;
== Options ==&lt;br /&gt;
&amp;lt;b id=CMD.OPT_ALT&amp;gt;CMD.OPT_ALT&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_CTRL&amp;gt;CMD.OPT_CTRL&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_SHIFT&amp;gt;CMD.OPT_SHIFT&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_RIGHT&amp;gt;CMD.OPT_RIGHT&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_INTERNAL&amp;gt;CMD.OPT_INTERNAL&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.OPT_META&amp;gt;CMD.OPT_META&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Waitcodes ==&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_TIME&amp;gt;CMD.WAITCODE_TIME&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_DEATH&amp;gt;CMD.WAITCODE_DEATH&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_SQUAD&amp;gt;CMD.WAITCODE_SQUAD&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.WAITCODE_GATHER&amp;gt;CMD.WAITCODE_GATHER&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Insert/Remove Commands ==&lt;br /&gt;
To get the commandqueue use the following lua-call&lt;br /&gt;
&lt;br /&gt;
=== CommandQueues ===&lt;br /&gt;
&#039;&#039;&#039;Spring.GetUnitCommands&#039;&#039;&#039; &amp;lt;br/&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Spring.GetCommandQueue&#039;&#039;&#039; &amp;lt;span class=&amp;quot;note&amp;quot;&amp;gt;(Alias)&amp;lt;/span&amp;gt;&lt;br /&gt;
  ( number unitID, number count = 0 ) -&amp;gt; nil | number commandQueueSize {{new|96}}&lt;br /&gt;
  ( number unitID [, number count = -1] ) &lt;br /&gt;
  -&amp;gt; nil | table commandQueueTable = {&lt;br /&gt;
     [1] = {&lt;br /&gt;
       &amp;quot;id&amp;quot;      = number,&lt;br /&gt;
       &amp;quot;params&amp;quot;  = { [1] = number, ...},&lt;br /&gt;
       &amp;quot;options&amp;quot; = {&lt;br /&gt;
         &amp;quot;coded&amp;quot;    = number,&lt;br /&gt;
         &amp;quot;alt&amp;quot;      = boolean,&lt;br /&gt;
         &amp;quot;ctrl&amp;quot;     = boolean,&lt;br /&gt;
         &amp;quot;shift&amp;quot;    = boolean,&lt;br /&gt;
         &amp;quot;right&amp;quot;    = boolean,&lt;br /&gt;
         &amp;quot;internal&amp;quot; = boolean,&lt;br /&gt;
         &amp;quot;meta&amp;quot;    = boolean&lt;br /&gt;
       }&lt;br /&gt;
     }, ...&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=note&amp;gt;First, said &amp;quot;tags&amp;quot; aka &amp;quot;id&amp;quot; are unique command identifiers, so each command that gets inserted into a unit&#039;s command &lt;br /&gt;
queue gets its unique &amp;quot;tag&amp;quot; number. (It is used to &#039;&#039;sync&#039;&#039; command queue operations, also it makes things much easier.)&lt;br /&gt;
Editors Note: I fucking hate it when open source devs use the word easy. It is a clear indicator that someone spends a whole day finding out about a well hidden simple concept. Well at least we are on this journey together :)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
To look at those &amp;quot;tags&amp;quot; you can do the following:&lt;br /&gt;
   local cmdQueue = Spring.GetUnitCommands(unitID);&lt;br /&gt;
   if (#cmdQueue&amp;gt;0) then &lt;br /&gt;
      local cmdTag = cmdQueue[1].tag&lt;br /&gt;
      Spring.Echo(cmdTag)&lt;br /&gt;
      ..&lt;br /&gt;
   end&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMD.INSERT&amp;gt;CMD.INSERT&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  options.ALT     -&amp;gt; treat param0 as a position instead of a tag &lt;br /&gt;
  options.CONTROL -&amp;gt; use the build queue for factories &lt;br /&gt;
  params[0] = command tag or position (negative numbers to reference&lt;br /&gt;
  the back of the queue and 0 the first)&lt;br /&gt;
  params[1] = insertCmd id &lt;br /&gt;
  params[2] = insertCmd options (shift,alt,right click,etc.)&lt;br /&gt;
  params[3 ... N+2] = insertCmd params[0 ... N-1]&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;example:&lt;br /&gt;
    Spring.GiveOrderToUnit(unitID,&lt;br /&gt;
      CMD.INSERT,&lt;br /&gt;
      {-1,CMD.ATTACK,&#039;&#039;CMD.OPT_SHIFT&#039;&#039;,&#039;&#039;unitID2&#039;&#039;},&lt;br /&gt;
      {&amp;quot;alt&amp;quot;}&lt;br /&gt;
    );&lt;br /&gt;
	Command structure dissection:&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;What to do with the command - in our case insert:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;CMD.INSERT&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;Place in the queue to insert:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;-1&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;Type of command to insert:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;CMD.ATTACK&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;Additional Information:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
	If the unit is working down a shift queue, add it seemless into it&lt;br /&gt;
&lt;br /&gt;
		&#039;CMD.OPT_SHIFT&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;TargetID or Position:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;unitID2&#039;&lt;br /&gt;
&lt;br /&gt;
	&#039;&#039;&#039;The &#039;-1&#039; is the queue position and not a tag:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
		&#039;{&amp;quot;alt&amp;quot;}&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if you insert cmd in pos 2 for example the rest of commands starting&lt;br /&gt;
  from 2 will be pushed back. &lt;br /&gt;
  Ilustration: {cmdA, cmdB, cmdC, cmdD} =&amp;gt; {cmdA, cmdB, NewCmd, cmdC, cmdD}&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;
  Note: If you didn&#039;t already notice, the command params and&lt;br /&gt;
        the command options are twisted in the array (compared to GiveOrder)!&lt;br /&gt;
  &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;
  Note2: The command options in the array/table is a number value!&lt;br /&gt;
         You have to use CMD.OPT_* in this case.&lt;br /&gt;
  &amp;lt;/font&amp;gt;&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;&lt;br /&gt;
  Note3: The inserted command doesn&#039;t go through allowcommand callins, only CMD.INSERT does.&lt;br /&gt;
  &amp;lt;/font&amp;gt;&lt;br /&gt;
&amp;lt;b id=CMD.REMOVE&amp;gt;CMD.REMOVE&amp;lt;/b&amp;gt;&lt;br /&gt;
  options.ALT     -&amp;gt; use the parameters as commandIDs &lt;br /&gt;
  options.CONTROL -&amp;gt; use the build queue for factories &lt;br /&gt;
  params[0 ... N-1] = tags or commandIDs to remove&lt;br /&gt;
&lt;br /&gt;
No clues what the above mean translated, but here is a working example of how to delete a buildorder from a factory:  &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;     &lt;br /&gt;
 local facCmds = Spring.GetFactoryCommands(factoryID)&lt;br /&gt;
 &lt;br /&gt;
      if facCmds then -- nil check&lt;br /&gt;
		local cmd = facCmds[1]&lt;br /&gt;
         Spring.GiveOrderToUnit(factoryID, CMD.REMOVE, {i,cmd.tag}, {&amp;quot;ctrl&amp;quot;})&lt;br /&gt;
&lt;br /&gt;
      end&lt;br /&gt;
 &amp;lt;/font color=&amp;quot;#55ee99&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Commands ==&lt;br /&gt;
&amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Note, the CMD[] table is bidirectional. That means: CMD[CMD.STOP] := &amp;quot;CMD_STOP&amp;quot;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMD.STOP&amp;gt;CMD.STOP&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.WAIT&amp;gt;CMD.WAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.TIMEWAIT&amp;gt;CMD.TIMEWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.NUMBER|CMDTYPE.NUMBER]]&lt;br /&gt;
&amp;lt;b id=CMD.DEATHWAIT&amp;gt;CMD.DEATHWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_RECTANGLE|CMDTYPE.ICON_UNIT_OR_RECTANGLE]]&lt;br /&gt;
&amp;lt;b id=CMD.SQUADWAIT&amp;gt;CMD.SQUADWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.NUMBER|CMDTYPE.NUMBER]]&lt;br /&gt;
&amp;lt;b id=CMD.GATHERWAIT&amp;gt;CMD.GATHERWAIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.MOVE&amp;gt;CMD.MOVE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.PATROL&amp;gt;CMD.PATROL&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.FIGHT&amp;gt;CMD.FIGHT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.ATTACK&amp;gt;CMD.ATTACK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_MAP|CMDTYPE.ICON_UNIT_OR_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.AREA_ATTACK&amp;gt;CMD.AREA_ATTACK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_AREA|CMDTYPE.ICON_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.GUARD&amp;gt;CMD.GUARD&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT|CMDTYPE.ICON_UNIT]]&lt;br /&gt;
&amp;lt;b id=CMD.AISELECT&amp;gt;CMD.AISELECT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.COMBO_BOX|CMDTYPE.COMBO_BOX]]&lt;br /&gt;
&amp;lt;b id=CMD.GROUPSELECT&amp;gt;CMD.GROUPSELECT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.GROUPADD&amp;gt;CMD.GROUPADD&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.GROUPCLEAR&amp;gt;CMD.GROUPCLEAR&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.REPAIR&amp;gt;CMD.REPAIR&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.FIRE_STATE&amp;gt;CMD.FIRE_STATE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.MOVE_STATE&amp;gt;CMD.MOVE_STATE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.SELFD&amp;gt;CMD.SELFD&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.LOAD_UNITS&amp;gt;CMD.LOAD_UNITS&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.LOAD_ONTO&amp;gt;CMD.LOAD_ONTO&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT|CMDTYPE.ICON_UNIT]]&lt;br /&gt;
&amp;lt;b id=CMD.UNLOAD_UNITS&amp;gt;CMD.UNLOAD_UNITS&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.UNLOAD_UNIT&amp;gt;CMD.UNLOAD_UNIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.ONOFF&amp;gt;CMD.ONOFF&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.RECLAIM&amp;gt;CMD.RECLAIM&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_FEATURE_OR_AREA|CMDTYPE.ICON_UNIT_FEATURE_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.CLOAK&amp;gt;CMD.CLOAK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.STOCKPILE&amp;gt;CMD.STOCKPILE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON|CMDTYPE.ICON]]&lt;br /&gt;
&amp;lt;b id=CMD.DGUN&amp;gt;CMD.DGUN&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MAP|CMDTYPE.ICON_MAP]]&lt;br /&gt;
&amp;lt;b id=CMD.RESTORE&amp;gt;CMD.RESTORE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_AREA|CMDTYPE.ICON_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.REPEAT&amp;gt;CMD.REPEAT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.TRAJECTORY&amp;gt;CMD.TRAJECTORY&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.RESURRECT&amp;gt;CMD.RESURRECT&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_FEATURE_OR_AREA|CMDTYPE.ICON_UNIT_FEATURE_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.CAPTURE&amp;gt;CMD.CAPTURE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_UNIT_OR_AREA|CMDTYPE.ICON_UNIT_OR_AREA]]&lt;br /&gt;
&amp;lt;b id=CMD.AUTOREPAIRLEVEL&amp;gt;CMD.AUTOREPAIRLEVEL&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.LOOPBACKATTACK&amp;gt;CMD.LOOPBACKATTACK&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.IDLEMODE&amp;gt;CMD.IDLEMODE&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.ICON_MODE|CMDTYPE.ICON_MODE]]&lt;br /&gt;
&amp;lt;b id=CMD.SET_WANTED_MAX_SPEED&amp;gt;CMD.SET_WANTED_MAX_SPEED&amp;lt;/b&amp;gt;&lt;br /&gt;
  type [[Lua_CMDs#CMDTYPE.NUMBER|CMDTYPE.NUMBER]]&lt;br /&gt;
&amp;lt;b id=CMD.SETBASE&amp;gt;CMD.SETBASE&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMD.INTERNAL&amp;gt;CMD.INTERNAL&amp;lt;/b&amp;gt;&lt;br /&gt;
  used in different ways&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;A negative number means build command&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The number is -unitDefID of the unittype that this command orders to be built.&lt;br /&gt;
   This means that build orders have no convenient CMD._____ string.&lt;br /&gt;
      The command id for build orders must always be a &amp;quot;minus&amp;quot; sign &amp;lt;i&amp;gt;appended to an integer value&amp;lt;/i&amp;gt;.&lt;br /&gt;
   &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Spring.GiveOrderToUnit(unitID, &amp;lt;b&amp;gt;-(unitDefID)&amp;lt;/b&amp;gt;, {x,y,z(,facing)}, {&amp;quot;shift&amp;quot;})&amp;lt;/font&amp;gt;&lt;br /&gt;
      alternatively:&lt;br /&gt;
   &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Spring.GiveOrderToUnit(unitID, &amp;lt;b&amp;gt;-UnitDefNames[&amp;quot;unitname&amp;quot;].id&amp;lt;/b&amp;gt;, {x,y,z(,facing)}, {&amp;quot;shift&amp;quot;})&amp;lt;/font&amp;gt;&lt;br /&gt;
     &amp;lt;b&amp;gt;&#039;facing&#039;&amp;lt;/b&amp;gt; is an integer parameter that controls unit&#039;s facing when placed.&lt;br /&gt;
&lt;br /&gt;
== CommandTypes ==&lt;br /&gt;
&amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;Note, the CMDTYPE[] table is bidirectional. That means: CMDTYPE[CMDTYPE.ICON] := &amp;quot;CMDTYPE_ICON&amp;quot;&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON&amp;gt;CMDTYPE.ICON&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 0 parameters in return&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_MODE&amp;gt;CMDTYPE.ICON_MODE&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (number selected mode)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_MAP&amp;gt;CMDTYPE.ICON_MAP&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 3 parameters in return (mappos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_AREA&amp;gt;CMDTYPE.ICON_AREA&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 4 parameters in return (mappos+radius)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT&amp;gt;CMDTYPE.ICON_UNIT&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameters in return (unitid)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_OR_MAP&amp;gt;CMDTYPE.ICON_UNIT_OR_MAP&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameters in return (unitid) or 3 parameters in return (mappos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_FRONT&amp;gt;CMDTYPE.ICON_FRONT&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 3 or 6 parameters in return (middle and right side of front if a front was defined)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.COMBO_BOX&amp;gt;CMDTYPE.COMBO_BOX&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (number selected option)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_OR_AREA&amp;gt;CMDTYPE.ICON_UNIT_OR_AREA&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (unitid) or 4 parameters in return (mappos+radius)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_FEATURE_OR_AREA&amp;gt;CMDTYPE.ICON_UNIT_FEATURE_OR_AREA&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (unitid or [[Lua_ConstGame#Engine|Game.maxUnits]]+featureid)&lt;br /&gt;
      or 4 parameters in return (mappos+radius)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_BUILDING&amp;gt;CMDTYPE.ICON_BUILDING&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 3 parameters in return (mappos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.ICON_UNIT_OR_RECTANGLE&amp;gt;CMDTYPE.ICON_UNIT_OR_RECTANGLE&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (unitid)&lt;br /&gt;
      or 3 parameters in return (mappos)&lt;br /&gt;
      or 6 parameters in return (startpos+endpos)&lt;br /&gt;
&amp;lt;b id=CMDTYPE.NUMBER&amp;gt;CMDTYPE.NUMBER&amp;lt;/b&amp;gt;&lt;br /&gt;
  expect 1 parameter in return (number)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b id=CMDTYPE.CUSTOM&amp;gt;CMDTYPE.CUSTOM&amp;lt;/b&amp;gt;&lt;br /&gt;
  used with CMD_INTERNAL&lt;br /&gt;
&amp;lt;b id=CMDTYPE.NEXT&amp;gt;CMDTYPE.NEXT&amp;lt;/b&amp;gt; &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;next command page&amp;lt;/font&amp;gt;&lt;br /&gt;
  used with CMD_INTERNAL&lt;br /&gt;
&amp;lt;b id=CMDTYPE.PREV&amp;gt;CMDTYPE.PREV&amp;lt;/b&amp;gt; &amp;lt;font color=&amp;quot;#55ee99&amp;quot;&amp;gt;previous command page&amp;lt;/font&amp;gt;&lt;br /&gt;
  used with CMD_INTERNAL&lt;br /&gt;
&lt;br /&gt;
[[category: Lua]]&lt;/div&gt;</summary>
		<author><name>Autowar</name></author>
	</entry>
	<entry>
		<id>https://springrts-wiki.p2004a.com/mediawiki/index.php?title=Animation-LuaCallins&amp;diff=1997</id>
		<title>Animation-LuaCallins</title>
		<link rel="alternate" type="text/html" href="https://springrts-wiki.p2004a.com/mediawiki/index.php?title=Animation-LuaCallins&amp;diff=1997"/>
		<updated>2015-01-14T03:50:08Z</updated>

		<summary type="html">&lt;p&gt;Autowar: To reduce visual confusion for newbies researching scripts,  &amp;quot;script.&amp;quot; has been added to the beginning of every callin to reflect actual usage in-code.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Call-ins are calls from the engine, into the unit script. In other words, these functions are called, if they are defined, when a particular â€œeventâ€ happens.&lt;br /&gt;
&lt;br /&gt;
For Lua unit scripts, a new callin mechanism has been implemented, which is faster than the regular callin mechanism which is used for widgets and gadgets.&lt;br /&gt;
&lt;br /&gt;
Types for arguments are only shown where they&#039;re ambiguous. For a number of (common) arguments, the types are:&lt;br /&gt;
&lt;br /&gt;
* unitID: number&lt;br /&gt;
* piece: number&lt;br /&gt;
* axis: number (1 = x axis, 2 = y axis, 3 = z axis)&lt;br /&gt;
* heading/pitch: number (radians)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Generic ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.Create&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
This is called just after the unit script has been created.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.StartMoving&#039;&#039;&#039; ( ) -&amp;gt; nil&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.StopMoving&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
These are called whenever the unit starts or stops moving. Typical use for them is to trigger wheels to start spinning, animate treads, or start/stop a walking animation. Since 95.0 they are only run when a unit transitions from zero to non-zero speed or vice versa, and no longer during in-place rotations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.Killed&#039;&#039;&#039; ( number recentDamage, number maxHealth ) -&amp;gt; number corpseType&lt;br /&gt;
&lt;br /&gt;
This is called when the unit is killed. The severity of the kill may be calculated as severity=recentDamage/maxHealth &#039;&#039;(*100 so that it&#039;s in percent, no? at least that is how severity was expressed in Cob/bos, I think. Of course there&#039;s no reason to emulate that, just pointing it out for people &amp;quot;converting&amp;quot;)&#039;&#039;. Typically, this function would play a death animation for the unit, and finally return a corpse type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.WindChanged&#039;&#039;&#039; ( number heading, number strength ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
This is called for wind generators whenever the wind direction or strength changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.ExtractionRateChanged&#039;&#039;&#039; ( number rate ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Called for metal extractors each time their extraction rate (metal per second) changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.setSFXoccupy&#039;&#039;&#039; ( number curTerrainType ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Called when terrain type changes. Terrain type is calculated with the following rules (in this order):&lt;br /&gt;
&lt;br /&gt;
* If unit is being transported -&amp;gt; curTerrainType = 0&lt;br /&gt;
* If ground height &amp;lt; -5 and unit is always upright -&amp;gt; curTerrainType = 2&lt;br /&gt;
* If ground height &amp;lt; -5 and unit is not always upright -&amp;gt; curTerrainType = 1&lt;br /&gt;
* If ground height &amp;lt; 0 and unit is always upright -&amp;gt; curTerrainType = 1&lt;br /&gt;
* Otherwise -&amp;gt; curTerrainType = 4&lt;br /&gt;
&lt;br /&gt;
Where is curTerrainType = 3 ? :-)&lt;br /&gt;
&lt;br /&gt;
Candidate to be changed to something saner later on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.MoveRate&#039;&#039;&#039; ( number curRate ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Called only for certain types of aircraft (those which use &#039;&#039;CTAAirMoveType&#039;&#039;.) The move rate is determined by the following rules (in this order):&lt;br /&gt;
&lt;br /&gt;
* If the aircraft is landing or taking off -&amp;gt; curRate = 1&lt;br /&gt;
* Otherwise -&amp;gt; curRate = floor(curSpeed / maxSpeed * 3), clamped to be in the range [0, 2]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.QueryLandingPads&#039;&#039;&#039; ( ) -&amp;gt; { number piece1, number piece2, ... }&lt;br /&gt;
&lt;br /&gt;
Called one time for units with landing pads. Should return a table with pieces which should be used as landing pads. The number of pieces returned also determines the number of pads, so for Lua unit scripts there is no QueryLandingPadCount.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.Activate&#039;&#039;&#039; ( ) -&amp;gt; nil&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.Deactivate&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Exact situation these are called depends a lot on the unit type. Factories are activated when they open their yard and deactivated when they close it. Aircraft are activated when they take off and deactivated when the land. Any unit that can be turned on or off is activated when it&#039;s turned on and deactivated when it&#039;s turned off. On &#039;&#039;script.SetUnitValue(COB.ACTIVATION, ...)&#039;&#039; one of these call-ins may be called too.&lt;br /&gt;
&lt;br /&gt;
== Weapons ==&lt;br /&gt;
&lt;br /&gt;
Weapon functions come in two variants.&lt;br /&gt;
&lt;br /&gt;
* Separate function with numeric weapon number suffix. (e.g. &#039;&#039;script.AimWeapon&amp;lt;u&amp;gt;1&amp;lt;/u&amp;gt;(heading, pitch)&#039;&#039;)&lt;br /&gt;
* Combined function which gets weapon number as second argument. (e.g. &#039;&#039;script.AimWeapon(&amp;lt;u&amp;gt;weaponNum&amp;lt;/u&amp;gt;, heading, pitch)&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
Only the first variant is listed here, so whenever you see a function whose name ends with a numeric one (&amp;quot;1&amp;quot;), you should either replace it with the actual weapon number, or you can write a single combined function that takes a &#039;&#039;weaponNum&#039;&#039; argument. For each script, all functions should use the same variant. Either all using name suffix, or all using combined functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.QueryWeapon1&#039;&#039;&#039; ( ) -&amp;gt; number piece&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.AimFromWeapon1&#039;&#039;&#039; ( ) -&amp;gt; number piece&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.AimWeapon1&#039;&#039;&#039; ( heading, pitch ) -&amp;gt; boolean&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.AimShield1&#039;&#039;&#039; ( ) -&amp;gt; boolean&lt;br /&gt;
&lt;br /&gt;
Weapon support. The return value of QueryWeapon and AimFromWeapon determines the pieces which will be used for aiming: typically e.g. the barrel for QueryWeapon and the turret for AimFromWeapon. AimWeapon is then called to allow the script to turn the weapons in the target direction, which is passed as the heading and pitch argument (in radians). Only if AimWeapon returns true, the weapon is actually fired.&lt;br /&gt;
&lt;br /&gt;
TODO: better explanation (?), note about AimWeapon being called very often etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.FireWeapon1&#039;&#039;&#039; ( ) -&amp;gt; nil&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.Shot1&#039;&#039;&#039; ( ) -&amp;gt; nil&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.EndBurst1&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
If after aiming the unit actually fires it&#039;s weapon, FireWeapon is called once at the beginning of the salvo. Shot is called just before each projectile is fired. RockUnit (see below) is called just after all projectiles for that frame have been fired. At the end of the salvo, EndBurst is called.&lt;br /&gt;
&lt;br /&gt;
Of these call-ins, FireWeapon is the more generic one and Shot and EndBurst are more specialized. FireWeapon is usually used to play a recoil animation or emit some smoke near the weapon&#039;s barrel using EmitSfx.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.BlockShot1&#039;&#039;&#039; ( targetUnitID, boolean userTarget ) -&amp;gt; boolean&lt;br /&gt;
&lt;br /&gt;
Allows you to block a weapon from shooting. TargetUnitID may be nil: in this case the unit has a ground-attack order.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.TargetWeight1&#039;&#039;&#039; ( targetUnitID ) -&amp;gt; number&lt;br /&gt;
&lt;br /&gt;
Allows you to tweak the priority of the target for this particular weapon. The target priority is multiplied by the return value of this function. Lower priority targets are targeted first, so return a value smaller than 1 to prioritize a target, or return a value larger than 1 to avoid a target.&lt;br /&gt;
&lt;br /&gt;
The exact behavior of specific values shouldn&#039;t be relied upon.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.RockUnit&#039;&#039;&#039; ( x, z ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
A bit like the weapon-specific FireWeapon function, although this is called after any weapon fires. As argument it gets a two dimensional vector in the direction the unit just fired. This may be used to â€œrockâ€ the unit as a whole a bit as part of the firing animation. Note though that this vector is in world space, so for a truly realistic rock direction it needs to be rotated according to the unit&#039;s current heading.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.HitByWeapon&#039;&#039;&#039; ( x, z, weaponDefID, damage ) -&amp;gt; nil | number newDamage&lt;br /&gt;
&lt;br /&gt;
This is called if a unit has been hit by a weapon. (x, z) is the direction from which the projectile came in unit space (the reverse direction of the impulse, to be exact.) It also gets the weaponDefID of the weapon which is dealing the damage, and the amount of damage. If HitByWeapon returns a number, this number will replace the damage value calculated by the engine.&lt;br /&gt;
&lt;br /&gt;
Note: Pre Spring 95, this call-in runs just before the LuaRules UnitPreDamaged callin (see also [[LuaCallinReturn]]). If HitByWeapon overrides the damage, UnitPreDamaged will see the new damage value, and may override again the damage value. Starting Spring 95, it is run after UnitPreDamaged.&lt;br /&gt;
&lt;br /&gt;
== Builders and factories ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.StartBuilding&#039;&#039;&#039; ( heading, pitch ) -&amp;gt; nil&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.StartBuilding&#039;&#039;&#039; ( ) -&amp;gt; nil&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.StopBuilding&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
These notify the script when a builder or factory starts or stops building.&lt;br /&gt;
&lt;br /&gt;
The first variant (with heading and pitch arguments) is called for builders. For factories, the second variant is used. In this case the heading and pitch are not necessary, because the factory script specifies the build location itself using QueryBuildInfo.&lt;br /&gt;
&lt;br /&gt;
BTW, don&#039;t forget to set INBUILDSTANCE to 1 to start building! For lua script, that is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
  function script.StartBuilding(heading, pitch)&lt;br /&gt;
&lt;br /&gt;
    SetUnitValue(COB.INBUILDSTANCE, 1)&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  function script.StopBuilding()&lt;br /&gt;
    SetUnitValue(COB.INBUILDSTANCE, 0)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.QueryBuildInfo&#039;&#039;&#039; ( ) -&amp;gt; number piece&lt;br /&gt;
&lt;br /&gt;
For factories only. Should return the piece to which the unit which is going to be build will be attached while it&#039;s being build.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.QueryNanopiece&#039;&#039;&#039; ( ) -&amp;gt; number piece&lt;br /&gt;
&lt;br /&gt;
Called each time a nano particle is to be created. Should return the piece at which the particle will be spawned. This may be used to iterate through a few pieces, to simulate the factory/builder having multiple nanolathes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;note&amp;quot;&amp;gt;N.B. As of 92.0 the results are cached and the function is called 31 times only. Deprecated in favour of Spring.SetUnitNanoPieces, which disables this callin when used.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Transports ==&lt;br /&gt;
&lt;br /&gt;
There are some different code paths inside Spring related to transports, each (unfortunately) also associated with a different set of unit script call-ins.&lt;br /&gt;
&lt;br /&gt;
This table shows for the three different transportUnloadMethods for both air transports and ground transports which callins are used and roughly when and how often they are called. Refer to the documentation below for a description of the call-ins.&lt;br /&gt;
&lt;br /&gt;
The entire behavior around transports should be considered subject to change; it is obvious it is far from a perfect design currently.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; style=&amp;quot;border-spacing:0px;&amp;quot;&lt;br /&gt;
|+&lt;br /&gt;
!&lt;br /&gt;
!Load&lt;br /&gt;
!UnloadLand (0)&lt;br /&gt;
!UnloadDrop (1)&lt;br /&gt;
!UnloadLandFlood (2)&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|default unload&lt;br /&gt;
|fly over and drop unit&lt;br /&gt;
|land, then release all units at once&lt;br /&gt;
|-&lt;br /&gt;
|air&lt;br /&gt;
|BeginTransport (each)&amp;lt;br&amp;gt;QueryTransport (each)&lt;br /&gt;
|EndTransport (last)&lt;br /&gt;
|EndTransport (each)&lt;br /&gt;
|StartUnload (first)&amp;lt;br&amp;gt;TransportDrop (each)&amp;lt;br&amp;gt;EndTransport (last)&lt;br /&gt;
|-&lt;br /&gt;
|ground&lt;br /&gt;
|TransportPickup (each)&lt;br /&gt;
|TransportDrop (each)&lt;br /&gt;
|TransportDrop (each)&lt;br /&gt;
|TransportDrop (each)&amp;lt;br&amp;gt;EndTransport (last)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Air transports ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.BeginTransport&#039;&#039;&#039; ( passengerID ) -&amp;gt; nil&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.QueryTransport&#039;&#039;&#039; ( passengerID ) -&amp;gt; number piece&lt;br /&gt;
&lt;br /&gt;
For an air transport, if any one unit is picked up, these two are called in succession and the passenger is attached to the piece returned by the second one.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.StartUnload&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Only called in UnloadLandFlood behavior. Signals the start of an unload cycle.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.TransportDrop&#039;&#039;&#039; ( passengerID, x, y, z ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Only called in UnloadLandFlood behavior. Called when a passenger will be unloaded. Contrary to ground transports, Spring will detach the passenger after the call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.EndTransport&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
In UnloadLand and UnloadLandFlood behaviors, these are called one time after all units are unloaded. (The transport is empty.) For the UnloadDrop behavior, this is called for every unit that is unloaded.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Ground transports ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.TransportPickup&#039;&#039;&#039; ( passengerID ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Called when a passenger should be loaded into the transport. This should eventually call AttachUnit to actually attach the unit. Assuming the transport is in range of the next passenger, this will be called again for the next passenger 16 frames later, &#039;&#039;unless&#039;&#039; the script enters the BUSY state: then Spring will not move on to the next passenger until the script leaves the BUSY state.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.TransportDrop&#039;&#039;&#039; ( passengerID, x, y, z ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Called when a passenger should be unloaded. This should eventually call DetachUnit to actually detach the unit, &#039;&#039;unless&#039;&#039; the used unload method is UnloadLandFlood, in which case Spring will actually detach the unit after the call.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.EndTransport&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Only called in UnloadLandFlood behavior, after the last unit has been unloaded.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Passenger ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.Falling&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
For a unit dropped from an UnloadDrop transport, this is called every frame to inform the script the unit is still falling. It may be used to show a parachute for example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.Landed&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
This is called one time after the unit reached the ground. May be used to hide a parachute for example.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Internal ==&lt;br /&gt;
&lt;br /&gt;
These call-ins are NOT available to Lua unit scripts. They are called by the engine however, but always &#039;intercepted&#039; by the framework gadget. For completeness (or if you are poking at the gadget), they are listed here anyway.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.MoveFinished&#039;&#039;&#039; ( piece, axis ) -&amp;gt; nil&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;script.TurnFinished&#039;&#039;&#039; ( piece, axis ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Called when a move or turn finished. The framework gadget uses this to resume the coroutines which are waiting for the particular move or turn to be finished.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;script.Destroy&#039;&#039;&#039; ( ) -&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
Called right before the unit&#039;s script is destroyed. This may happen if the unit is being destroyed, but also if the unit&#039;s script is being replaced by another script. The framework gadget uses this to stop all threads and remove the unit from some internal data structures.&lt;br /&gt;
&lt;br /&gt;
[[Category:Animation]]&lt;br /&gt;
[[Category:Lua]]&lt;/div&gt;</summary>
		<author><name>Autowar</name></author>
	</entry>
</feed>