Picking up items
by Neil Marshall · in Torque Game Engine · 06/25/2002 (8:49 pm) · 5 replies
I'm trying to add power bars to my game which, when you run over them, will add to the players energy and allow them to run.
I modeled my little bouncing powerbar in max and I added a sequence. Then I opened up health.cs and copied the health kit code and renamed everything PowerBar. Then I added code to animate the sequence all the time.
Now the problem is, in the game I can run over health kits just fine, but when I put down my powerbar, nothing happens. It just sits there spinning and I can't pick it up. What am I doing wrong?
Here is the code I have in health.cs
I modeled my little bouncing powerbar in max and I added a sequence. Then I opened up health.cs and copied the health kit code and renamed everything PowerBar. Then I added code to animate the sequence all the time.
Now the problem is, in the game I can run over health kits just fine, but when I put down my powerbar, nothing happens. It just sits there spinning and I can't pick it up. What am I doing wrong?
Here is the code I have in health.cs
datablock ItemData(PowerBar)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Energy";
// Basic Item properties
shapeFile = "~/data/shapes/items/powerbar.dts";
mass = 1;
friction = 1;
elasticity = 0.3;
// Dynamic properties defined by the scripts
pickupName = "a powerbar";
repairAmount = 50;
};
function PowerBar::onUse(%this,%user)
{
// Apply some health to whoever uses it, the health kit is only
// used if the user is currently damaged.
if (%user.getDamageLevel() != 0) {
%user.decInventory(%this,1);
%user.applyRepair(%this.repairAmount);
if (%user.client)
messageClient(%user.client, 'MsgHealthKitUsed', '\c2You ate the power bar');
}
}
function PowerBar::onAdd(%this,%obj)
{
%obj.playThread(0,"RotateSeq");
}
#2
06/26/2002 (7:40 am)
Great, I got it to work. The question is, why does a health patch have an onCollision but a health pack doesn't, yet they both appear to work?
#3
The HealthKit is an manual use inventory item. HealthKit::onUse.
06/26/2002 (8:26 am)
The HealthPatch is a "use on collision" item. HealthPatch::onCollision.The HealthKit is an manual use inventory item. HealthKit::onUse.
#4
I placed a health kit and a power bar side by side. I ran over my object, nothing. Ran over the health kit, it picked it up. Both appeared to be running the same code yet one didn't work. (I was damaged at the time, just to make sure that wasn't it)
06/26/2002 (8:50 am)
Yes I know, but I couldn't even get my character to pickup the powerbar when it was setup like a health kit.I placed a health kit and a power bar side by side. I ran over my object, nothing. Ran over the health kit, it picked it up. Both appeared to be running the same code yet one didn't work. (I was damaged at the time, just to make sure that wasn't it)
#5
maxInv[HealthKit] = 1; //around line 687 in release 1.1.1
maxInv[PowerBar] = 1; //whatever you want the # to be.
You'll also need to setup a keybind to use the PowerBar in the default.bind.cs file (config.cs too if you have one), just like the HealthKit uses the "h" key.
I basically copied the HealthKit setup for some other inventory items. It should work fine.
The HealthPatch type setup doesn't need that extra stuff.
06/26/2002 (9:10 am)
If you use the HealthKit type setup, you need to make sure you set the max inventory in the player.cs file.maxInv[HealthKit] = 1; //around line 687 in release 1.1.1
maxInv[PowerBar] = 1; //whatever you want the # to be.
You'll also need to setup a keybind to use the PowerBar in the default.bind.cs file (config.cs too if you have one), just like the HealthKit uses the "h" key.
I basically copied the HealthKit setup for some other inventory items. It should work fine.
The HealthPatch type setup doesn't need that extra stuff.
Torque 3D Owner Robert Blanchet Jr.
function PowerBar::onCollision(%this, %obj, %user) { if(%user.getClassName() !$= "Player") return; // Only interested in player collisions // do stuff }