Adding another HealthBar type. Is it difficult?
by Stefan Lundmark · in Torque Game Engine · 03/10/2004 (8:58 am) · 14 replies
Hello everyone
I've been around for quite some time now, and done some C++ and alot of script.
What I was trying to do today was to add another bar like the ones already there, health and energy.
I looked around in the guihealthbar files, created two new booleans for health and experience, to be able to switch them off and on. All this worked great, but later I discovered I need to dig into shapebase data and that's where I got confused.
There were so many values I got lost immediatly.
Am I going too deep now or is it more simple than it seems?
Any pointers and/or examples would be greatly appreciated.
I've been around for quite some time now, and done some C++ and alot of script.
What I was trying to do today was to add another bar like the ones already there, health and energy.
I looked around in the guihealthbar files, created two new booleans for health and experience, to be able to switch them off and on. All this worked great, but later I discovered I need to dig into shapebase data and that's where I got confused.
There were so many values I got lost immediatly.
Am I going too deep now or is it more simple than it seems?
Any pointers and/or examples would be greatly appreciated.
About the author
#2
Did you read my full post, mate? :P
It calls for stuff inside the shapebase files, such stuff can't be changed by copying the Guihealthbarhud file and renaming.
By copying that one, it will still call to the same files as mHealth or mEnergy, won't it?
You know, it calls maxHealth inside the player files, and that is not even set through the .cc/.h file you mentioned, as far as I know.
Thanks though
03/10/2004 (9:22 am)
Ronald:Did you read my full post, mate? :P
It calls for stuff inside the shapebase files, such stuff can't be changed by copying the Guihealthbarhud file and renaming.
By copying that one, it will still call to the same files as mHealth or mEnergy, won't it?
You know, it calls maxHealth inside the player files, and that is not even set through the .cc/.h file you mentioned, as far as I know.
Thanks though
#3
Assuming you have added this to player.cc, then it will not be difficult to obtain this value through a custom health bar hud instead of health or energy..
Copy that .cc (add to project) and rename it to your class.. then make the changes you need..
03/10/2004 (9:44 am)
So you want players to have an experience value?Assuming you have added this to player.cc, then it will not be difficult to obtain this value through a custom health bar hud instead of health or energy..
Copy that .cc (add to project) and rename it to your class.. then make the changes you need..
#4
Still, this does not answer the posted question.
Although you made me think abit there, would that work?
I mean, there are SO many values in shapebase about player health and how it works it made me confused about what is really needed to do a new bar just showing experience.
I'll try it though, I guess.
03/10/2004 (9:48 am)
WestyStill, this does not answer the posted question.
Although you made me think abit there, would that work?
I mean, there are SO many values in shapebase about player health and how it works it made me confused about what is really needed to do a new bar just showing experience.
I'll try it though, I guess.
#5
I think people are confused why you don't want to add something to shapebase. In order to have a new value to display your going to need to add something, but it doesn't have to be complicated. For instance, if you want to add say an experience meter. You could do the following:
Add to shapebase.h somewhere near mEnergy;
F32 mExperience; // using a float in range 0-1 because easiest to add to new HUD
Add to shapebase.h somewhere with other public function defs:
F32 getExperience() { return mExperience; }
Then just like Westy and Ron said, copy and rename guiHealthBarBud.cc to something like guiExperienceHud.cc. Replace the call to control->getEnergyValue() with a call to control->getExperience(). Build and Run. Add your new control to playgui with the gui editor and you should be good to go. Obviously a float for experience in the range 0-1 probably isn't what you want, but hopefully you get the idea. All the complication that shapebase does with energy is unnecessary.
Of course you'll have to initialize and update experience appropriatly (is this where you are confused?) but you could add a couple consoleMethod's to add experience and call those from script whenevery player kills or accomplishes something.
-Pascal
[Edit] Forgot to mention: If you add a new value, you need to make sure it gets sent from server to client. Take a look at packUpdate and unpackUpdate in player.cc for how to pass values from server->client.
03/11/2004 (8:36 am)
Hi Stefan, I think people are confused why you don't want to add something to shapebase. In order to have a new value to display your going to need to add something, but it doesn't have to be complicated. For instance, if you want to add say an experience meter. You could do the following:
Add to shapebase.h somewhere near mEnergy;
F32 mExperience; // using a float in range 0-1 because easiest to add to new HUD
Add to shapebase.h somewhere with other public function defs:
F32 getExperience() { return mExperience; }
Then just like Westy and Ron said, copy and rename guiHealthBarBud.cc to something like guiExperienceHud.cc. Replace the call to control->getEnergyValue() with a call to control->getExperience(). Build and Run. Add your new control to playgui with the gui editor and you should be good to go. Obviously a float for experience in the range 0-1 probably isn't what you want, but hopefully you get the idea. All the complication that shapebase does with energy is unnecessary.
Of course you'll have to initialize and update experience appropriatly (is this where you are confused?) but you could add a couple consoleMethod's to add experience and call those from script whenevery player kills or accomplishes something.
-Pascal
[Edit] Forgot to mention: If you add a new value, you need to make sure it gets sent from server to client. Take a look at packUpdate and unpackUpdate in player.cc for how to pass values from server->client.
#6
Can this be done in script or does it require source edits?
I did what Ron mentioned, by copying images in the Gui editor (F-10). Obviously it doesn't work.
I'm trying to add an Energy Bar. I'd like to use script, but I can edit the source if needed. I'm not a programmer, but i've got a compiler.
Thanks!
Tony
08/01/2008 (7:50 am)
I realize I'm bumping a four year old thread, but this is where my question belongs...Can this be done in script or does it require source edits?
I did what Ron mentioned, by copying images in the Gui editor (F-10). Obviously it doesn't work.
I'm trying to add an Energy Bar. I'd like to use script, but I can edit the source if needed. I'm not a programmer, but i've got a compiler.
Thanks!
Tony
#7
There's already energy bar functionallity in Torque. Just set the DisplayEnergy boolean to true in your script.
08/01/2008 (8:05 am)
Hi Tony,There's already energy bar functionallity in Torque. Just set the DisplayEnergy boolean to true in your script.
#8
I'm sorry. I'm using my cellphone to post since I have no other internet connection right now.
Maybe I just need to go back and try again. Maybe the player just lost focus?
I'm going to create a new ctrl rather than copy/pasting.
Edit: OK so I started over. I see where the red HitPoints bar has displayEnergy unchecked under Misc.
Where are these variables and booleans defined? In source or script? How is it tied to the player? In player.cs?
So since the blue has displayEnergy checked (=true) then how do I tap into this?
Any guidance is greatly appreciated!!!
EDIT: 2 I tried making a new GuiBitmapCtrl and new GuiHealthBarHud, rather than copy/pasting. It still locks up my mouse buttons. Not the entire mouse (windows cursor still works), just my in game mouse function. I can't turn or fire.
Any help?
Thanks!
Tony
08/01/2008 (8:12 am)
Thanks Stefan. I tried that but it didn't work. It locked my player so that I couldn't use the right mouse button to turn. Is there someplace in player.cs I need to define an energy datablock or something? or maybe change a defaultBind?I'm sorry. I'm using my cellphone to post since I have no other internet connection right now.
Maybe I just need to go back and try again. Maybe the player just lost focus?
I'm going to create a new ctrl rather than copy/pasting.
Edit: OK so I started over. I see where the red HitPoints bar has displayEnergy unchecked under Misc.
Where are these variables and booleans defined? In source or script? How is it tied to the player? In player.cs?
So since the blue has displayEnergy checked (=true) then how do I tap into this?
Any guidance is greatly appreciated!!!
EDIT: 2 I tried making a new GuiBitmapCtrl and new GuiHealthBarHud, rather than copy/pasting. It still locks up my mouse buttons. Not the entire mouse (windows cursor still works), just my in game mouse function. I can't turn or fire.
Any help?
Thanks!
Tony
#9
I had to make all my edits using a text editor, but it worked. I now have three GuiHealthHud bars (one red, green, blue) AND my mouse works.
Nw can anyone tell me how to tie these bars into my player.cs file?
Is it the GuiDefaultProfile that I edit? If so, where is that profile located?
Thanls!
Tony
08/01/2008 (11:17 am)
Apparently there is something wrong with my GUI Editor. Everytime I try to do anything, even just select a ctrl, it corrupts my PlayGui.gui file.I had to make all my edits using a text editor, but it worked. I now have three GuiHealthHud bars (one red, green, blue) AND my mouse works.
Nw can anyone tell me how to tie these bars into my player.cs file?
Is it the GuiDefaultProfile that I edit? If so, where is that profile located?
Thanls!
Tony
#10
Short on time, but you need to understand that a profile is merely a general description of a control, and not the actual description of how your GUI looks like. It simply tells the engine that all of these buttons, that use the same profile, all will have a red color and the Arial font, for instance. It's a common description of non-unique character.
I'm not sure what you're asking. You don't have to edit player.cs to get this working. Are you asking how to set values to your new bars? That you'll have to do trough the engine source (go inside game/fps/ and you'll find the source file in there) or manually pass the value from script, which I do not recommend but it's a good start if you want to get moving.
08/01/2008 (12:15 pm)
Hi again Tony,Short on time, but you need to understand that a profile is merely a general description of a control, and not the actual description of how your GUI looks like. It simply tells the engine that all of these buttons, that use the same profile, all will have a red color and the Arial font, for instance. It's a common description of non-unique character.
I'm not sure what you're asking. You don't have to edit player.cs to get this working. Are you asking how to set values to your new bars? That you'll have to do trough the engine source (go inside game/fps/ and you'll find the source file in there) or manually pass the value from script, which I do not recommend but it's a good start if you want to get moving.
#11
What I was asking in a roundabout way was
How do you affect the bars?
In the game, whn you take damage, the red bar gets shorter. Where is the code for that? I thought it was in player.cs, but it sounds like it may be in C++ source code? Player.cc maybe?
Tony
ps. The reason for my mouse locking error is that I was trying to overwrite playGui.gui while it was being used. To edit playGui.gui, you have to save it as something else, then close TGE and rename it.
08/01/2008 (12:39 pm)
Looks like its time to break out the source code.What I was asking in a roundabout way was
How do you affect the bars?
In the game, whn you take damage, the red bar gets shorter. Where is the code for that? I thought it was in player.cs, but it sounds like it may be in C++ source code? Player.cc maybe?
Tony
ps. The reason for my mouse locking error is that I was trying to overwrite playGui.gui while it was being used. To edit playGui.gui, you have to save it as something else, then close TGE and rename it.
#12
08/01/2008 (1:45 pm)
The GUI is not connected to game mechanics in that way. It wouldn't be very clean, think of a server which has no GUI. Instead, the health bar code "polls" the player each frame for information, and renders the bar as you would expect. All this is done in guiHealthBarHud.cc.
#13
Then I just need to figure out how to draw on them in script.
Where can I find the onDamage(?) code that affects the health bar? Is that a .cc file or a .cs? I'm sure if I could use that as an example I'd be able to the rest myself. My biggest problem is just not knowing where to look for things.
I'll start by really digging into the guiHealthBarHud.cc
Thanks!
Tony
08/01/2008 (4:26 pm)
Thanks for all your help Stefan. I was actually just looking at Dreamer's resource on guiHealthBarHud.cc and it looks surprisingly straight forward to add a field or two (or more).Then I just need to figure out how to draw on them in script.
Where can I find the onDamage(?) code that affects the health bar? Is that a .cc file or a .cs? I'm sure if I could use that as an example I'd be able to the rest myself. My biggest problem is just not knowing where to look for things.
I'll start by really digging into the guiHealthBarHud.cc
Thanks!
Tony
#14
Each frame? 24 times a second? Even when standing still? That seems like a major waste of processor energy. I'm no programmer, so if that's the best way of doing it I'll accept it.
guiHealthBarHud.cc is not commented for a newbie (especially a non-programmer).
I'll open another thread asking for help with it.
Thanks Stefan! I appreciate all the help! I'm making progress.
Tony
08/04/2008 (6:39 am)
Quote:the GuiHealthBar "polls" the player each frame"
Each frame? 24 times a second? Even when standing still? That seems like a major waste of processor energy. I'm no programmer, so if that's the best way of doing it I'll accept it.
guiHealthBarHud.cc is not commented for a newbie (especially a non-programmer).
I'll open another thread asking for help with it.
Thanks Stefan! I appreciate all the help! I'm making progress.
Tony
Associate Ron Yacketta