Setting unit Active/Passive state

Setting unit Active/Passive state

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

Moderator: Moderators

Post Reply
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Setting unit Active/Passive state

Post by gajop »

How can this be done?
I tried the following, but none of it had any effect:

Code: Select all

            Spring.GiveOrderToUnit(unitId, CMD.INSERT,
                { 0, CMD.ONOFF, 0, boolToNumber(s.active)},
                {"alt"}
            );
            
            Spring.GiveOrderToUnit(unitId, CMD.INSERT,
                { 0, CMD.IDLEMODE, 0, boolToNumber(s.active)},
                {"alt"}
            );
            Spring.SetUnitCOBValue(unitId, COB.ACTIVATION, boolToNumber(s.active))
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Setting unit Active/Passive state

Post by Silentwings »

I didn't check syntax but I would expect the third of those to have worked.

I'm not sure of the relationship inside engine between on/off and active/passive (or even if there is one). I have no idea what CMD.IDLEMODE does and wiki seems not to know either.

If you are testing with BA & constructors, we have a custom CMD.PASSIVE that is implemented with a gadget.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Setting unit Active/Passive state

Post by jK »

1. CMD.IDLEMODE is iirc air landing behavior
2. why use CMD.INSERT to push a cmd to the _front_?
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Setting unit Active/Passive state

Post by gajop »

jK wrote:2. why use CMD.INSERT to push a cmd to the _front_?
I want the existing command queue to remain and only change the state of the unit. Putting it in the front should make sure that happens immediately.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Setting unit Active/Passive state

Post by jK »

shift?
Hint: shift doesn't always append the cmd to the end of the queue, it just makes sure the queue remains. Beside that there are two different types of cmds: state ones and orders. on/off, firestate, repeat, ... are state ones those always executed directly when you give the cmd and are never really added to the queue (in lua point of view it's like processing the cmd in AllowCommand instead of Fallback).
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Setting unit Active/Passive state

Post by gajop »

jK wrote:shift?
Hint: shift doesn't always append the cmd to the end of the queue, it just makes sure the queue remains. Beside that there are two different types of cmds: state ones and orders. on/off, firestate, repeat, ... are state ones those always executed directly when you give the cmd and are never really added to the queue (in lua point of view it's like processing the cmd in AllowCommand instead of Fallback).
Oh, OK, that simplifies things. Will amend the code, thanks.
Post Reply

Return to “Lua Scripts”