Game Development Community

Ammo display

by Xavier "eXoDuS" Amado · in Torque Game Engine · 12/08/2001 (8:08 am) · 15 replies

How can i make an hud item/bar to display the ammunition left?

#1
12/09/2001 (8:05 am)
im looking into this today (and might spill over into tomorow) so, if it works out, ill let you know!
#2
12/09/2001 (5:30 pm)
Im tracing through what the crimeforce guys did in their demo, if anyone else has an easy way to do this, id be much appreciative...
Ryan
#3
12/09/2001 (6:12 pm)
OK, so far this is what i got:
in the gui editor, i created a guitextctrl called AmmoAmount. Then in my weapons ::onFire function, i added this:

AmmoAmount.setText(%obj.getinventory(%this.ammo));

which sets the text in the gui to be what my ammo is. but, only when i fire, so right now im lookin to see where i can also throw that ammoamout.settext() call... ill post when i figure it out!
Ryan

EDIT: and i changed weapons.cs's onuse function to be:
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);
      AmmoAmount.setText(%obj.getinventory(%data.image.getId().ammo));//this sets the text on use
      if (%obj.client)
         messageClient(%obj.client, 'MsgWeaponUsed', '\c0Weapon selected');
   }
/EDIT
#4
12/09/2001 (6:41 pm)
I just posted a whole tutorial about it in the resource section...it hasnt been approved yet by GG so it hasnt shown up yet.

Here is a direct link:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=1786
#5
12/09/2001 (6:53 pm)
oh man, i wish you had been a half hour eariler... :)
Ryan
#6
12/09/2001 (8:13 pm)
Thanks a lot!!!!
both of u
#7
12/10/2001 (5:18 pm)
Forgot about updating the HUD on ammo pickup...recheck the tutorial and you will see i added the update to it.
#8
12/10/2001 (5:33 pm)
ok, but now i pickup crossbow ammo while holding my rifle, and it shows the crossbow ammo i just picked up for the ammo... but much better now :)
Ryan
#9
12/10/2001 (7:05 pm)
Do what the Updated section says in my tutorial now and see if it works correctly..I dont have more than 1 weapon in yet so I can't test it....let me know here if it works.

-Tim
#10
12/10/2001 (11:42 pm)
Make sure you guys are separating client from server stuff.

If this is all single player, no problem.

But in a client/server game, the server keeps track of the ammo, and you should really be setting the ammo hud amount with either a messageClient(); or commandToClient(); call
#11
12/11/2001 (1:14 am)
My tutorial does use commandToClient.
#12
12/11/2001 (5:44 am)
yeah, the stuff i brewed up was just a quick hack... the tutorial that tim has done uses commandtoserver()... and yes, the updated part of the tut doesnt quite work for multiple weapons... if i have one weapon and pick up ammo for another, for the time between when i pick it up and do something else with my weapon (fire, switch weapons, ect) it displays the amount of ammo i just picked up... ill take a look at it today and let you guys know what i come up with
Ryan
#13
12/11/2001 (2:41 pm)
Hope this helps:
In the function Ammo::onInventory(%this,%obj,%amount)
you should include the ammo update and display inside the if block that determines if the ammo is of that weapon... just like this:

if (isObject(%image.ammo) && %image.ammo.getId() == %this.getId())
{
%obj.setImageAmmo(%i,%amount != 0);
//Ammo Hud
%currentAmmo = %obj.getInventory(%this);
%obj.client.setAmmoAmountHud(%currentAmmo);
}

Thanks
#14
12/12/2001 (3:13 am)
Sorry about the bug its fixed in the tutorial now, and coming back here I see that Xavier "ExoDuS" Amado found the problem. (which was a typo on my part when i wrote the tutorial) Took me using the latest head release (which has 2 weapons) and when I took the tutorial myself I realized the mistake.
#15
12/12/2001 (7:33 am)
:)
Thanks for the nice tutorial and for your help!