Page 1 of 1

Load/Unload units via LUA

Posted: 28 Feb 2016, 09:46
by daryl
Hi all,
i'm making a mission with "mission editor" and I need that a "transporter" load "tank" and unload it at x,y coordinates in the maps.
All of this by Lua code.
I'm sorry but i'm not a coder...and i did't found similar post..
can you help me please?

Re: Load/Unload units via LUA

Posted: 28 Feb 2016, 10:53
by Silentwings
Spring.GiveOrderToUnit(transportID, CMD.LOAD_UNITS, {transporteeID}, {})
Spring.GiveOrderToUnit(transportID, CMD.UNLOAD_UNITS, {x,y,z,radius}, {})

and in general,
https://springrts.com/wiki/Lua_SyncedCtrl#Give_Order
https://springrts.com/wiki/Lua_CMDs

There is also a newer system with Spring.AttachUnit and Spring.DetachUnit, but this system (it needs a gadget) is not used yet by any games afaik.

Re: Load/Unload units via LUA

Posted: 28 Feb 2016, 12:23
by daryl
thx, but can you make to me an example because i'm not a good coder... :(

for example:

-- i created a commander
com=Spring.CreateUnit("icucom",6900,0,11400,0,Spring.GetGaiaTeamID())
Spring.SetUnitNeutral (com, true)
Spring.SetUnitAlwaysVisible(com, true)
Spring.SetUnitNoMinimap(com, true)

-- I created an Atlas (the transporter)
atlas=Spring.CreateUnit("armatlas",6970,0,11470,0,Spring.GetGaiaTeamID())
Spring.SetUnitNeutral (atlas, true)
Spring.SetUnitAlwaysVisible(atlas, true)
Spring.SetUnitNoMinimap(atlas, true)

-- I want that Atlas load commander
Spring.GiveOrderToUnit("atlas", CMD.LOAD_UNITS, {"com"}, {})


It's wrong... how can i get the unitID??
Spring.GiveOrderToUnit(transportID, CMD.LOAD_UNITS, {transporteeID}, {})

Re: Load/Unload units via LUA

Posted: 28 Feb 2016, 13:02
by PicassoCT
daryl wrote:
It's wrong... how can i get the unitID??
Spring.GiveOrderToUnit(transportID, CMD.LOAD_UNITS, {transporteeID}, {})
Spring.GiveOrderToUnit("atlas", CMD.LOAD_UNITS, {"com"}, {}) should be

Spring.GiveOrderToUnit(atlas, CMD.LOAD_UNITS, { com }, {})


"atlas" is the string "atlas"
while atlas is a variable containing the number that is the atlas identifying number

Re: Load/Unload units via LUA

Posted: 28 Feb 2016, 13:48
by FLOZi
To improve your coding style and avoid such confusion:

Code: Select all

local comID = Spring.CreateUnit(etc...)

Re: Load/Unload units via LUA

Posted: 29 Feb 2016, 20:18
by daryl
PicassoCT wrote:
daryl wrote:
It's wrong... how can i get the unitID??
Spring.GiveOrderToUnit(transportID, CMD.LOAD_UNITS, {transporteeID}, {})
Spring.GiveOrderToUnit("atlas", CMD.LOAD_UNITS, {"com"}, {}) should be

Spring.GiveOrderToUnit(atlas, CMD.LOAD_UNITS, { com }, {})


"atlas" is the string "atlas"
while atlas is a variable containing the number that is the atlas identifying number

ok..now atlas load the commander... but don't unload it...
for example I used this code:

Code: Select all

com=Spring.CreateUnit("icucom",6900,0,11400,0,Spring.GetGaiaTeamID())
Spring.SetUnitNeutral (com, true)
Spring.SetUnitAlwaysVisible(com, true)
Spring.SetUnitNoMinimap(com, true)

atlas=Spring.CreateUnit("armatlas",6970,0,11470,0,Spring.GetGaiaTeamID())
Spring.SetUnitNeutral (atlas, true)
Spring.SetUnitAlwaysVisible(atlas, true)
Spring.SetUnitNoMinimap(atlas, true)


Spring.GiveOrderToUnit(atlas, CMD.LOAD_UNITS, { com }, {"shift"})
Spring.GiveOrderToUnit(atlas, CMD.UNLOAD_UNITS, {10,10,0,15}, {"shift"})
where I wrong now??

Re: Load/Unload units via LUA

Posted: 29 Feb 2016, 21:34
by Silentwings
You've asked to unload to x,y,z,r=10,10,0,15, which https://springrts.com/wiki/Lua_CMDs#CMD ... IT_OR_AREA says is a circle of radius r (in the x-z plane) about the point x,y,z.

If you give it some saner values (part of your circle is outside of the map, probably most/all of it is below ground, and its tiny) it might do better. Maybe try x,z=500,500 and y=Spring.GetGroundHeight(x,z) and r=200. It will also need flat ground around there to unload onto.

Btw, in Spring, x is east/west, z is north/south, y is up/down. The top left hand corner of the map is x=0,z=0, and y=0 is the height of the water.

Re: Load/Unload units via LUA

Posted: 29 Feb 2016, 22:14
by PicassoCT
But the gate is up.. and the battles are Enderendian

Re: Load/Unload units via LUA

Posted: 01 Mar 2016, 07:37
by daryl
Silentwings wrote:You've asked to unload to x,y,z,r=10,10,0,15, which https://springrts.com/wiki/Lua_CMDs#CMD ... IT_OR_AREA says is a circle of radius r (in the x-z plane) about the point x,y,z.

If you give it some saner values (part of your circle is outside of the map, probably most/all of it is below ground, and its tiny) it might do better. Maybe try x,z=500,500 and y=Spring.GetGroundHeight(x,z) and r=200. It will also need flat ground around there to unload onto.

Btw, in Spring, x is east/west, z is north/south, y is up/down. The top left hand corner of the map is x=0,z=0, and y=0 is the height of the water.

ops :roll:

you has reason :)

now it work!

thank you very much!!!