Detect when user (not script) issues an order to unit(s)
Posted: 12 Feb 2011, 08:56
When a user issues an order to a unit I need to take some actions that I don't take when a script issues an order via Spring.GiveOrderToUnit. At the moment my widget code is:
But this doesn't take into account left-click orders. When the press is registered the unit selection hasn't changed yet so I can't tell if the left-click was an order or a deselect action.
UPDATE: Solved usingSpring.GetActiveCommand() widget:CommandNotify()
Code: Select all
-- Intercept mouse press
function widget:MousePress(x, y, button)
-- allow user to take over unit when issuing an order so unit goals don't interfere with user actions
if button == 3 then -- right mouse
Spring.Echo("Right mouse")
for _, unitID in ipairs(Spring.GetSelectedUnits()) do
if GetUnitGoal(unitID) then
Spring.Echo("Taking over unit "..unitID)
-- cancel goal
RemoveUnitGoal(unitID)
end
SetUnitFlag(unitID, "busy")
end
end
end
UPDATE: Solved using