Restore health to static
by Adam Troutman · in Technical Issues · 05/18/2006 (8:10 pm) · 5 replies
Can someone tell me why this won't repair?
function tree::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
%obj.applydamage(%damage);
if(%obj.getDamageLevel() == %this.maxDamage){
%trans = %obj.getTransform();
%p = new (item)()
{
datablock = planks;
};
%p.setTransform(%trans);
//hiding and respawning of the tree
%obj.startFade(0, 0, true);
%obj.hide(true);
Echo("tree should be hidden");
%obj.schedule(30000, "hide", false);
%obj.schedule(30000, "startFade", 1000, 0, false);
%obj.applyrepair(500);
}
}
#2
07/11/2006 (10:08 am)
There is an applyRepair function (on players at least, presumably from shapebase), but I think all it does is a gradual health restore instead of instant. So using setDamageLevel(0) would be fine. Also perhaps it might not work if the object is set to hidden, try scheduling the repair to happen after it's unhidden perhaps?
#3
His solution was to reset self-repair rate to 0, apply the repair, and then return self-repair to its prior value.
Like so:
That book is invaluable.
The other question is, why not just Delete the old tree instead of Hiding it and spawn an entirely new one instead of repairing the old? (Not that it would seem to really matter, mind you.)
Good luck.
07/13/2006 (1:13 am)
I have no idea if this is what is causing your bug but it certainly caused mine. Taken from "The Game Programmer's Guide to Torque" by Edward Maurina, Chap. 6, page 163:Quote:
There is, however, a slight trick to making this work. If we have chosen to allow our shape to self-repair (by calling setRepairRate() with a nonzero value), we cannot apply repairs at a greater rate than the specified rate.
His solution was to reset self-repair rate to 0, apply the repair, and then return self-repair to its prior value.
Like so:
%obj.setRepairRate( 0 ); %obj.applyRepair( %value ); %obj.setRepairRate( %obj.GetDatablock().repairRate() );
That book is invaluable.
The other question is, why not just Delete the old tree instead of Hiding it and spawn an entirely new one instead of repairing the old? (Not that it would seem to really matter, mind you.)
Good luck.
#4
07/13/2006 (1:15 am)
Um well this is an old post and i don't have a problem anymore so thanks anyway.
Associate Anthony Rosenbaum