Game Development Community

Crossbow projectile name?

by Infinitum3D · in Torque Game Engine · 12/19/2006 (10:30 am) · 5 replies

I'm trying to make my barrels "Explode" on collision with a crossbow bolt. What name do I use for the projectile? I've tried "CrossbowBolt", "projectile", and "Ammo", but I'm wrong on all three. What is the projectile called?

I'm using Starter.FPS

Quote:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
// Exploding Shapes
//-----------------------------------------------------------------------------



datablock StaticShapeData(explodingBarrel)
{
category = "Barrels";
shapeFile = "~/data/shapes/barrels/barrel01.dts";
};

//--collision detection of CrossbowBolt to barrel--//
function explodingBarrel::onCollision(%this, %obj, %col)
{


//--Apply damage to the object from CrossbowBolt--//

if (%col.getClassName() $="WHAT_NAME_GOES_HERE?")
{
//%col.damage(%obj,%pos,%this.directDamage,"CrossbowBolt");


//--if barrel is hit by CrossbowBolt then delete the barrel--//

%obj.delete();
}
}

#1
12/19/2006 (11:54 am)
Try this in cs file, put cs file in server\scripts. Exec in game.cs. In the world editor creator add the model under Shapes to the mission and shoot away. Tested in clean install Torque 1.5.0. You might want look at Games Extract : FX Pack #1.

datablock StaticShapeData(TestShape)
{
   category = "Exploding Objects";
   shapeFile = "~/data/shapes/barrel/barrel.dts";
   maxDamage = 100;
   destroyedLevel = 100;
   mass = 10;
   friction = 1;
   elasticity = 0.3;
   explosion = TestShapeDataExplosion;
   debrisShapeName = "~/data/shapes/barrel/barrel_debris1.dts";
   debris = StaticShapeDataDebri;
};

function TestShape::onAdd(%this,%obj)
{
   %obj.playThread(0,"ambient");
}
//---------------------------------
//General StaticShapeData functions
//---------------------------------
function StaticShapeData::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
      echo("Blowing stuff up");
      %obj.applyDamage(%damage);
}
function StaticShapeData::onDamage(%this, %obj, %delta)
{
   %damage = %obj.getDamageLevel();
   if (%damage >= %this.destroyedLevel)
   {
      if(%obj.getDamageState() !$= "Destroyed")
      {
        %obj.setDamageState(Destroyed); 
     }
   } 
  else 
  { 
     if(%obj.getDamageState() !$= "Enabled")
         %obj.setDamageState(Enabled);
   }
}
function StaticShapeData::onDestroyed(%this, %obj, %prevState)
{
      %obj.schedule(300, "delete");
}
#2
12/20/2006 (5:25 am)
Thanks! I had to comment out the two debris lines. Torque says I don't have the right version of the SDK or something to that effect.

I had to adjust the code for my directories, but other than that it works great! Thanks.

Quote:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
// Exploding Shapes
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

datablock StaticShapeData(ExplodingBarrelShape)
{
category = "Exploding Objects";
shapeFile = "~/data/shapes/barrels/barrel01.dts";
maxDamage = 100;
destroyedLevel = 100;
mass = 10;
friction = 1;
elasticity = 0.3;
explosion = ExplodingBarrelShapeDataExplosion;
// debrisShapeName = "~/data/shapes/barrel/barrel_debris1.dts";
// debris = StaticShapeDataDebri;
};

function ExplodingBarrelShape::onAdd(%this,%obj)
{
%obj.playThread(0,"ambient");
}

//---------------------------------
//General StaticShapeData functions
//---------------------------------

function StaticShapeData::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
echo("Blowing stuff up");
%obj.applyDamage(%damage);
}
function StaticShapeData::onDamage(%this, %obj, %delta)
{
%damage = %obj.getDamageLevel();
if (%damage >= %this.destroyedLevel)
{
if(%obj.getDamageState() !$= "Destroyed")
{
%obj.setDamageState(Destroyed);
}
}
else
{
if(%obj.getDamageState() !$= "Enabled")
%obj.setDamageState(Enabled);
}
}

function StaticShapeData::onDestroyed(%this, %obj, %prevState)
{
%obj.schedule(300, "delete");
}


//---------------------------


Just to make sure I understand the code...
This basically destroys the barrel based on damage from ANY source, not just crossbow shots, right? And it takes multiple shots to blow up the barrel because the destroyedLevel is 100, and the damege done is set at a maximum of 100 (so a random number from 1-100). If I lower the maxDamage value, that means the barrel takes less damage per hit, so it takes more hits to actually destroy. Or I could lower the destroyedLevel number to lower the amont of damage needed to blow it up.


This is good, but what if I want something that can only be destroyed by a specific weapon, like an idol that can only be damaged by a certain sword, or a statue that can't be damaged by a sword, but can be destroyed by a crossbow?

Is that a whole other concept, or just some minor adjustments to this code?

Thanks for the help!!!

Tony
#3
12/20/2006 (8:04 am)
Its somthing to do with %damageType, I remember this being in one of Kennith Finney's books.

You could add damageType in ALL the projectile datablock then
if(damageType == %sourceobject->mDataBlock->damagetype)
{
blaa
}
or somthing like that
#4
12/20/2006 (8:37 am)
Just thought I'd add this for future reference...

You can find the name or class, etc.. by adding echo's to your code and looking in the console. For instance you had:

function explodingBarrel::onCollision(%this, %obj, %col)
{
//--Apply damage to the object from CrossbowBolt--//

if (%col.getClassName() $="WHAT_NAME_GOES_HERE?")
{

I would have put in something like this for testing (\c2 changes the consoles text color)

function explodingBarrel::onCollision(%this, %obj, %col)
{
echo( "\c2 %this ::: " @ %this );
echo( "\c2 %obj ::: " @ %obj );
echo( "\c2 %col ::: " @ %col );
echo( "\c2 %obj.getClassName ::: " @ %obj.getClassName() );
echo( "\c2 %col.getClassName ::: " @ %col.getClassName() );

you can also get useful info by using dump()

echo( "\c2 %obj.dump ::: " @ %obj.dump() );
#5
12/20/2006 (6:34 pm)
You right you can shoot it with any weapon. If you need debris.dts let me know. They make the barrel look like it is flying a part. You can modify the code to get what you want so only certain weapons can destroy certain objects. I might have it on computer I will look and see.