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

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

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

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

Post 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()
Last edited by SpliFF on 12 Feb 2011, 09:14, edited 2 times in total.
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

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

Post by CarRepairer »

use widget:CommandNotify

Now where's spring-assimp?
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

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

Post 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.
nox
Posts: 1
Joined: 27 Oct 2011, 00:31

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

Post by nox »

widget:CommandsChanged() is called when left mouse is released i think
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

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

Post 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.
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

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

Post by SpliFF »

Check the date on my comment, this is an old thread. Assimp is already in the next release.
User avatar
Anarchid
Posts: 1384
Joined: 30 Nov 2008, 04:31

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

Post by Anarchid »

Oh. Sorry. I blame the necromancer above.
Post Reply

Return to “Lua Scripts”