Car "repair" problem
by Very Interactive Person · in Torque Game Engine · 05/19/2004 (4:41 am) · 10 replies
I'm trying to script a repair "powerup" that can be picked up by wheeled vehicles.
Now I'm experiencing 2 problems:
1)The repairing doesn't seem to work (the car starts repairing real slow untill its back at 100%, I just wanted to decrease its damage level with a certain value)
2)The "powerup" doesn't respawn. It just stays there. It should dissapear and respawn after a certain time.
Here' my script, can anyone tell me what I am doing wrong here?
Now I'm experiencing 2 problems:
1)The repairing doesn't seem to work (the car starts repairing real slow untill its back at 100%, I just wanted to decrease its damage level with a certain value)
2)The "powerup" doesn't respawn. It just stays there. It should dissapear and respawn after a certain time.
Here' my script, can anyone tell me what I am doing wrong here?
datablock ShapeBaseImageData(RepairPowerUpImage)
{
shapeFile = "~/data/shapes/powerups/healthpowerup/health.dts";
item = RepairPowerUp;
offset = "0 0 0";
lightType = "PulsingLight";
lightColor = "0.5 0.5 0.5 1.0";
lightTime = "1000";
lightRadius = "3";
cloakable = false;
};
datablock ItemData(RepairPowerUp)
{
category = "Powerups";
image = RepairPowerUpImage;
shapefile = "~/data/shapes/powerups/healthpowerup/health.dts";
mass = 55;
elasticity = 0.2;
friction = 0.6;
pickupRadius = 3;
pickUpName = "Repair powerup!";
computeCRC = true;
lightType = "PulsingLight";
lightColor = "0.5 0.5 0.5 1.0";
lightTime = "1000";
lightRadius = "3";
repairAmount = 20;
isInvincible = true;
};
function RepairPowerUp::onCollision(%this,%obj,%col)
{
echo(%col.getDamageLevel());
if (%col.getDamageLevel() != 0) {
%col.applyRepair(%this.repairAmount);
serverPlay3D(repairPickup,%obj.getTransform());
%obj.respawn();
}
}
#2
powerups.cs (0): Unknown command respawn.
Object (1381) Item -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
05/19/2004 (6:40 am)
The strange thing is I got this code from I game I did like a year ago... and then it worked fine. Now I see this in the console:powerups.cs (0): Unknown command respawn.
Object (1381) Item -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
#4
05/19/2004 (9:59 am)
Here is how I did it for my objects:function Missile::onCollision(%this, %obj,%col,%pos,%normal)
{
%obj.startFade(0, 0, true);
%obj.setHidden(true);
$CurrentInventoryImage = "launcher_icon.png";
%col.setInventory(%obj);
// Shedule a reapearance
%obj.schedule(20 * 1000, "setHidden", false);
%obj.schedule(20 * 1000 + 100, "startFade", 1000, 0, false);
}
#5
05/19/2004 (9:59 am)
Doh! I feel so dumb now lol. I forgot to add in the script file with the generic item functions (like respawn etc).
#6
05/19/2004 (10:01 am)
Still leaves me with my second question tough... how would I repair the vehicle at once? Like if its damage level is 60 change it to 20? applyRepair isn't what I tought it would be.
#7
somehow applyRepair doesn't work (well.. I couldn't get it to work).
11/26/2006 (11:38 am)
I know this thread is more than 2 years old but I too had some diffilculties with this. The way to do it is withsetDamageLevel(0)
somehow applyRepair doesn't work (well.. I couldn't get it to work).
#8
05/02/2007 (12:34 pm)
Vincent, thanks for posting that, it solves my problem today! :-)
#9
06/17/2007 (10:52 am)
For partial vehicle repairs I use this:%obj.setDamageLevel(%obj.getDamageLevel() - 250);
#10
What I didn't realize was there is apparently a very deliberate relationship between the applyRepair console method and the "repairRate" property in the object's datablock. I was thinking repairRate was only meant to be a default value to pass to the .setRepairRate method when you wanted self regenerating objects. Turns out, repairRate is intended to be a cap on how fast applyRepair can "fix" the shape. For example, in starter.fps, notice how when you take a health power up your health bar animates slowly upward instead of just jumping up by the full amount. This is repairRate at work. Basically, if you set repair rate for, let's just say 0.1, when applyRepair gets called, Torque will add 0.1 health per game tick until the cumulative repair equals what you set in applyRepair effectively spreading the repair out over a few seconds.
Furthermore, the default value for repairRate (if you do not specify) is so small that it might as well be zero (IOW, you repair so slowly you pretty much can't tell its happening). So if you have no repairRate at all in your datablock, it can look as though applyRepair doesn't do anything.
So to relate this to the above discussion, to make applyRepair instantly repair your vehicle, go into the vehicle datablock, and make sure there is a repairRate property and set it equal to whatever you set maxDamage to. (Don't worry... it doesn't make the vehicle self-repair unless you also call the .setRepairRate method on the vehicle instance). But once repairRate in the vehicle's datablock equals maxDamage, for all intents and purposes you just told Torque "I don't want a cap on how fast applyRepair works... just apply the whole repair at once."
Hope this eventually helps someone else understand more easily than I came to it. :-)
12/05/2008 (4:53 pm)
I know this comes way too late to help the original problem, but I found this thread because I was trying to understand problems with applyRepair myself. Alas, I (mistakenly) thought I had found an engine bug, but it turns out there was something I didn't understand about the way the code was implemented and why it is that way. It seems to fit here, so in case anyone else comes searching on applyRepair problems, I'll post this. What I didn't realize was there is apparently a very deliberate relationship between the applyRepair console method and the "repairRate" property in the object's datablock. I was thinking repairRate was only meant to be a default value to pass to the .setRepairRate method when you wanted self regenerating objects. Turns out, repairRate is intended to be a cap on how fast applyRepair can "fix" the shape. For example, in starter.fps, notice how when you take a health power up your health bar animates slowly upward instead of just jumping up by the full amount. This is repairRate at work. Basically, if you set repair rate for, let's just say 0.1, when applyRepair gets called, Torque will add 0.1 health per game tick until the cumulative repair equals what you set in applyRepair effectively spreading the repair out over a few seconds.
Furthermore, the default value for repairRate (if you do not specify) is so small that it might as well be zero (IOW, you repair so slowly you pretty much can't tell its happening). So if you have no repairRate at all in your datablock, it can look as though applyRepair doesn't do anything.
So to relate this to the above discussion, to make applyRepair instantly repair your vehicle, go into the vehicle datablock, and make sure there is a repairRate property and set it equal to whatever you set maxDamage to. (Don't worry... it doesn't make the vehicle self-repair unless you also call the .setRepairRate method on the vehicle instance). But once repairRate in the vehicle's datablock equals maxDamage, for all intents and purposes you just told Torque "I don't want a cap on how fast applyRepair works... just apply the whole repair at once."
Hope this eventually helps someone else understand more easily than I came to it. :-)
Torque Owner Brett Fattori
- Brett