diff --git a/luaui/Widgets/unit_immobile_builder.lua b/luaui/Widgets/unit_immobile_builder.lua index 7c9e449cf2..6efb246856 100644 --- a/luaui/Widgets/unit_immobile_builder.lua +++ b/luaui/Widgets/unit_immobile_builder.lua @@ -34,6 +34,7 @@ local spGetUnitPosition = Spring.GetUnitPosition local spGiveOrderToUnit = Spring.GiveOrderToUnit local spGetCommandQueue = Spring.GetCommandQueue local spGetSpectatingState = Spring.GetSpectatingState +local spGetUnitCurrentCommand = Spring.GetUnitCurrentCommand local hmsx = Game.mapSizeX/2 local hmsz = Game.mapSizeZ/2 @@ -132,10 +133,13 @@ end function widget:UnitCommand(unitID, unitDefID, _, cmdID, _, cmdOpts) if isImmobileBuilder[unitDefID] and cmdOpts.shift and cmdID ~= CMD_FIGHT then - local commandQueue = spGetCommandQueue(unitID, -1) - local lastCommand = commandQueue[#commandQueue] - if lastCommand and lastCommand.id == CMD_FIGHT then - spGiveOrderToUnit(unitID, CMD.REMOVE, { lastCommand.tag }, 0) + local count = spGetCommandQueue(unitID, 0) + if count == 0 then + return + end + local cmdID, opts, tag = spGetUnitCurrentCommand(unitID, count) + if cmdID and cmdID == CMD_FIGHT then + spGiveOrderToUnit(unitID, CMD.REMOVE, { tag }, 0) end end end