Torque Game Engine Health pack?
by Dan · in Game Design and Creative Issues · 06/29/2010 (2:16 pm) · 12 replies
is there a way to easily make a small item that gives you health if your hurt like 20% of your health is healed...and also it there a way in the GUI editor to make somehting that shows you how much ammo you have left?
#2
07/03/2010 (4:01 pm)
lol dude telling me to look at the scripts for the health.cs and weapon.cs asnt going to help...i know 0 about programming in that language and i really dont know much about it at all thaqts why i want to learn. you know the AIpatrol Torque tutorial. i was wandering if maybe that could be used as the health pack but i dont know how to program it so...a little help would be much appreciated =)!!!
#3
Examples and experimentation are the two best methods to use when you first start to learn about something new.
07/03/2010 (4:16 pm)
The best way to learn would be to use the examples i spoke of and some experimentation to teach you not only the answer to your first question but many others that will also arise as you learn. Examples and experimentation are the two best methods to use when you first start to learn about something new.
#4
Lets take the first datablock: ItemData(HealthKit). This contains the information that a health kit object will need to make use of. Such things as shapefile, editor category, some basic physics stuff, and how much health that it recovers for you (repairAmount).
The default behavior of a healthkit is to pick up one, hang on to it and use it when needed. Once a healthkit is placed in the world and a player collides with it then the Item class functions in item.cs will handle picking it up and storing it in the player's inventory.
Let's take a look at function healthkit::onUse()
Breaking that down for human understandability you'll see that the logic goes:
* check the user's damagelevel, if it is not 0 then do something. damageLevel represents an amount of damage to the player object, if it is 0 then it's not damaged.
* 1 healthkit item is removed from the user's inventory
* the repairAmount for the healthpack is applied to the user. The repairAmount value is taken from the datablock mentioned above.
* finally, send a message to teh user that a health kit has been used.
If you want to make a healthkit that heals 20 points of health you would either duplicate or derive a new datablock (healthkit2 for example) and function. For simplicity, until you learn more, just duplicate the existing example and make your wanted changes. You will also have to allow the player your new item in the appropriate playerdata datablock (see player.cs)
Also in the health.cs script file is a datablock and function for a healthpatch. Once again the datablock contains the pertinent information, and the behavior is handled in a script function - in this case HealthPatch::onCollision(). I'll leave it up to you to break this function down and understand it, but basically what happens is that a player collides with a healthpatch and automatically gains some health.
07/03/2010 (5:02 pm)
If you look inside of health.cs (assuming TGE based upon thread title) like Caylo suggested you will see a couple of datablocks and functions.Lets take the first datablock: ItemData(HealthKit). This contains the information that a health kit object will need to make use of. Such things as shapefile, editor category, some basic physics stuff, and how much health that it recovers for you (repairAmount).
The default behavior of a healthkit is to pick up one, hang on to it and use it when needed. Once a healthkit is placed in the world and a player collides with it then the Item class functions in item.cs will handle picking it up and storing it in the player's inventory.
Let's take a look at function healthkit::onUse()
function HealthKit::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', 'c2Health Kit Applied');
}
}This function is called when you activate the keybind that is set for this action, in this case 'h'. Breaking that down for human understandability you'll see that the logic goes:
* check the user's damagelevel, if it is not 0 then do something. damageLevel represents an amount of damage to the player object, if it is 0 then it's not damaged.
* 1 healthkit item is removed from the user's inventory
* the repairAmount for the healthpack is applied to the user. The repairAmount value is taken from the datablock mentioned above.
* finally, send a message to teh user that a health kit has been used.
If you want to make a healthkit that heals 20 points of health you would either duplicate or derive a new datablock (healthkit2 for example) and function. For simplicity, until you learn more, just duplicate the existing example and make your wanted changes. You will also have to allow the player your new item in the appropriate playerdata datablock (see player.cs)
maxInv[HealthKit] = 1;In this example the stock player datablock allows the player 1 HealthKit, simply add your item name and inventory allowance.
Also in the health.cs script file is a datablock and function for a healthpatch. Once again the datablock contains the pertinent information, and the behavior is handled in a script function - in this case HealthPatch::onCollision(). I'll leave it up to you to break this function down and understand it, but basically what happens is that a player collides with a healthpatch and automatically gains some health.
Quote:The best way to learn would be to use the examples i spoke of and some experimentation to teach you not only the answer to your first question but many others that will also arise as you learn.Start small and modify datablocks for objects so you understand their properties and how they interact in the game world. Read through code and try to grasp the logic behind it. There is a wealth of resources and "documentation" that explains syntax and basic structure that you can learn from.
Examples and experimentation are the two best methods to use when you first start to learn about something new.
#5
07/03/2010 (5:10 pm)
Excellent write up Michael, thanks for being so detailed.
#6
07/04/2010 (10:27 am)
yeah thanks again Michael. you always answer my questions so thoroughly. it's very helpful!
#7
07/04/2010 (12:24 pm)
oh i just realized i don't have a file titles health.cs. do i have to make this a file or do i just not know where it is?
#8
07/06/2010 (1:44 pm)
so i could find the weapon.cs script file in the server folder but i dont have any file called "health.cs"
#9
create a new text file in "gamename/server/scripts" directory, name it health.cs, and add the following:
EDIT: modify filepaths, shapefile, repairAmount, etc as needed.
07/06/2010 (2:23 pm)
Hmm... you must be using a demo? Never noticed, until now, that the old TGE demos (demo|tutorial.base|racer) didn't include a health script file, apparently it only exists in the starter.fps mod.create a new text file in "gamename/server/scripts" directory, name it health.cs, and add the following:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
// Inventory items. These objects rely on the item & inventory support
// system defined in item.cs and inventory.cs
//-----------------------------------------------------------------------------
// Health kits can be added to your inventory and used to heal up.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Audio profiles
//-----------------------------------------------------------------------------
datablock AudioProfile(HealthUseSound)
{
filename = "~/data/sound/health_mono_01.ogg";
description = AudioClose3d;
preload = true;
};
//------------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Health Kits are designed to be picked up and stored in the player's
// inventory until they "use" it. This differs from the Health Patches below
// that apply immediately on collision with a wounded player.
//-----------------------------------------------------------------------------
datablock ItemData(HealthKit)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Health";
// Basic Item properties
shapeFile = "~/data/shapes/items/healthKit.dts";
mass = 1;
friction = 1;
elasticity = 0.3;
emap = true;
// Dynamic properties defined by the scripts
pickupName = "a health kit";
repairAmount = 50;
};
function HealthKit::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', 'c2Health Kit Applied');
}
}
//-----------------------------------------------------------------------------
// Health Patchs cannot be picked up and are not meant to be added to
// inventory. Health is applied automatically when an objects collides
// with a patch.
//-----------------------------------------------------------------------------
datablock ItemData(HealthPatch)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Health";
// Basic Item properties
shapeFile = "~/data/shapes/items/healthPatch.dts";
mass = 1;
friction = 1;
elasticity = 0.3;
emap = true;
// Dynamic properties defined by the scripts
repairAmount = 20;
maxInventory = 0; // No pickup or throw
};
function HealthPatch::onCollision(%this,%obj,%col)
{
// Apply health to colliding object if it needs it.
// Works for all shapebase objects.
if (%col.getDamageLevel() != 0 && %col.getState() !$= "Dead" ) {
%col.applyRepair(%this.repairAmount);
%obj.respawn();
if (%col.client)
messageClient(%col.client, 'MsgHealthPatchUsed', 'c2Health Patch Applied');
serverPlay3D(HealthUseSound,%obj.getTransform());
}
}Add an exec statement to "server/scripts/game.cs", and make sure that a maxInv amount for the health kit is added to the player datablock.EDIT: modify filepaths, shapefile, repairAmount, etc as needed.
#10
07/06/2010 (3:02 pm)
Oink! My not refreshing the page before sending in forum reply, Michael Hall got it covered with a much more beautiful solution..
#11
ok so im going to try to make this easier for myself by making a more clarified request.
ok so here is this
http://www.codesampler.com/torque.htm
in one part of this tutorial it has a section on shapes and basic collision. they give a you a small yellow cube with a smiley face on it. in the tutorial they teach you how to make it so upon contact it will say you've hit it on the box that you open with "~"...i forgot the name.....dont judge lol.....ok so i was wandering if i could take this further and make it so that upon contact it is "consumed". but i want to know how to make it so its not in you inventory and you just use it as soon as you touch it but it disappears for a little similar to crossbow and ammo. so even if you have full health you will "consume" the health anyways......i dont know its hard to explain i guess but is this possible for a moron child like me to program?
08/02/2010 (3:09 pm)
lol ok wow apparently i'm a dim-wit when it comes to programming but anyways....ok so im going to try to make this easier for myself by making a more clarified request.
ok so here is this
http://www.codesampler.com/torque.htm
in one part of this tutorial it has a section on shapes and basic collision. they give a you a small yellow cube with a smiley face on it. in the tutorial they teach you how to make it so upon contact it will say you've hit it on the box that you open with "~"...i forgot the name.....dont judge lol.....ok so i was wandering if i could take this further and make it so that upon contact it is "consumed". but i want to know how to make it so its not in you inventory and you just use it as soon as you touch it but it disappears for a little similar to crossbow and ammo. so even if you have full health you will "consume" the health anyways......i dont know its hard to explain i guess but is this possible for a moron child like me to program?
#12
08/02/2010 (5:34 pm)
Use the healthpatch code as an example and remove the check for getDamageLevel()
Torque 3D Owner Caylo Gypsyblood
Building an AMMO GUI is going to take a bit more work, but much of your work is already done and archived away here in the forums, carefully crafted search query will return some very nice examples.