Building damage not registering
by Tank Dork · in Torque Game Engine · 06/16/2006 (5:39 pm) · 5 replies
I am using this code to try and get a building to register damage.. I seem to have missed something.. the shape will correctly register a collison with my player but not projectiles.. and it won't increment damage levels. Anyone see something I missed?
// Ammodepot script
datablock StaticShapeData( AmmoDepot )
{
category = "Building";
shapeFile = "~/data/shapes/buildings/ammodepot.dts";
sticky = true;
lightType = NoLight;
mass = 1;
respawn = false;
elasticity = 0.2;
friction = 0.6;
emap = true;
maxDamage = 100.00;
destroyedLevel = 99.00;
repairRate= 0.0;
};
// create shape
%AmmoDepot = new StaticShape() {
datablock = AmmoDepot;
};
function AmmoDepot::onAdd(%this,%obj)
{
%obj.setRepairRate(0);
echo( "I am repairing!!" );
}
function AmmoDepot::onCollision(%this,%obj)
{
%obj.determineDamageState();
echo( "Something hit me!!" );
}
function ShapeBase:: determineDamageState( %AmmoDepot ) {
%curDamage = %AmmoDepot.getDamageLevel();
%disabledDamage = %AmmoDepot.getDatablock().disabledLevel;
%destroyedDamage = %AmmoDepot.getDatablock().destroyedLevel;
if ( %curDamage >= %destroyedDamage ) {
%AmmoDepot.setDamageState( Destroyed );
echo( "I have been destroyed!!" );
}
else if( %curDamage >= %disabledDamage ) {
%AmmoDepot.setDamageState( Disabled );
}
else {
%AmmoDepot.setDamageState( Enabled );
}
}
function AmmoDepot::onDamage(%this, %obj, %delta)
{
}
function AmmoDepot::onDestroyed(%this,%obj,%state)
{
// Schedule corpse removal. Just keeping the place clean.
%obj.schedule($CorpseTimeoutValue - 100, "startFade", 100, 0, true);
%obj.schedule($CorpseTimeoutValue, "delete");
}About the author
#2
06/16/2006 (7:06 pm)
Don't you need a ::damage function for your AmmoDepot too? I think all ShapeBase is set to do by default, is call the damage function of the datablock of the object that is hit.
#3
@Paul I will check that out.. I kinda figured it had something to do with that empty on damage function..
The problem I am having is figuring out how torque script is handling this.. my player shapes have
no problem.. just my static shapes. Trying to do it "right" without writing my own damage controls :)
06/16/2006 (9:24 pm)
Thanks for forum policing Mincetro.. believe it or not sometimes buildings need damaged in TGE.. don't remember mentioning RTS.@Paul I will check that out.. I kinda figured it had something to do with that empty on damage function..
The problem I am having is figuring out how torque script is handling this.. my player shapes have
no problem.. just my static shapes. Trying to do it "right" without writing my own damage controls :)
#4
06/16/2006 (11:36 pm)
Paul is right, you will need a function to apply damage. By default shapeBase objects are set to not recieve damage.function AmmoDepot::damage(%data, %myObj, %sourceObj, %position, %amount, %damageType, %momentum)
{
%myObj.applyDamage(%amount);
}
#5
06/17/2006 (1:16 am)
Worked like a charm! Thank you two for getting me back on track!
Torque 3D Owner iHugMedia