Game Development Community

Weapon ammo

by James Steele · in Torque Game Engine Advanced · 05/21/2006 (12:09 pm) · 2 replies

I'm having a problem with firing a weapon. I'm using a bastardized load of code from the BT tank pack, as well as the fps demo. I'm mounted my weapon just fine, and it cycled through the weapon states.

The problem is...is keeps on switching to "No Ammo" straight away. Which is weird because I have the following in my data block for the object using the weapon;

maxInv[BasicArtWeapon] = 1;
maxInv[BasicArtWeaponAmmo] = 10000;

ammo = 1;

and then when the object is created I have...

%obj.mountable = true;

%obj.setInventory(BasicArtWeapon, 1);
%obj.setInventory(BasicArtWeaponAmmo, 10000);
%obj.mountImage(BasicArtWeaponImage, 0);

I'm completely missing something....but I just can't figure out what! I was wondering if any of you guys had an idea of anything obvious to the initiated, but not to the dumb schmuck likle myself.

thanks in advance!

#1
05/21/2006 (10:18 pm)
Mounted images don't actually care about thier "ammo" item, they care about thier ammo state. Basically, when they fire they check thier ammo and set thier ammo state. Also, they need to check thier ammo when they are mounted. This allows great flexibility, but it can also confuse newbies :)

Figure out which ::onMount your weapon is using. If you have a special one just for that weapon, make sure you check. Assuming it's something like ::onMount(%data,%player,%slot), go and do

if(%player.getInventory(%data.ammo))
   %player.setImageAmmo(%slot,true);

This is off the top of my head, but it should do it. Also be sure to do the reverse when you fire, otherwise you gun will not actually run out of ammo.
#2
05/21/2006 (11:05 pm)
Max,


that worked a treat. I couldn't quite work out the relation between the inventory and the mounted image stuff, but I see what's going on now.

thanks again!