CmdID Query

CmdID Query

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

CmdID Query

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

Re: CmdID Query

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

Re: CmdID Query

Post 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).
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: CmdID Query

Post 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?
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: CmdID Query

Post 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.
Von66341
Posts: 111
Joined: 10 Feb 2011, 03:00

Re: CmdID Query

Post by Von66341 »

Thanks Niobium! It works!
Post Reply

Return to “Game Development”