Game Development Community

Torque game engine demo health bar

by Dan · in Game Design and Creative Issues · 04/28/2009 (6:53 pm) · 25 replies

i was wondering if there is a way to make like a health and mana bar in the bottom corner of the screen when your done with an editing a torque game mission. i would also like to know if there is any free down loadable spells like AFX but free
Page «Previous 1 2
#1
04/28/2009 (10:10 pm)
It already does that, or it should anyway. Are you using a demo? Which one?

AFX is a special effects choreography sub-system which needs to be added onto Torque, so I doubt you'll find anything like it's capabilities for free. There is a resource here that describes how to create some basic spell-like weapons that make use of the existing particle effect systems, and there is this: Very simple "spell casting", and there is another "Spell System" which requires access to the source code in order to use it.
#2
04/29/2009 (3:56 pm)
yes i am using a demo. i am using 1.5.2. i know that 1.3 or 1.4 i don't remember has it when you do that online thing but when you press f11 it goes away but i only have 1.5.2 and i don't know how to make it even appear on my on accord

i was wondering more about a health and /or a mana bar of some sort for when i am just messing around on the demos i have made
#3
04/30/2009 (7:56 pm)
You'll need to add a health bar GUI Control to your playGui.gui since the demo doesn't seem to have one.
new GuiHealthBarHud() 
{
    profile = "GuiDefaultProfile";
    horizSizing = "right";
    vertSizing = "top";
    position = "14 315";
    extent = "26 138";
    minExtent = "8 8";
    visible = "1";
    helpTag = "0";
    showFill = "1";
    displayEnergy = "0";
    showFrame = "1";
    fillColor = "0.000000 0.000000 0.000000 0.500000";
    frameColor = "0.000000 1.000000 0.000000 0.000000";
    damageFillColor = "0.800000 0.000000 0.000000 1.000000";
    pulseRate = "1000";
    pulseThreshold = "0.5";
    value = "1";
};

See that field that says displayEnergy = "0" ? If you change that to a 1 then it will display the amount of energy instead of health, but you'll want to change the damageFillColor also.
new GuiHealthBarHud() 
{
    profile = "GuiDefaultProfile";
    horizSizing = "right";
    vertSizing = "top";
    position = "53 315";
    extent = "26 138";
    minExtent = "8 8";
    visible = "1";
    helpTag = "0";
    showFill = "1";
    displayEnergy = "1";
    showFrame = "1";
    fillColor = "0.000000 0.000000 0.000000 0.500000";
    frameColor = "0.000000 1.000000 0.000000 0.000000";
    damageFillColor = "0.000000 0.000000 0.800000 1.000000";
    pulseRate = "1000";
    pulseThreshold = "0.5";
    value = "1";
};

Adding both of those before the closing brace in your playGUI, "~/client/ui/playGui.gui will give you a health and energy bar in the bottomw left corner of the screen. Alternatively you can open up the GUI editor (F10) and add the gui controls from inside the game.

You will probably find the GUI Documentation, and the TDN GUI/Getting Started page to be of benefit to learn more about the GUI system in Torque.
#4
05/01/2009 (1:37 pm)
thank you for all the help,but i still have a few questions

i used your directions and was able to create a health bar from inside the game but i don't know where to save it so when ever i load that mission it is always there

how can i use energy. the energy is always a full bar and i don't know how to use or diminish my "energy". what type of energy

i have just recently downloaded a torsion demo but do not know how to write scripts so that it will do anything is there any tutorials you know of that i could use or you could explain. i would like to use torsion for the health bar and the simple spells but i don't know really how to use it
#5
05/02/2009 (3:36 pm)
i was also wondering if i am able to tweak the settings of the game without the plastic tweaker
#6
05/02/2009 (3:49 pm)
Some settings yes. Many graphics, audio, network, and control options can be exposed to the options dialog for quick updating and tweaking in game. Datablock fields for objects on the other hand are a whole other beast and aren't out-of-the-box tweakable in realtime due to the nature of how datablocks are loaded and networked at mission start.

There have been a few ease of datablock tweaking tools over Torque's history, some of which were never released or revealed, the Plastic Tweaker was just another one that for the most part got it right. Do I use it? No. I still manually edit script files, load the game, test, exit, and repeat.
#7
05/02/2009 (4:27 pm)
"i used your directions and was able to create a health bar from inside the game but i don't know where to save it so when ever i load that mission it is always there

how can i use energy. the energy is always a full bar and i don't know how to use or diminish my "energy". what type of energy

i have just recently downloaded a torsion demo but do not know how to write scripts so that it will do anything is there any tutorials you know of that i could use or you could explain. i would like to use torsion for the health bar and the simple spells but i don't know really how to use it"


....any answers?
#8
05/02/2009 (4:52 pm)
Things like the health/energy bars and any other HUD's you would want to the player to always see would go into the playGui.gui located in the "~/client/ui" directory. Pop-up and/or mission specific GUI elements/HUD's can go into their own file(s), but you would need to write the logic that controls that.

Off-hand I don't think that there is anything directly tied into using energy. So yeah that bar will always be full. You can make the player use energy for various actions in the playerbody datablock:
runEnergyDrain = 0;
jumpEnergyDrain = 0;
Those are currently set to 0 but can be changed as you wish. You can also make weapons use energy, or set up something like player shields or vehicle energy -- but that should come later once you have a better understanding.

I don't use Torsion, can't offer any insight there, but if you're wanting to learn some basics about scripting you should check out the TGE Documentation, truthfully I don't know of too many tutorials, but in the beginning I found the CodeSampler.com tutorials to be useful. I self-taught myself TorqueScript from the examples in front of me -- that and incorporating the script resources available here.
#9
05/03/2009 (11:38 am)
is there a way of changing the player datablock from inside the game so i can change the players run and jump energy drain to actually use the energy?
#10
05/03/2009 (2:29 pm)
when i select the the orc character in the demo when i am in inspector i go to dynamic field and add in jumpEnergyDrain and set it to .4 (and other whole numbers and non whole numbers)but it doesn't to anything (i am assuming what i am doing this completely wrong)i don't know how to alter the player datablock from inside the game to make it so that jumping and/or running reduces the energy from the energy bar which i was able to create from inside the game
#11
05/03/2009 (5:39 pm)
never mind i was able have the energy drained when the orc character jumped using torsion(taught myself kinda =p) but i still couldnt do it from inside the game
#12
05/03/2009 (8:47 pm)
Ok, at least you got it :) You can't modify the datablocks in-game -- there's no editor/interface built in for it. It may seem tedious but due to the way in which datablocks are networked and loaded for each mission it can't/shouldn't be done without something like the Plastic Tweaker. Try a search for datablock editor, I think there was a resource that let you tweaked vehicles and/or players in-game but if I remember correctly it didn't work 100%.

You can reload/exec your script files from the console if you want to try that route, but I wouldn't recommend it. You should also be aware that datablocks are just structures that an object will reference. If you change the datablock then all objects referencing that datablock will be affected by those changes. What you were doing in the editor with a player's dynamic fields is an object method not a datablock method.
#13
05/05/2009 (10:16 am)
still a few more questions lol

part 1:is there a way of making a breath bar (slowly degenerates to 0 from 100% in about 45 seconds)appear when the orc is completely submerged in water. then after about 45 seconds the bar has been drained to zero and this triggers the orc to die? (if possible is this way to complicated?)

part 2: do you know of any GOOD resources on swimming (i want to make it so the orc character doesn't just walk on the bottom because this looks stuiped)i cant find any that are good and obviously i am a beginner and i don't know anything about scripting and about adding swimming motions into the game......
#14
05/05/2009 (10:21 am)
oh yeah i was able to save the health bar and energy bar HUD's so they always appear. i messed around with the player data block script a little to learn a little more about script
#15
05/05/2009 (12:03 pm)
I wrote a drowning script one time but never did up a scripted breath meter. In script I think you could probably do up a countdown HUD easier than you could a timed-meter, does the demo you're using have the racing.starter in it? That has a good example of a countdown clock that was done in script.

I know it's possible to modify the source code and create a new GUI control just for that, and they're several resources for that -- but you wouldn't be able to have access to any of that.

It's the same problem with swimming, you'll have to modify the source code to really make that work well. There's a resource called FPS Swimming, I think, that works great for swimming. Another problem is that even when add the swimming code the player model still needs a swim animation, otherwise he just flies through the water.

I'll go ahead and show you how to drown someone after 'X' amount of time. All of these changes will need to be made to the player.cs file. I've tried to explain it step by step so you can learn from and understand how this script code works.

Add this to the top of the file:
$UnderwaterDamage = 5;   // damage done every $UnderwaterCheckTime ms if the player is underwater
$UnderwaterInitTime = 10000;   // initial time before the player gets damage
$UnderwaterCheckTime = 1000;   // time to check underwater status (ms)

Next you'll need to add something to start the scheduling of a "checkUnderwater" function. Add this schedule to the end of function Armor::onEnterLiquid:
$Drowning::Schedule = schedule($UnderwaterInitTime, 0, "checkUnderwater", %obj);
What that does is when you enter the water it schedules a "checkUnderwater" function after you've been in the water for more than the time set in the InitTime variable.

Now you need a way of canceling the "checkUnderwater" function if you leave the water. Add this to the end of function Armor::onLeaveLiquid:
cancel($Drowning::Schedule);

This is the "checkUnderwater" function that does the work:
function checkUnderwater(%obj)
{
    // Send a ray from the eye point of the player to the sky to see if it crosses a waterblock. 
    // If it does, this means that the player is underwater.  The raycast only returns true if
    // it intersects the water surface.

    if (%obj.getState() $= "Dead")
        cancel($Drowning::Schedule);
    else
    {
        // Let's use a "drowning" damageType so the game will know to 
        // distinguish between a drowning and other types of death.
        %damageType = "Drowning";

        %eye = %obj.getEyePoint();
        %end = VectorAdd(%eye, "0 0 100");
        %searchMasks = $TypeMasks::WaterObjectType;
        if (ContainerRayCast(%eye, %end, %searchMasks))
        {
            // So long as we're still underwater lets increment a holdbreath counter.
            // This simulates the player being able to hold his breath before drowning occurs.
            %obj.holdbreath++;

            // if the holdbreath counter is greater than 20 then hurt the player
            if (%obj.holdbreath > 20)
                %obj.damage(0, %obj.getPosition(), $UnderwaterDamage, %damageType);
        }
        else
            %obj.holdbreath = 0;

        // reschedule the "checkUnderwater" function after 1 second.
        $Drowning::Schedule = schedule(1000, 0, "checkUnderwater", %obj);
    }
}

This last change needs to be made in game.cs in function GameConnection::onDeath(). This is where we tell the game how to handle a drowning death, for this example we're just sending a message. You could optionally affect the score, or anything else you wish to do.

This goes inside the body of the function, before or the if statement that handles suicide type deaths.
if (%damageType $= "Drowning")
{
    messageAll('MsgClientKilled', '%1 drowned!', %this.name);
    return;
}

This is a simple means of handling drowning, and an even simpler method of dealing with damageType messages.


#16
05/05/2009 (12:37 pm)
i know of the demo your talking about with the racing demo but i cant find where to download it i used to have it on my old computer i have the newer demo.
#17
05/05/2009 (1:12 pm)
where do i put this? This is the "checkUnderwater" function that does the work:
view plainprint?

1. function checkUnderwater(%obj)
2. {
3. // Send a ray from the eye point of the player to the sky to see if it crosses a waterblock.
4. // If it does, this means that the player is underwater. The raycast only returns true if
5. // it intersects the water surface.
6.
7. if (%obj.getState() $= "Dead")
8. cancel($Drowning::Schedule);
9. else
10. {
11. // Let's use a "drowning" damageType so the game will know to
12. // distinguish between a drowning and other types of death.
13. %damageType = "Drowning";
14.
15. %eye = %obj.getEyePoint();
16. %end = VectorAdd(%eye, "0 0 100");
17. %searchMasks = $TypeMasks::WaterObjectType;
18. if (ContainerRayCast(%eye, %end, %searchMasks))
19. {
20. // So long as we're still underwater lets increment a holdbreath counter.
21. // This simulates the player being able to hold his breath before drowning occurs.
22. %obj.holdbreath++;
23.
24. // if the holdbreath counter is greater than 20 then hurt the player
25. if (%obj.holdbreath > 20)
26. %obj.damage(0, %obj.getPosition(), $UnderwaterDamage, %damageType);
27. }
28. else
29. %obj.holdbreath = 0;
30.
31. // reschedule the "checkUnderwater" function after 1 second.
32. $Drowning::Schedule = schedule(1000, 0, "checkUnderwater", %obj);
33. }
34. }




and where exactly at the the top do i put

1. $UnderwaterDamage = 5; // damage done every $UnderwaterCheckTime ms if the player is underwater
2. $UnderwaterInitTime = 10000; // initial time before the player gets damage
3. $UnderwaterCheckTime = 1000; // time to check underwater status (ms)


at the top of my file its a bunch of stuff about player death animations
#18
05/05/2009 (2:02 pm)
The checkUnderwater function can go anywhere, I would just keep it near the onLiquid callbacks for convenience, since those two modifications tie into it. The variables can be placed anywhere, just make sure that they are placed before the function itself. Generally if you're going to place a global variable in a script file it's useful (and common practice) to group them at the top so you don't have to go looking for them when you need to modify them.
#19
05/05/2009 (4:24 pm)
i was wondering if you could change the player.cs and game.cs scripts using script above so i can see how to actually change script. i tried and it didnt work(i have never done scripting or any programming ever)so i was wondering if you could just show me how its done if you don't want to you don't have to.

if you are going to i put my version of the player.cs and game.cs scripts from the torque game engine demo 1.5.2 on this wed site(http://djrea4815.webs.com/) if you reply just paste the parts you changes and two lines of the original scripts above and below on each part changed

so that i can see the context that its in so i know where and how it is written
#20
05/05/2009 (4:50 pm)
When you made your changes to the script, did you delete the same-named DSO file? That's one thing that is often overlooked about TGE. If you make changes and you don't remove the generated .dso file the engine loads it automatically and it's like your changes never happened. If the .dso is not found then it loads the changed script and re-compiles a new .dso from it.
Page «Previous 1 2