Game Development Community

Weapon Pickup gives Full Ammo

by Chris "C2" Byars · in Torque Game Engine · 03/20/2006 (4:28 pm) · 6 replies

How can I make it so when a player picks up a weapon, they will get the full ammo for that weapon, without having to pick up any ammo items, straight from the get-go.

In function "Weapon::onPickup(%this, %obj, %shape, %amount)", I tried:
%obj.setInv(%this.image.ammo, %this.image.ammo.maxInventory);

But I can't seem to get the right local for the variable %obj. (%obj doesn't work).

Using that command works fine, say if it were in "function _____Image::onFire(%this, %obj, %slot)" or something like that.

#1
03/20/2006 (6:09 pm)
You were close, try...

%obj.[b]setInventory[/b](%this.image.ammo, %this.image.ammo.maxInventory);

I don't think setInv is a legitimate command.
#2
03/20/2006 (6:38 pm)
Ah, what an easy mistake. Now there's no console message, it just doesn't give the user ammo. :)
#3
03/20/2006 (6:53 pm)
It did for me.

Have you set up all your ammo inventory in your playerData datablock?
maxInv[StyerAmmo] = 30;

Is your ammo ItemData set up correctly?
maxInventory = 30;

Have you commented this out from game.cs in the createPlayer function?
//%player.setInventory(StyerAmmo,30);

Are you using a clip system or just ammo?

That's about all I can think of?
#4
03/20/2006 (7:11 pm)
I use clips and ammo, a heavily modified system, but the echos I've made all report back as the values they should be. I use backpacked (total) ammo, and the current ammo.


%obj.setInventory(%this.image.ammo,%this.image.ammo.maxInventory);
   %obj.setInventory(%this.image.bpammo,%this.image.bpammo.maxInventory);

   echo("Ammo Inv amount is: "@ %this.image.ammo.maxInventory);
   echo("BP Ammo Inv amount is: "@ %this.image.bpammo.maxInventory);
   echo("The ammo is: "@ %this.image.ammo);
   echo("The BP ammo is: "@ %this.image.bpammo);

Ex: If I run over a sniper rifle and pick it up, the echos report back correctly:,
Ammo Inv amount is: 4
BP Ammo Inv amount is: 4
The ammo is: sniperRifleAmmo
The BP ammo is: sniperRiflebpammo

Seems to me that it should work.

If I put an echo in there that gets the ammo after its been "set":
echo("Get Ammo: "@ %obj.getInventory(%this.image.ammo));

It returns blank space. No ammo. Why doesn't that setInventory work?
#5
03/20/2006 (7:36 pm)
Show me your function WeaponImage::onMount(%this, %obj, %slot) section in weapon.cs
#6
03/21/2006 (3:50 am)
I got it, had to use %shape instead of %obj.

function Weapon::onPickup(%this, %obj, %shape, %amount)
{
   // The parent Item method performs the actual pickup.
   // For player's we automatically use the weapon if the
   // player does not already have one in hand.

   %shape.setInventory(%this.image.ammo,%this.image.ammo.maxInventory);
   %shape.setInventory(%this.image.bpammo,%this.image.bpammo.maxInventory);


   if (Parent::onPickup(%this, %obj, %shape, %amount)) {
      serverPlay3D(WeaponPickupSound,%obj.getTransform());
      if (%shape.getClassName() $= "Player" &&
            %shape.getMountedImage($WeaponSlot) == 0)  {
         %shape.use(%this);
      }
   }
}