Page 1 of 1

Detect when user (not script) issues an order to unit(s)

Posted: 12 Feb 2011, 08:56
by SpliFF
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:

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
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 using Spring.GetActiveCommand() widget:CommandNotify()

Re: Detect when user (not script) issues an order to unit(s)

Posted: 12 Feb 2011, 09:01
by CarRepairer
use widget:CommandNotify

Now where's spring-assimp?

Re: Detect when user (not script) issues an order to unit(s)

Posted: 12 Feb 2011, 09:06
by SpliFF
spring-assimp is on hold until more people start showing some interest. There are a few tweaks I was going to do to assist with testing but the number of people testing is disappointingly low. There's been zero feedback except to complain about how the demo is packaged which is pretty much irrelevant to whether the code works.

For that reason I'm working on my own stuff until I need assimp support or people give me enough feedback to justify pushing it into the mainline git repository.

Thanks for the CommandNotify tip, that looks perfect. I had thought it would trigger on GiveOrderToUnit but it doesn't.

Re: Detect when user (not script) issues an order to unit(s)

Posted: 27 Oct 2011, 00:33
by nox
widget:CommandsChanged() is called when left mouse is released i think

Re: Detect when user (not script) issues an order to unit(s)

Posted: 27 Oct 2011, 08:17
by Anarchid
For that reason I'm working on my own stuff until I need assimp support or people give me enough feedback to justify pushing it into the mainline git repository.
Where do i send that? I definitely want assimp and roam in mah spring somewhere early 2012 for my evil plan, as correctly predicted by the Mayan calendar.

Re: Detect when user (not script) issues an order to unit(s)

Posted: 27 Oct 2011, 13:32
by SpliFF
Check the date on my comment, this is an old thread. Assimp is already in the next release.

Re: Detect when user (not script) issues an order to unit(s)

Posted: 27 Oct 2011, 13:39
by Anarchid
Oh. Sorry. I blame the necromancer above.