2 registered members (dr_panther, 7th_zorro),
1,203
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Bahh, dunno whats wrong
#359973
02/20/11 23:09
02/20/11 23:09
|
Joined: Apr 2009
Posts: 141
dakilla
OP
Member
|
OP
Member
Joined: Apr 2009
Posts: 141
|
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.
One day there will be an unfixable bug, That day is not today.
|
|
|
Re: Bahh, dunno whats wrong
[Re: dakilla]
#360158
02/22/11 14:45
02/22/11 14:45
|
Joined: Jan 2011
Posts: 65
reknak
Junior Member
|
Junior Member
Joined: Jan 2011
Posts: 65
|
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!
Last edited by reknak; 02/22/11 21:17. Reason: added BMAP*
|
|
|
Re: Bahh, dunno whats wrong
[Re: reknak]
#360171
02/22/11 16:14
02/22/11 16:14
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
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!
Last edited by Richi007; 02/22/11 16:15. Reason: Small code correction
|
|
|
Re: Bahh, dunno whats wrong
[Re: MasterQ32]
#360236
02/22/11 21:14
02/22/11 21:14
|
Joined: Jan 2011
Posts: 65
reknak
Junior Member
|
Junior Member
Joined: Jan 2011
Posts: 65
|
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
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|