Load/Unload units via LUA

Load/Unload units via LUA

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
daryl
Posts: 192
Joined: 08 Oct 2006, 10:33

Load/Unload units via LUA

Post 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?
User avatar
Silentwings
Moderator
Posts: 3695
Joined: 25 Oct 2008, 00:23

Re: Load/Unload units via LUA

Post 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.
User avatar
daryl
Posts: 192
Joined: 08 Oct 2006, 10:33

Re: Load/Unload units via LUA

Post 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}, {})
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10378
Joined: 24 Jan 2006, 21:12

Re: Load/Unload units via LUA

Post 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
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6238
Joined: 29 Apr 2005, 01:14

Re: Load/Unload units via LUA

Post by FLOZi »

To improve your coding style and avoid such confusion:

Code: Select all

local comID = Spring.CreateUnit(etc...)
User avatar
daryl
Posts: 192
Joined: 08 Oct 2006, 10:33

Re: Load/Unload units via LUA

Post 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??
User avatar
Silentwings
Moderator
Posts: 3695
Joined: 25 Oct 2008, 00:23

Re: Load/Unload units via LUA

Post 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.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10378
Joined: 24 Jan 2006, 21:12

Re: Load/Unload units via LUA

Post by PicassoCT »

But the gate is up.. and the battles are Enderendian
User avatar
daryl
Posts: 192
Joined: 08 Oct 2006, 10:33

Re: Load/Unload units via LUA

Post 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!!!
Post Reply

Return to “Lua Scripts”