Game Development Community

Weapon Mounting (one more time)

by Phil Nestoryak · in Torque Game Engine · 11/04/2004 (5:14 pm) · 15 replies

I've been reading and trying this for two weeks with limited success (forums,books,tutorials,etc) But just can't seem to make it work

Im using a fresh copy of StrongHold sampler, I've added a few extra weapons , but lets talk AK47. the ak47.cs file matches the parameters of the default crossbow.cs , I see nothing special in weapons.cs , items.cs , inventory.cs locking into a specific weapon (its all inclusive in the particular file for the weapon (ie: crossbow.cs and AK47.cs do call min/max inventory etc) But on collision with anything other than the default set of objects that FPS has will not echo a pickup (like the crossbow and ammo) In the AK47.cs I added in a collision detection echo, and it does show it collided via the command line, but it is not tripping the main collision routine for pickup.

The tutorials get a bit confusing because they do not hold to the same paramaters and file tree structure as the included FPS and they show some serious editing of several files, but the included FPS already has the pickup and mount code (no where near what the tutorials are showing)

This is my last "hump" to get over, to pickup / mount/use another weapon. The other parts of TGE don't seem too bad to pickup on, I've had a blast making water/bots/bot jets/particles/detection points/etc Just can not get this working.

Any help would save my sanity ..... thanks ...

#1
11/04/2004 (5:32 pm)
Can you post some snippets of the code that you're trying to use? And show us what the object's definition in the mission file looks like, etc?
#2
11/04/2004 (5:54 pm)
The Stronghold.mis only shows:

new Item() {
position = "203.333 144.49 225.363";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "ak47";
collideable = "0";
static = "1";
rotate = "1";
};
new Item() {
position = "201.598 144.457 224.578";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "ak47Ammo";
collideable = "0";
static = "1";
rotate = "1";

And the ak47.cs shows:

datablock ItemData(ak47)
{
// Mission editor category
category = "Weapon";

// Hook into Item Weapon class hierarchy. The weapon namespace
// provides common weapon handling functions in addition to hooks
// into the inventory system.
className = "Weapon";

// Basic Item properties
shapeFile = "~/data/shapes/weapons/ak47/ak47.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;

// Dynamic properties defined by the scripts
pickUpName = "a AK47";
image = ak47Image;
};
#3
11/04/2004 (8:28 pm)
Are you saying that you have a function called...

function AK47::onCollision()

????


If so, take it out and your problem will be fixed.
#4
11/05/2004 (1:31 am)
The only thing I added was an echo to confirm to collision, having it in or out makes no difference.
function ak47::onCollision( %this, %obj, %col )
{
echo( "ak47::onCollision called ----------------------------------" );
}

Most every weapon I have downloaded is coded just like the crossbow (which works) so it seems something basic is incorrect (in another file?) but my search to find any reference to the working crossbow in other files came up empty)

I've seen tutorials where they hard code the item(s) into inventory , but that dose not seem like the preferred way (like the included FPS)

I have noticed that "sometimes" the .dso file(s) do not get re-generated on a change to the .cs (that was a bummer to find out)
#5
11/05/2004 (1:51 am)
OK from hacking around this am before work seems like I got the collision pickup working, but no mount/use of it . Unless it added it to inventory and I just do not know how to switch to it.
(the end of the player.cs re-defines maxINV for each item again, I really was not expecting it to) Not to mention I had to kill the .dso to force a re-compile.
#6
11/05/2004 (4:46 am)
Do you want to mount the weapon upon pickup? or do you want a key to switch to it?

For pickup just use
function ak47::onCollision( %this, %obj, %col )
{
 echo( "ak47::onCollision called ----------------------------------" );
 %col.mountImage("ak47Image",0);
}

Hope this helps

MArrion
#7
11/05/2004 (5:34 am)
Im at work now, but I guess I could try it that way. Im trying to hold to the way that the FPS does things and it does not have that mount code in the crossbow.cs .. then again the crossbow is mounted on game start (yet another mystery) so maybe your suggestion will work... I'll try it tonight

Do you have a code snip of the key switch? I have a scroll wheel switch code, but I don't want to mess with that now ... thanks ...
#8
11/05/2004 (1:09 pm)
Thats it guys ! >>> THANKS <<<

So to recap for anyone else reading the thread

ak47.cs
add:

function ak47::onCollision( %this, %obj, %col )
%col.mountImage("ak47Image",0); // does the pickup
// optional echo here as shown above

Player.cs
Add min/max to Inventory

// Allowable Inventory Items
maxInv[ak47] = 1;
maxInv[ak47Ammo] = 50;

And in the game.cs add the .cs file to load

// Load up all datablocks, objects etc. This function is called when
// a server is constructed.
exec("./ak47.cs");

Time to buy Tim's ContentPacks now and have a blast !

Thanks again guys !
#9
11/05/2004 (3:18 pm)
Thats it guys ! >>> THANKS <<<

So to recap for anyone else reading the thread

ak47.cs
add:

function ak47::onCollision( %this, %obj, %col )
%col.mountImage("ak47Image",0); // does the pickup
// optional echo here as shown above

Player.cs
Add min/max to Inventory

// Allowable Inventory Items
maxInv[ak47] = 1;
maxInv[ak47Ammo] = 50;

And in the game.cs add the .cs file to load

// Load up all datablocks, objects etc. This function is called when
// a server is constructed.
exec("./ak47.cs");

Time to buy Tim's ContentPacks now and have a blast !

Thanks again guys !
#10
11/05/2004 (3:22 pm)
Function ak47::onCollision( %this, %obj, %col )
%col.mountImage("ak47Image",0); // does the pickup
// optional echo here as shown above


Is that really necessary? Ive added tons of weapons and all I ever needed to do was add the maxInvs to player...
Seems this way the maxInvs are being ignored and they could pick up as many as they want. But its been a while since ive done stuff with weapons so I might be wrong.
#11
11/05/2004 (3:33 pm)
Didn't work for any of the weapons I've tried to add..from the base FPS starter and a few tutorials missions I downloaded. I'd rather not have to go thru this, just adding to the player.cs seems like the correct thing to do
#12
11/05/2004 (5:51 pm)
What i dont get is, if the crossbow does NOT have a

Crossbow::onCollision()

Function in it, why you think you need one for the rest of your weapons. You said having

AK47::onCollision() in there doesn't matter cause it only echo's, you are wrong.

If AK47::onCollision() does not exist in your game, then TGE will call ItemData::onCollision() instead
and since that doesn't exist either, there will be nothing else done. Now had you checked Armor::onCollison
would have seen...

// Try and pickup all items
   if (%col.getClassName() $= "Item") {
      %obj.pickup(%col);
      return;
   }


All items being your crossbow, your AK47, your whatever. At that time function

ShapeBase::pickup(%this,%obj,%amount)

would be called and there your inventory is checked(which you said was messed up)
and assuming you can posses the item in your inventory it would have called....

Weapon::onPickup(%this, %obj, %shape, %amount)


Which would then equip the weapon. So like I said the very first time.....


"Take out function AK47::onCollision() and your problem will be fixed."


At least it will be fixed now that you figured out you had set the inventory wrong.
#13
11/06/2004 (3:42 am)
It WILL NOT mount without forcing it. None of them will (using the FPS sample, fresh copy)
#14
11/06/2004 (3:36 pm)
LOL, that's because you are not listening, and you are not doing it right.
Go to weapon.cs and look at line 61 for "function Weapon::onPickup()"

Replace it with this one and remove the AK47::onCollision() the weapon
will equip itself when you pick it up.

function Weapon::onPickup(%this, %obj, %shape, %amount)
{
   // The parent Item method performs the actual pickup.
   [b]// For player's we automatically use the weapon [i]if the
   // player does not already have one in hand.[/i][/b]  Now,
   // thanks to Gonzo this will equip the weapon weather you
   // like it or not.
 
   if (Parent::onPickup(%this, %obj, %shape, %amount))
   {
      serverPlay3D(WeaponPickupSound,%obj.getTransform());
      
      if(%shape.getClassName() $= "Player")
      {
		%shape.use(%this);
      }
   }
}
#15
12/17/2004 (8:49 pm)
Forgive me for being a clueless idiot here, but I think I missed quite a bit somewhere.
Namely how to add the weapon in the first place. If this is the wrong place for this question, can you point me in the right direction? Also any known resources or code snippets on how to display how much remaining ammo I actually have left would also be extremly helpful.

Thanks

Radhat