Now, do I need to manually recreate the arrays and if so, is there code to do that already?
Yes, and yes.
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
For Factories, it's a little different:
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