Game Development Community

Where in script is picking up weapons handled?

by Nikhil Haldar-Sinha · in Torque Game Engine · 07/29/2006 (8:03 am) · 7 replies

I'm trying to figure out where the onCollision for weapons is handled. I want to add some logic based on what type of weapon is picked up.

Thanks.

-Nick

#1
07/29/2006 (8:06 am)
Weapon.cs - Around line 61
#2
07/29/2006 (8:08 am)
That's onPickup. What I want to do is something like Halo, where if you go over a weapon, it'll prompt you to pick it up. Wouldn't I need something lower than that, like a collision? Or is that the collision function?
#3
07/29/2006 (8:17 am)
Weapon.cs
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.
   if (Parent::onPickup(%this, %obj, %shape, %amount)) {
      serverPlay3D(WeaponPickupSound,%obj.getTransform());
      if (%shape.getClassName() $= "Player" && 
            %shape.getMountedImage($WeaponSlot) == 0)  {
         %shape.use(%this);
      }
   }
}

Item.cs
function ItemData::onPickup(%this,%obj,%user,%amount)
{
   // Add it to the inventory, this currently ignores the request
   // amount, you get what you get.  If the object doesn't have
   // a count or the datablock doesn't have maxIventory set, the
   // object cannot be picked up.
   %count = %obj.count;
   if (%count $= "")
      if (%this.maxInventory !$= "") {
         if (!(%count = %this.maxInventory))
            return;
      }
      else
         %count = 1;
   %user.incInventory(%this,%count);

   // Inform the client what they got.
   if (%user.client)
      messageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);

   // If the item is a static respawn item, then go ahead and
   // respawn it, otherwise remove it from the world.
   // Anything not taken up by inventory is lost.
   if (%obj.isStatic())
      %obj.respawn();
   else
      %obj.delete();
   return true;
}

The weapon's that exist in your world are actually items. Upon collision with the weapon item the appropriate weapon image is mounted.

- Tim
#4
07/29/2006 (8:20 am)
How do I make it so if it's not picked up it isn't lost? I don't want to have it constantly respawn. Would this be better done in the code?
#5
07/29/2006 (8:49 am)
This variable at the top of item.cs may be useful.
$Item::RespawnTime = 20 * 1000;

Set it to 0 and when you walk over a weapon item it won't disappear, is this what you mean?

$Item::RespawnTime = 0;
#6
07/29/2006 (8:51 am)
Well, I guess what I really want is to not have the onPickup called onCollision with a weapon on the ground. How would I do that?
#7
08/01/2006 (1:20 pm)
I had to take a look at the stock TGE scripts (Mine look nothing like them anymore). Anyway, all pickups are called from function Armor::onCollision. That is the function you would want to modify. Filter for weapons by the classname.