-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- -- file: erase_command.lua -- brief: Enable selected units' commands in queue to be erased by -- ctrl+meta+right click -- author: gunblob -- -- Copyright (C) 2008. -- Licensed under the terms of the GNU GPL, v2 or later. -- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- function widget:GetInfo() return { name = "Erase Command", desc = "Enable selected units' commands in queue to be erased by ctrl+meta+right click", author = "gunblob", date = "June 12, 2008", license = "GNU GPL, v2 or later", layer = 0, enabled = false -- loaded by default? } end local closeDistance = 2000 -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- function widget:MousePress(x, y, button) local alt, ctrl, meta, shift = Spring.GetModKeyState() if meta and ctrl and button == 3 then local obj, realCoord = Spring.TraceScreenRay(x,y,true) selUnits = Spring.GetSelectedUnits() local closeCommands = {} for _, unit in ipairs(selUnits) do commandsTable = Spring.GetUnitCommands(unit) for _, command in ipairs(commandsTable) do local tx, ty, tz if command.id ~= 70 and #command.params == 1 then tid = command.params[1] if tid <= 10000 then tx, ty, tz = Spring.GetUnitPosition(tid) else tx, ty, tz = Spring.GetFeaturePosition(tid - 10000) end else tx = command.params[1] ty = command.params[2] tz = command.params[3] end if command.id ~= 70 and tx and ty and tz then local dx, dz dx = tx - realCoord[1] dz = tz - realCoord[3] if dx * dx + dz * dz < closeDistance then table.insert(closeCommands, command.tag) end end end -- commands for _, closeCommand in ipairs(closeCommands) do Spring.GiveOrderToUnit(unit, CMD.REMOVE, {closeCommand}, {}) end end -- units return true end return false end