Page 1 of 1

CmdID Query

Posted: 10 Jun 2011, 16:44
by Von66341
Hi!

I have this portion of a code that logs when a command is being execute.

Code: Select all

function widget:UnitCommand(unitID, unitDefID, unitTeam, cmdID, cmdOpts, cmdParams)
local txt
local x,y,z = Spring.GetUnitPosition(unitID)
if cmdID == 36525 then -- Special On/Off Command 	
txt = "Unit ID "..unitID.." of Team "..unitTeam.." was commanded to the special weapon"
write(txt)
end 
end	


The full code for special command can be found here:
http://pastebin.com/njYaALTM

The logger works for other command, for e.g. attack, turn, wait, guard. However, it does not log for this special command which I create. Anyone have any suggestion what may went wrong?

Thanks!

Re: CmdID Query

Posted: 10 Jun 2011, 22:11
by knorke

Code: Select all

function widget:UnitCommand(unitID, unitDefID, unitTeam, cmdID, cmdOpts, cmdParams)
Spring.Echo ("bla")
end   
Does this print "bla" when you execute the custom command? Maybe the if does not trigger for some reason.

Re: CmdID Query

Posted: 11 Jun 2011, 15:38
by Google_Frog
function widget:CommandNotify(id, params, options)

This collects custom widget commands. It may be the only function that does so because custom widgets commands are local (I would not be surprised if UnitCommand was only for synced commands).

Re: CmdID Query

Posted: 13 Jun 2011, 04:53
by Von66341
I tried out the above 2 suggestion.

1.

Code: Select all

function widget:UnitCommand(unitID, unitDefID, unitTeam, cmdID, cmdOpts, cmdParams)
Spring.Echo ("bla")
end 
This echo is display when my custom commands are run.

However, it is command ID 70 instead of my custom command ID.

These are the custom command I have that echo the correct command ID:
CMD_RADAR - command ID 35525
CMD_TURN - command ID 35521
CMD_MORPH - commandID 3210

These 2 does not, it only activates the command ID 70 instead of its respective command shown below.
CMD_SPECIAL - commandID 36525
CMD_SMOKE - commandID 35520

The code CMD_RADAR can be found here (corrrectly echo):
http://pastebin.com/MWFKtk5u

The code CMD_SPECIAL can be found here(NOT correctly echo):
http://pastebin.com/2kDUWnSY

I did both code (CMD_RADAR and CMD_SPECIAL) in the similar manner.
Any suggestions why the difference in the command ID being pick up?

2. function widget:CommandNotify(cmdID, params, options)
Able to detect my special commands being activated.
However, is there a way to get the unitID and TeamID from the cmdID?

Re: CmdID Query

Posted: 13 Jun 2011, 13:00
by Niobium
Von66341 wrote:Any suggestions why the difference in the command ID being pick up?
You are returning false in :AllowCommand, so the command gets stopped there and isn't processed further.

Re: CmdID Query

Posted: 14 Jun 2011, 03:07
by Von66341
Thanks Niobium! It works!