guiHealthTextCtrl -- Display your health and energy as text!
by Robert Pierce · 05/19/2005 (7:16 am) · 16 comments
Download Code File
EDIT 5/14/05: Added examples datablocks.
EDIT 5/15/05: Fixed minor syntax error. Re-uploaded .ZIP file with altered files
EDIT 5/19/05: It appears the resource has been approved!
EDIT 5/28/05: The GUI control no longer uses a hard coded value of 100.
EDIT 5/31/05: New field (displayMaximum).
EDIT 6/08/05: Fixed a nasty bug that caused the engine to crash, >.<
To use this GUI Control, just download the .ZIP file and extract it to your engine/gui folder if you are using 1.3 or below or extract it to engine/gui/game if you are using 1.3.1 or above. If you are using 1.3.1 or above, make sure you read below where is says Required Changes for TGE 1.3.1+.
After you have made sure the file has been extracted correctly, you should add it to your makefile or project, whichever method is appropriate, and then compile. Most people suggest a Clean Rebuild, to make sure everything is rebuilt, but I will leave that up to you. NOTE: If you are having compile errors (and you don't know what to do), try a Clean Rebuild if you chose not to do so.
REQUIRED CHANGES FOR ANY VERSION OF TGE
In game/shapeBase.h:
Below:
Below:
Below:
REQUIRED CHANGES FOR TGE 1.3.1+
To use this GUI control with TGE 1.3.1 or above, you must make some minor changes.
In guiHealthTextCtrl.cc:
Change:
Change:
I should not be forgetting anything related to TGE 1.3.1+ changes.
To use this control, you just add it in through the WYSIWYG editor in TGE or you can use a text editor to manually place it in a file (client/ui/playGui.gui being the best choice with default configuration).
An important thing to note is that this GUI control functions like guiHealthBarHud. In other words, a dynamic variable called "displayEnergy" set in the datablock decides whether the text displayed is the avatars health or energy.
For example: In the project I am working on, it is used to display health like this:
Also, I did not create a brand new GUI profile for this. In my uses, I used the "HudTextProfile" which gives it a light green that is easily viewable on the colored bars (if they are colored in your uses).
I hope you all enjoy this GUI control. I will be watching for a while to provide support and fix any bugs, :).
Robert Pierce
Lead Programmer
Uber Real Games
EDIT 5/14/05: Added examples datablocks.
EDIT 5/15/05: Fixed minor syntax error. Re-uploaded .ZIP file with altered files
EDIT 5/19/05: It appears the resource has been approved!
EDIT 5/28/05: The GUI control no longer uses a hard coded value of 100.
EDIT 5/31/05: New field (displayMaximum).
EDIT 6/08/05: Fixed a nasty bug that caused the engine to crash, >.<
To use this GUI Control, just download the .ZIP file and extract it to your engine/gui folder if you are using 1.3 or below or extract it to engine/gui/game if you are using 1.3.1 or above. If you are using 1.3.1 or above, make sure you read below where is says Required Changes for TGE 1.3.1+.
After you have made sure the file has been extracted correctly, you should add it to your makefile or project, whichever method is appropriate, and then compile. Most people suggest a Clean Rebuild, to make sure everything is rebuilt, but I will leave that up to you. NOTE: If you are having compile errors (and you don't know what to do), try a Clean Rebuild if you chose not to do so.
REQUIRED CHANGES FOR ANY VERSION OF TGE
In game/shapeBase.h:
Below:
F32 getDamageValue();Add:
F32 getMaxDamage();F32 getMaxEnergy();In game/shapeBase.cc:
Below:
F32 ShapeBase::getDamageValue()
{
// Return a 0-1 damage value.
return mDamage / mDataBlock->maxDamage;
} Add: F32 ShapeBase::getMaxDamage()
{
return mDataBlock->maxDamage;
}
F32 ShapeBase::getMaxEnergy()
{
return mDataBlock->maxEnergy;
}OPTIONALBelow:
ConsoleMethod( ShapeBase, getDamageLevel, F32, 2, 2, "")
{
return object->getDamageLevel();
} Add: ConsoleMethod( ShapeBase, getMaxDamage, F32, 2, 2, "")
{
return object->getMaxDamage();
}
ConsoleMethod( ShapeBase, getMaxEnergy, F32, 2, 2, "")
{
return object->getMaxEnergy();
}REQUIRED CHANGES FOR TGE 1.3.1+
To use this GUI control with TGE 1.3.1 or above, you must make some minor changes.
In guiHealthTextCtrl.cc:
Change:
#include "gui/guiHealthTextCtrl.h"To:
#include "gui/game/guiHealthTextCtrl.h"Change:
GameConnection* conn = GameConnection::getServerConnection();To:
GameConnection* conn = GameConnection::getConnectionToServer();In guiHealthTextCtrl.h:
Change:
#include "gui/guiTypes.h"To:
#include "gui/core/guiTypes.h"Change:
#include "gui/guiTypes.h"To:
#include "gui/core/guiTypes.h"
I should not be forgetting anything related to TGE 1.3.1+ changes.
To use this control, you just add it in through the WYSIWYG editor in TGE or you can use a text editor to manually place it in a file (
An important thing to note is that this GUI control functions like guiHealthBarHud. In other words, a dynamic variable called "displayEnergy" set in the datablock decides whether the text displayed is the avatars health or energy.
For example: In the project I am working on, it is used to display health like this:
new GuiHealthTextCtrl(Health) {
profile = "HudTextProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "16 368";
extent = "16 28";
minExtent = "8 8";
visible = "1";
displayEnergy = "0";
helpTag = "0";
};It is used to display energy like this: new GuiHealthTextCtrl(Energy) {
profile = "HudTextProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "48 368";
extent = "20 28";
minExtent = "8 8";
visible = "1";
displayEnergy = "1";
helpTag = "0";
};As you will notice, the example for health has the "displayEnergy" variable set to "0", meaning it doesn't display the energy. Also, the second example, the example for energy has the "displayEnergy" variable set to "1", meaning it does display energy.Also, I did not create a brand new GUI profile for this. In my uses, I used the "HudTextProfile" which gives it a light green that is easily viewable on the colored bars (if they are colored in your uses).
I hope you all enjoy this GUI control. I will be watching for a while to provide support and fix any bugs, :).
Robert Pierce
Lead Programmer
Uber Real Games
#2
I have gone through 4 health text display tutorial/mods and everyone hard codes the max to 100.
No one seems to know how to get the maxDamage in the engine (not script).
If this wasn't hard coded to 100, it wouldn't be just another (broken) text health indicator.
But it is.
Nice deploy though.
Ari
05/22/2005 (3:52 am)
I'm so angry.I have gone through 4 health text display tutorial/mods and everyone hard codes the max to 100.
No one seems to know how to get the maxDamage in the engine (not script).
If this wasn't hard coded to 100, it wouldn't be just another (broken) text health indicator.
But it is.
Nice deploy though.
Ari
#3
I hope you get this, since this resource should no longer be "just another (broken) text health indicator".
I updated this today (since I had freetime), and 100 is no longer hard coded. I decided to hard code the value of 100 since I was too lazy to add a few methods here and there.
Anyway, there is a new method added to ShapeBase and a new ConsoleMethod. With these, 100 does not need to be hardcoded.
I did notice that once the maxDamage member is set near 5000000, this starts getting screwy.
I will be updating this resource and re-uploading the files within 10 minutes of when I make this post.
EDIT: Resource and .ZIP file updated.
Robert
05/28/2005 (7:36 pm)
@Ari:I hope you get this, since this resource should no longer be "just another (broken) text health indicator".
I updated this today (since I had freetime), and 100 is no longer hard coded. I decided to hard code the value of 100 since I was too lazy to add a few methods here and there.
Anyway, there is a new method added to ShapeBase and a new ConsoleMethod. With these, 100 does not need to be hardcoded.
I did notice that once the maxDamage member is set near 5000000, this starts getting screwy.
I will be updating this resource and re-uploading the files within 10 minutes of when I make this post.
EDIT: Resource and .ZIP file updated.
Robert
#4
I decided to add a "novelty" feature.
This new feature is the ability to display the maximum health/energy in the format of/. Example: Say you have 60 health left, out of 200 health, it would render as 60/200.
I will be updating this resource and re-uploading the files withing 10 minutes of when I make this post.
EDIT: Finished editing and uploading.
Robert
05/31/2005 (3:34 pm)
Update!I decided to add a "novelty" feature.
This new feature is the ability to display the maximum health/energy in the format of
I will be updating this resource and re-uploading the files withing 10 minutes of when I make this post.
EDIT: Finished editing and uploading.
Robert
#5
I fixed it all now, so it works!
NOTE: There are limits, but it should still be usable if your values are reasonable.
Robert
06/08/2005 (11:01 pm)
I just noticed I made a big mistake when I added the Maximum display ability. I forgot to make a variable larger, therefore making the engine crash when it couldn't properly unload the data in memory.I fixed it all now, so it works!
NOTE: There are limits, but it should still be usable if your values are reasonable.
Robert
#6
This isn't my resource but I find comments like this very disturbing. Most of these resources were designed for the original creators purpose and give a leg up to people who need something similar and can modify them for their particular task. Robert went through the trouble of sharing some of his work and you blast it because it doesnt meet you needs? If you are doing MMOG development and are the lead programmer you should be able to go in and change the code to meet your specifications.
06/09/2005 (8:04 am)
@AriQuote:If this wasn't hard coded to 100, it wouldn't be just another (broken) text health indicator. But it is.
This isn't my resource but I find comments like this very disturbing. Most of these resources were designed for the original creators purpose and give a leg up to people who need something similar and can modify them for their particular task. Robert went through the trouble of sharing some of his work and you blast it because it doesnt meet you needs? If you are doing MMOG development and are the lead programmer you should be able to go in and change the code to meet your specifications.
#7
Heheh, just needed a little push.
You're my new hero. :)
Thanks tons, the maxDamage thing was killing me.
This is NOT just another text health display!
All the others I have seen are hard coded, so this definately is a step up.
Nice work, you just made my morning!
@Todd:
I'm eating these words while I'm posting: "If this wasn't hard coded to 100, it wouldn't be just another (broken) text health indicator. But it is."
Also, I'm not the only programmer who had the problem or else they wouldn't all be coded at 100.
It was a post designed to "push" the coder since it was fresh in his head.
Ari Rule
06/11/2005 (10:47 am)
@Robert:Heheh, just needed a little push.
You're my new hero. :)
Thanks tons, the maxDamage thing was killing me.
This is NOT just another text health display!
All the others I have seen are hard coded, so this definately is a step up.
Nice work, you just made my morning!
@Todd:
I'm eating these words while I'm posting: "If this wasn't hard coded to 100, it wouldn't be just another (broken) text health indicator. But it is."
Also, I'm not the only programmer who had the problem or else they wouldn't all be coded at 100.
It was a post designed to "push" the coder since it was fresh in his head.
Ari Rule
#8
I did have fun trying to find the best way (I could think of) for getting the maxDamage datablock value (I wanted to avoid adding extra functions).
Robert
06/11/2005 (10:51 am)
Thinking back, I still have no idea why I hard coded it to 100.I did have fun trying to find the best way (I could think of) for getting the maxDamage datablock value (I wanted to avoid adding extra functions).
Robert
#9
I thought these were allready in the engine.
No wonder I was going in circles!
Besides making this a great resource you taught me something I was missing in the engine.
Thanks again!
Ari Rule
06/11/2005 (10:59 am)
Aha!I thought these were allready in the engine.
No wonder I was going in circles!
F32 getMaxDamage();F32 getMaxEnergy();and
F32 ShapeBase::getMaxDamage()
{
return mDataBlock->maxDamage;
}
F32 ShapeBase::getMaxEnergy()
{
return mDataBlock->maxEnergy;
}Besides making this a great resource you taught me something I was missing in the engine.
Thanks again!
Ari Rule
#10
Since I am still a Linux noob++, I am not entirely sure what the problem is.
Robert
06/11/2005 (11:12 am)
This is interesting. I just built Torque (with this resource) on my Linux box ([K]Ubuntu distro) and it seems the "displayMaximum" functionality doesn't work the way I expected it to (in Linux).Since I am still a Linux noob++, I am not entirely sure what the problem is.
Robert
#12
Still, I don't have much of an idea why it isn't working exactly like I want it to on Linux, but then again, I haven't really done any Linux programming...
Robert
06/29/2005 (3:10 pm)
That is a nice suggestion, and it would be really cool if it was added to HEAD.Still, I don't have much of an idea why it isn't working exactly like I want it to on Linux, but then again, I haven't really done any Linux programming...
Robert
#13
08/24/2005 (10:16 pm)
Very nice resource. But does anyone get the problem of displaying a 1/1 health text during multiplayer game? With me being the server, I see my health as 100/100, but when other player comes in, they see their health text as 1/1 instead of 100/100. Anyone know the solution to this problem?
#14
Thanks for notifying me about this... I will try to replicate this on a fresh and edited install of TGE.
--Robert
08/25/2005 (2:27 pm)
@Joseph:Thanks for notifying me about this... I will try to replicate this on a fresh and edited install of TGE.
--Robert
#15
The bars always update but sometimes the text bugs out to 1/1.
Any ideas?
Btw, thanks again for this resource.
Ari Rule
08/30/2005 (11:18 pm)
I get the same thing also, happens kind of randomly for me.The bars always update but sometimes the text bugs out to 1/1.
Any ideas?
Btw, thanks again for this resource.
Ari Rule
#16
06/01/2006 (6:02 pm)
me too 
Torque Owner Dreamer
Default Studio Name