Posted By: dakilla
Bahh, dunno whats wrong - 02/20/11 23:09
Hey, I have recently been trying to make a simple 3rd person shooter in a simplistic style, everything was going swimmingly until I tried to make a health-bar script. I have pulled my hair out and just dont know what to do, normally i try to work things out myself before posting on any forum, but here is the script:
function healthbar(ENTITY* ent, var healthheight, var maxhealth)
{
VECTOR* temp;
while(1)
{
vec_set(temp, ent.x);
vec_to_screen(temp, camera);
PANEL* healthbar =
{
window(temp.x, temp.y, 20, 5, "windowhealth.png", ent.skill1 / maxhealth * 40, NULL);
flags = SHOW;
}
wait(1);
}
Thanks in advance.
Posted By: reknak
Re: Bahh, dunno whats wrong - 02/22/11 14:45
I don't know what is wrong but I know an way to make a simple healthbar script for players; an variable, window panel + frame panel and a digit panel if you want that too. When you an action/function effects the player health just change healthplayer variable in that action/function.
e.g. what I use in one of my maps:
BMAP* healthbarframe_bmp = "healthbarframe.bmp";
...
var healthplayer = 150;
...
PANEL* first_pan =
{
pos_x = 1077;
pos_y = 919;
layer = 1;
bmap = healthbarframe_bmp;
flags = OVERLAY | SHOW;
}
PANEL* second_pan =
{
window (1080, 919, 65, 25, "healthbar.bmp", healthplayer, 0);
flags = SHOW;
}
PANEL* third_pan =
{
digits (1100, 900, 3, "Arial#15b", 0.667, healthplayer);
flags = SHOW | OUTLINE;
If players regenerate health, you can add this code within a while loop in the main function;
if (healthplayer < 150)
healthplayer += 0.03;
Hope that helps somewhat!
Posted By: MasterQ32
Re: Bahh, dunno whats wrong - 02/22/11 16:14
o don't think that this code really helps him, because you have many errors!
so first think about your code and test it before posting!
corrected:
var healthplayer = 150;
...
PANEL* first_pan =
{
pos_x = 1077; //It works, but only for one screen resolution!
pos_y = 919; //The same here!
//Fix: Function which updates the position
bmap = "healthbarframe_bmp"; //Forgot quotation marks
window (1080, 919, 65, 25, "healthbar.bmp", healthplayer, 0);
//Can be used directly without new panel
digits (1100, 900, 3, "Arial#15b", 0.667, healthplayer);
//Same here
flags = SHOW;
//Refresh isn't needed anymore
layer = 1;
}
//Your snippet:
if (healthplayer < 150)
healthplayer = minv(150,healthplayer + 0.03 * time_step); //Timestep needed because of different frame rates!
Posted By: reknak
Re: Bahh, dunno whats wrong - 02/22/11 21:14
o don't think that this code really helps him, because you have many errors!
, nah it works perfectly with me, maybe I made some spelling errors