Author Topic: How do I position units via lua  (Read 1221 times)

ZaRo

  • Guest
How do I position units via lua
« on: 28 October 2009, 11:48:45 »
Hello

Thank you for making this wonderful opensource software!
I'm currently having some small problems with my placement via lua.

Here's my code:

Code: [Select]
<?xml version="1.0" standalone="yes" ?>
<scenario>
<difficulty value="0"/>
<players>
<player control="human" faction="magic" team="1"/>
<player control="cpu" faction="magic" team="2"/>
<player control="closed"/>
<player control="closed"/>
</players>
<map value="amap"/>
<tileset value="forest-klima"/>
<tech-tree value="magitech"/>
<default-resources value="false"/>
<default-units value="true"/>
<default-victory-conditions value="false"/>
<scripts>
<startup>
disableAi(1)
createUnit ( "UNIT", 0, {startLocation(0)[1] - 20, startLocation(0)[1] - 15})
</startup>
</scripts>
</scenario>

My map looks like this:

I would like to have UNIT placed in the space between the trees in the lower right corner of the map. How do I do that? Every time I edit one of the "
Code: [Select]
( "UNIT", 0, {startLocation(0)[1] - [b]20[/b], startLocation(0)[1] - [b]15[/b]}) bold numbers, the UNIT jumps in triangles, instead of up/across as I would expect it to do.

Thanks in advance for your help

Best regards
ZaRo

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: How do I position units via lua
« Reply #1 on: 28 October 2009, 13:15:41 »
Get the latest GAE if you don't have it already.

in glestadv.ini find MiscDebugMode and change it to true.

load up the game with your map, click on the ground somewhere in the gap, take note of the co-ordinates. (on the second row of 'debug' info at the left of the screen)

in Lua, use createUnit( "UNIT", faction, { x, y } )

PS: The reason it was jumping in 'triangles' is because you were using the x co-ordinate of startLocation for both the x and y you calculate, startLocation(0)[1] is the X co-ord, startLocation(0)[2] is the Y coord :)
Glest Advanced Engine - Code Monkey

Timeline | Downloads

ZaRo

  • Guest
Re: How do I position units via lua
« Reply #2 on: 29 October 2009, 12:53:18 »
Thank you for the solution! It worked perfectly :)

Best regards
ZaRo