Distinguish player commands from Lua commands (AllowCommand)

Distinguish player commands from Lua commands (AllowCommand)

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

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Distinguish player commands from Lua commands (AllowCommand)

Post 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?
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Distinguish player commands from Lua commands (AllowCommand)

Post 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?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Distinguish player commands from Lua commands (AllowCommand)

Post 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?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Distinguish player commands from Lua commands (AllowCommand)

Post 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)
User avatar
zoggop
Posts: 289
Joined: 07 Sep 2010, 18:47

Re: Distinguish player commands from Lua commands (AllowComm

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Distinguish player commands from Lua commands (AllowComm

Post 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.
Post Reply

Return to “Lua Scripts”