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?
Load/Unload units via LUA
Moderator: Moderators
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Load/Unload units via LUA
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.
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
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}, {})
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
Spring.GiveOrderToUnit("atlas", CMD.LOAD_UNITS, {"com"}, {}) should bedaryl wrote:
It's wrong... how can i get the unitID??
Spring.GiveOrderToUnit(transportID, CMD.LOAD_UNITS, {transporteeID}, {})
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
To improve your coding style and avoid such confusion:
Code: Select all
local comID = Spring.CreateUnit(etc...)
Re: Load/Unload units via LUA
PicassoCT wrote:Spring.GiveOrderToUnit("atlas", CMD.LOAD_UNITS, {"com"}, {}) should bedaryl wrote:
It's wrong... how can i get the unitID??
Spring.GiveOrderToUnit(transportID, CMD.LOAD_UNITS, {transporteeID}, {})
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"})
- Silentwings
- Posts: 3720
- Joined: 25 Oct 2008, 00:23
Re: Load/Unload units via LUA
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.
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
But the gate is up.. and the battles are Enderendian
Re: Load/Unload units via LUA
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
you has reason :)
now it work!
thank you very much!!!