Page 1 of 1

Distinguish player commands from Lua commands (AllowCommand)

Posted: 23 Nov 2011, 08:22
by knorke
How can I detect in a gadget if a unit just recieved an order from the player or if was given the order via Lua?
Basically I want:

Code: Select all

AllowCommand (...)
if (this order is given by player) then
...
else
...
end
If I understand correctly, CMD.OPT_INTERNAL can help with that.
But when I do this:

Code: Select all

function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions,cmdTag, synced)
for k,v in pairs (cmdOptions) do
  Spring.Echo (k, v)
end
I only get this:
alt, false
ctrl, false
coded, 16
right, true
meta, false
shift, false
There is no key named "internal" in the cmdOptions table?

This gadget:
http://zero-k.googlecode.com/svn/trunk/ ... cal_ai.lua uses the "internal" to do the same check.
It reads the command and its options from Spring.GetCommandQueue, but shouldn't the parameters in AllowCommand contain the same data?

Re: Distinguish player commands from Lua commands (AllowCommand)

Posted: 23 Nov 2011, 12:19
by Google_Frog
Tactical AI also does this "GiveOrderToUnit(unitID, CMD_INSERT, {0, CMD_MOVE, CMD_OPT_INTERNAL, cx,cy,cz }, {"alt"} )", maybe it's required?

Re: Distinguish player commands from Lua commands (AllowCommand)

Posted: 23 Nov 2011, 15:03
by knorke
will test later.
would still be strange: "right", "shift" etc are true when set and false when not set.
Don't see why "internal" should be nil when not set?

Re: Distinguish player commands from Lua commands (AllowCommand)

Posted: 24 Nov 2011, 15:15
by knorke
since with CMD_INSERT parameters are funnily swaped, it would look like this?
Spring.GiveOrderToUnit(unitID, CMD.ATTACK , { targetID}, {CMD.OPT_INTERNAL})
seems to make no difference, still no "internal" in the cmdOptions table.
I was thinking of possing some nonsense parameter to serve as something to differentiate but does not seem very good.

But now it is not so urgent anymore as I found something else for the original problem. (which was miners being stupid)

Re: Distinguish player commands from Lua commands (AllowComm

Posted: 05 Mar 2014, 04:52
by zoggop
I'm trying to figure out how to differenciate player orders from a lua widget's orders, too. Right now I'm storing a string containing unitID, cmdID, and a list of cmdParams for every order the widget gives out. The problem with this is it doesn't really work for ICON_UNIT orders, because the player could just as well have given such an order (the likelyhood of the player sending a move order to the exact same spot is on the other hand negligable). Tags seem like a good solution, except that there's no way to know what the tag of an order just given. The order doesn't show up in the command queue until later (the next game frame, I'm assuming), and getting the command queue is the only way to get tags. Has anyone devised a good solution for this?

edit: Hm, also, cmdTag is always 0 in the UnitCommand callin.

Re: Distinguish player commands from Lua commands (AllowComm

Posted: 08 Mar 2014, 07:50
by knorke
I'm trying to figure out how to differenciate player orders from a lua widget's orders, too.
Just note, my question was about orders given by lua gadgets.
The order doesn't show up in the command queue until later (the next game frame, I'm assuming),
For widgets I would assume potentially even later? Until the order has traveled through the network lag.