ShapeBaseData not showing model
by iHugMedia · in Torque Game Engine · 07/14/2006 (10:06 pm) · 7 replies
(This has been asked before, I've already searched but couldn't find anything useful to my situation, the fixes didn't work)
Hey everyone, for my game I need to have static objects that allow for a variable that determines how damaged/repaired they are. I decided to use the ShapeBase because it already had a Damage variable, which means it would be easier to modify the crowwbow to be a repair tool or something.
I ran into a problem, though, my Shape isn't showing up, all that appears in the level is the Gizmo axis. Does anyone have any insight?
Mince.
Hey everyone, for my game I need to have static objects that allow for a variable that determines how damaged/repaired they are. I decided to use the ShapeBase because it already had a Damage variable, which means it would be easier to modify the crowwbow to be a repair tool or something.
I ran into a problem, though, my Shape isn't showing up, all that appears in the level is the Gizmo axis. Does anyone have any insight?
datablock ShapeBaseData(FoodMachine)
{
shapefile = "~/data/shapes/fdmach.dts";
category = "RepairableItems";
maxDamage = "10";
};
function FoodMachine::Damage(%data, %obj, %sourceObj, %pos, %damage, %damageType)
{
%obj.applyDamage(%damage);
if(%obj.getDamageLevel() >= %obj.maxDamage)
{
messageClient(%obj.client, 'MsgWeaponUsed', 'This object has now been fixed');
}
}
function FoodMachine::onAdd(%this,%obj)
{
return(%obj);
}
function ShapeBaseData::create(%data)
{
%obj = new ShapeBase() {
dataBlock = %data;
};
return %obj;
}Thanks,Mince.
About the author
Pretentious arts student
#2
This lets you create specific functions for any particular StaticShapeData Datablocks you create with that classname.
E.g.
The code you posted above doesn't specify a className so your functions like:
If you wanted to create any number of different Datablocks that all behave the same you can just use:
-Tim
07/14/2006 (11:32 pm)
Oh, just in case it's not obvious within the code I provided above, take note of:className = "FoodMachines";
This lets you create specific functions for any particular StaticShapeData Datablocks you create with that classname.
E.g.
function FoodMachines::Damage()
The code you posted above doesn't specify a className so your functions like:
function FoodMachine::Damage()Will have no effect. Mmake sure the className is different than the Datablock name.
If you wanted to create any number of different Datablocks that all behave the same you can just use:
function StaticShapeData::Damage()
-Tim
#3
07/14/2006 (11:58 pm)
Thanks Tim! It's working perfectly now!
#4
07/15/2006 (12:01 am)
Glad to help! =)
#5
I just have one more problem, I'm using this piece of code to determine what object attacked the Machine
Thanks,
Mince.
EDIT - the "0.185379" changes every time the function is called
07/16/2006 (5:29 am)
(sorry for so many questions)I just have one more problem, I'm using this piece of code to determine what object attacked the Machine
%control = %client.getControlObject();
if ((%control.getMountedImage(0)) == "C02Image"){
%obj.applyDamage(%amount);
} else {
echo('Wrong Tool');
}But erevy time I compile it in Torsion it says that it always equates to 0, and in-game it says starter.fps/server/scripts/repairableitems.cs (11): Unable to find object: '' attempting to call function 'getControlObject' starter.fps/server/scripts/repairableitems.cs (12): Unknown command getMountedImage. Object CrossbowFireSound(21) AudioProfile -> SimDataBlock -> SimObject starter.fps/server/scripts/repairableitems.cs (11): Unable to find object: '' attempting to call function 'getControlObject' starter.fps/server/scripts/repairableitems.cs (12): Unable to find object: '0.185379' attempting to call function 'getMountedImage'every time teh weapon is fired. It looks like I'm not telling it what the client is properly, but this one is stumping me!
Thanks,
Mince.
EDIT - the "0.185379" changes every time the function is called
#6
I.e. %damageType
That will tell you what type of projectile hit your object and if the object received any radius damage. The name of the projectile is defined in each weapon's Projectile::onCollision function.
So the code below only applies damage if the object is hit by a Crossbow projectile. If shot by any other weapon it will echo "Wrong Tool Fool!". It also ignores all radius damage for obvious reasons. I'll leave you to season it to taste.
07/16/2006 (7:15 am)
Well, why not save yourself some trouble and use the call backs that are already present! I.e. %damageType
That will tell you what type of projectile hit your object and if the object received any radius damage. The name of the projectile is defined in each weapon's Projectile::onCollision function.
function CrossbowProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"CrossbowBolt");
// Radius damage is a support scripts defined in radiusDamage.cs
// Push the contact point away from the contact surface slightly
// along the contact normal to derive the explosion center. -dbs
radiusDamage(%obj, %pos, %this.damageRadius, %this.radiusDamage, "Radius", %this.areaImpulse);
}So the code below only applies damage if the object is hit by a Crossbow projectile. If shot by any other weapon it will echo "Wrong Tool Fool!". It also ignores all radius damage for obvious reasons. I'll leave you to season it to taste.
function FoodMachines::damage(%data, %obj, %sourceObj, %position, %amount, %damageType)
{
if (%damageType $= "Radius")
return;
if (%damageType $= "CrossbowBolt")
{
echo("applying damage");
%obj.applyDamage(%amount);
}
else
{
echo("Wrong Tool Fool!");
}
if(%obj.getDamageLevel() >= %obj.maxDamage)
{
messageClient(%obj.client, 'MsgWeaponUsed', 'This object has now been fixed');
}
}
#7
07/16/2006 (3:38 pm)
Okay, I didn't realis that that was what the DamageType was, It hough it only returned Radius/Directdamage. Thanks for the help again!
Torque Owner Tim Heldna
Long answer:
datablock StaticShapeData(FoodMachine) { shapefile = "~/data/shapes/fdmach.dts"; category = "RepairableItems"; className = "FoodMachines"; maxDamage = "10"; }; function FoodMachines::damage(%data, %obj, %sourceObj, %position, %amount, %damageType, %momentum) { %obj.applyDamage(%amount); if(%obj.getDamageLevel() >= %obj.maxDamage) { messageClient(%obj.client, 'MsgWeaponUsed', 'This object has now been fixed'); } } function FoodMachines::onDamage(%this,%obj) { %damageAmt = %obj.getDamageLevel(); if (%damageAmt >= %this.destroyedLevel) { %obj.setDamageState(Destroyed); } } function FoodMachines::onDestroyed(%data, %obj, %prevState) { echo("Food Machine Destroyed!"); } function FoodMachines::create(%data) { %obj = new StaticShape() { dataBlock = %data; }; return %obj; } function FoodMachines::onAdd(%this,%obj) { return(%obj); }Assuming you know how to set up a basic model with collision in Torque that will work fine. Destroyable, repairable objects are now at your disposal.
- Tim