View topic - CmdID Query



All times are UTC + 1 hour


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: CmdID Query
PostPosted: 10 Jun 2011, 15:44 

Joined: 10 Feb 2011, 03:00
Hi!

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

Code:
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!


Top
 Offline Profile  
 
 Post subject: Re: CmdID Query
PostPosted: 10 Jun 2011, 21:11 
Moderator
User avatar

Joined: 22 Feb 2006, 01:02
Location: cheap kitchen
Code:
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.


Top
 Offline Profile  
 
 Post subject: Re: CmdID Query
PostPosted: 11 Jun 2011, 14:38 
Moderator

Joined: 12 Oct 2007, 08:24
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).


Top
 Offline Profile  
 
 Post subject: Re: CmdID Query
PostPosted: 13 Jun 2011, 03:53 

Joined: 10 Feb 2011, 03:00
I tried out the above 2 suggestion.

1.
Code:
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?


Top
 Offline Profile  
 
 Post subject: Re: CmdID Query
PostPosted: 13 Jun 2011, 12:00 
User avatar

Joined: 07 Dec 2008, 02:35
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.


Top
 Offline Profile  
 
 Post subject: Re: CmdID Query
PostPosted: 14 Jun 2011, 02:07 

Joined: 10 Feb 2011, 03:00
Thanks Niobium! It works!


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.