Code: Select all
function CommandNotify(id, params, options)
-- GUARD + CTRL = copy command queue
if ((id == CMD_GUARD) and options.ctrl) then
targetID = params[1];
queue = Spring.GetCommandQueue(targetID);
if (queue ~= nil) then -- might not be an ally
Spring.GiveOrder( CMD_STOP, {}, {} )
for k,v in ipairs(queue) do -- in order
if (not v.options.internal) then
opts = {}
if (v.options.alt) then table.insert(opts, "alt") end
if (v.options.ctrl) then table.insert(opts, "ctrl") end
if (v.options.shift) then table.insert(opts, "shift") end
if (v.options.right) then table.insert(opts, "right") end
Spring.GiveOrder( v.id, v.params, opts )
end
end
return false -- do not add the original GUARD command
end
end
return true
end
Code: Select all
function SelectedString()
local s = ""
uidTable = Spring.GetSelectedUnits("raw")
uidTable.n = nil -- or use ipairs
for k,v in pairs(uidTable) do
s = s .. ' +' .. v
end
return s
end
function UnitCreated(unitID, unitDefID)
ud = UnitDefs[unitDefID]
if ((ud ~= nil) and (Spring.GetUnitTeam(unitID) == MyTeamID)) then
if (ud.builder and not ud.canMove) then
-- set immobile builders (nanotowers) to the ROAM movestate,
-- and give them a PATROL order (does not matter where, afaict)
selstr = SelectedString()
Spring.SendCommands({ "selectunits clear +" .. unitID })
x, y, z = Spring.GetUnitPosition(unitID)
Spring.GiveOrder( CMD_MOVE_STATE, { 2 }, { } )
Spring.GiveOrder( CMD_PATROL, { x + 25, y, z - 25 }, { } )
Spring.SendCommands({ "selectunits clear" .. selstr })
elseif (ud.isFactory) then
-- give factories a self GUARD pattern for their progeny
selstr = SelectedString()
Spring.SendCommands({ "selectunits clear +" .. unitID })
x, y, z = Spring.GetUnitPosition(unitID)
Spring.GiveOrder( CMD_MOVE, { x + 100, y, z + 100 }, { "shift" } )
Spring.GiveOrder( CMD_MOVE, { x + 100, y, z }, { "shift" } )
Spring.GiveOrder( CMD_GUARD, { unitID }, { "shift" } )
Spring.SendCommands({ "selectunits clear" .. selstr })
end
end
end