Game Development Community

Who clicked me?

by Andy Hubbard · in Torque 3D Professional · 08/06/2010 (5:13 pm) · 3 replies

Hi all,

Noob question, as usual!

I need to have a GUI button that when clicked the clicking client does something. More specifically it is an inventory 'equip' button that when an item in the inventory list is highlighted and the equip button is clicked then the player equips the item.

To do this I have had to do a commandToServer and then that command on the server knows the client and I can equip the item no problem. This feels like a waste of bandwidth and I would like the equiping to be handled purely on the client.

Any ideas?

Thanks,

Andy

#1
08/06/2010 (5:34 pm)
Doesn't the server need to know what the player has equiped? does it not modify any server variables, like stats? Is it multiplayer, so other players need to know what's equipped? If any of this is true, then commandToServer is really the right way to do it. If it's truly just a cosmetic effect for the player only, then you can keep it client side.
#2
08/06/2010 (6:48 pm)
Also, I wouldn't worry about bandwidth issues on things like equipping an item...it's not really a frequent action in just about any game I can think of...
#3
08/07/2010 (8:40 am)

I planned to let the usual server side code in inventory.cs and item.cs handle things like stats, variables and letting the other clients know what is going on. So all the equip button does is use the item. My current code is below to clarify what I am trying to do.

function serverCmdequipItem(%client, %item)
{
   if (%item $= "") {
      messageClient(%client, 'MsgItemPickup', '\c0No item selected');
      return;
   }

   %client.getControlObject().use(%item);
   // can I get this use(%item) call into the GUI button function below?

}

function inventoryGui::buttonEquip()
{
   // equip the selected item to the relevant mount point
   // for now this is only weapons
   //
   // $lstInventoryitem is the item datablock name got from a
   // GuiTextListCtrl inventory listing when the item is selected
   // in the list

   commandToServer('equipItem', $lstInventoryitem);

   // can I call use($lstInventoryitem) here?
   // maybe LocalClientConnection.getControlObject();
   // but that did not seem to work :(
   // ??
}


I also have a 'use item' button and a 'drop item' button. With all these added up I'd like to get away from the commandToServer requirement. A fair bit of 'use item' will be going on I expect ....

Thanks for the input so far.