Game Development Community

Weapon Cycling, message hud addon for which weapon

by Michael Bartnett · in Torque Game Engine · 06/04/2005 (11:13 pm) · 2 replies

Hey,
I already posted this in the Weapon Cycling [href=http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5907]resource[/href], but I imagine not a whole ton of people look there regularly, so I put it here.

When you swap weapons in the FPS sample after adding the weapon cycling feature in the message hud it still says "Weapon Selected". I wanted to make it say which weapon was selected. I edited Weapon::onUse in weapon.cs so that it looks like this:

function Weapon::onUse(%data,%obj)
{
   // Default behavoir for all weapons is to mount it into the
   // this object's weapon slot, which is currently assumed
   // to be slot 0
   if (%obj.getMountedImage($WeaponSlot) != %data.image.getId()) {
      %obj.mountImage(%data.image, $WeaponSlot);
   %curwpn = %obj.getMountedImage($WeaponSlot).item.getName();
      if (%obj.client)
      {
   if(%curwpn $= "Pistol")
      messageClient(%obj.client, 'MsgWeaponUsed', '\c0Pistol selected');
   if(%curwpn $= "M4ss")
      messageClient(%obj.client, 'MsgWeaponUsed', '\c0M4ss selected');
   if(%curwpn $= "Mp5")
      messageClient(%obj.client, 'MsgWeaponUsed', '\c0Mp5 selected');
}
   }
}

For the most part it works fine, but if you are holding down fire and simultaneously swap weapons the weapon labels will get behind.

Example:
I have the pistol, m4ss, and the mp5. I have the m4ss selected, and I'm holding down the fire button. At the same time I hit the next weapon button. The mp5 image is mounted and begins firing just the way I told it to, except up in the hud a new message pops up saying "M4ss Selected". It recognizes the fact that it needs to show a message signifying a new weapon has been selected, but it does not update which weapon has been selected as it is calculating which message to show. Any thoughts on how to fix this? I'm betting on people who play the game won't be thinking things through methodically and will be pressing buttons all over the place, so it'd be good to clean this bit up.
On a side note, once you stop firing and switch to another weapon the labels are fine.

#1
05/31/2008 (9:30 am)
Thanks for this, worked perfect for me.
Works even 2 years after :)
#2
08/13/2008 (12:59 pm)
I simplified it so it works a little better so you don't have to update that function manually each time you add a new weapon to the game. It's up to you and may not work if you want to call something different or possibly give a description or something but for me I used this:

%curwpn = %obj.getMountedImage($WeaponSlot).item.getName();
      if (%obj.client)
         messageClient(%obj.client, 'MsgWeaponUsed', '\c0Weapon selected %1', %curwpn);

You can obviously play with the format of it for example put '%1 selected' or something. This is awesome I've been wanting to add this to my game.