I'm using
orders = Spring.GetCommandQueue(unitID) -- save
Spring.GiveOrderArrayToUnitArray({unitID}, orders) -- restore
But this gives error "bad command ID". Apparently they use different array formats.
How should this be done?
Saving and restoring command queue
Moderator: Moderators
Re: Saving and restoring command queue
I didn't wrote the wiki for nothing ...
Re: Saving and restoring command queue
Which one? I've been using http://spring.clan-sy.com/wiki/Lua_Scripting but couldn't get good tips there.
- CarRepairer
- Cursed Zero-K Developer
- Posts: 3359
- Joined: 07 Nov 2007, 21:48
Re: Saving and restoring command queue
Actually I think this has something to do with the big red font in this page: http://spring.clan-sy.com/wiki/Lua_CMDs
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Saving and restoring command queue
edit: fuckit, waste of time
Re: Saving and restoring command queue
Now, do I need to manually recreate the arrays and if so, is there code to do that already?
Re: Saving and restoring command queue
Yes, and yes.Now, do I need to manually recreate the arrays and if so, is there code to do that already?
For standard Units, where you just want to mirror command queues from A to B, here's some code.
Wrap it in a function where params a,b are your target(s) unitIDs and the unitID you're copying from, respectively:
Code: Select all
local states = Spring.GetUnitStates(targetID)
if (states ~= nil) then
Spring.GiveOrderToUnit(unitID, CMD.FIRE_STATE, { states.firestate }, 0)
Spring.GiveOrderToUnit(unitID, CMD.MOVE_STATE, { states.movestate }, 0)
Spring.GiveOrderToUnit(unitID, CMD.REPEAT, { states['repeat'] and 1 or 0 }, 0)
Spring.GiveOrderToUnit(unitID, CMD.ONOFF, { states.active and 1 or 0 }, 0)
Spring.GiveOrderToUnit(unitID, CMD.CLOAK, { states.cloak and 1 or 0 }, 0)
Spring.GiveOrderToUnit(unitID, CMD.TRAJECTORY, { states.trajectory and 1 or 0 }, 0)
end
local queue = Spring.GetCommandQueue(targetID);
if (queue ~= nil) then
for k,v in ipairs(queue) do -- in order
local opts = v.options
if (not opts.internal) then
local newopts = {}
if (opts.alt) then table.insert(newopts, "alt") end
if (opts.ctrl) then table.insert(newopts, "ctrl") end
if (opts.right) then table.insert(newopts, "right") end
table.insert(newopts, "shift")
Spring.GiveOrderToUnit(unitID, v.id, v.params, opts.coded)
end
end
end
local buildqueue = Spring.GetRealBuildQueue(targetID)
if (buildqueue ~= nil) then
for udid,buildPair in ipairs(buildqueue) do
local udid, count = next(buildPair, nil)
Spring.AddBuildOrders(unitID, udid, count)
end
end
Code: Select all
local states = Spring.GetUnitStates(targetID)
if (states ~= nil) then
Spring.GiveOrderToUnit(unitID, CMD.FIRE_STATE, { states.firestate }, 0)
Spring.GiveOrderToUnit(unitID, CMD.MOVE_STATE, { states.movestate }, 0)
Spring.GiveOrderToUnit(unitID, CMD.REPEAT, { states['repeat'] and 1 or 0 }, 0)
Spring.GiveOrderToUnit(unitID, CMD.ONOFF, { states.active and 1 or 0 }, 0)
Spring.GiveOrderToUnit(unitID, CMD.CLOAK, { states.cloak and 1 or 0 }, 0)
Spring.GiveOrderToUnit(unitID, CMD.TRAJECTORY, { states.trajectory and 1 or 0 }, 0)
end
local queue = Spring.GetCommandQueue(targetID);
if (queue ~= nil) then
for k,v in ipairs(queue) do -- in order
local opts = v.options
if (not opts.internal) then
local newopts = {}
if (opts.alt) then table.insert(newopts, "alt") end
if (opts.ctrl) then table.insert(newopts, "ctrl") end
if (opts.right) then table.insert(newopts, "right") end
table.insert(newopts, "shift")
Spring.GiveOrderToUnit(unitID, v.id, v.params, opts.coded)
end
end
end
local buildqueue = Spring.GetRealBuildQueue(targetID)
if (buildqueue ~= nil) then
--Spring.Echo("found build orders")
for udid,buildPair in ipairs(buildqueue) do
local udid, count = next(buildPair, buildPair[1])
--Spring.Echo(udid,count)
for x = 1,count,1 do
Spring.GiveOrderToUnit(unitID, -udid, {1}, {""})
end
end
end