ItsMods

Full Version: Health Bar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I got a problem with the Health bar,
after you died the Health bar will show a bug what said you have 1 HP left under your current HP.


[Image: fehlert.png]

Quote:hud_health()
{
self endon("disconnect");
self endon("death");
level endon("game_ended");

x = 10;
y = 412;
self.maxwidthsize = 80;
basehealth = self.health;
self.healthperwidth = basehealth/self.maxwidthsize;

self.healthword = newclienthudelem(self);
self.healthword.alignX = "left";
self.healthword.alignY = "middle";
self.healthword.horzAlign = "fullscreen";
self.healthword.vertAlign = "fullscreen";
self.healthword.x = x;
self.healthword.y = y - 12;
self.healthword.alpha = 1;
self.healthword.sort = 2;
self.healthword.fontscale = 1.4;
self.healthword.color = (1,1,1);
self.healthword setText("Health:");

self.healthnum = newclienthudelem(self);
self.healthnum.alignX = "left";
self.healthnum.alignY = "middle";
self.healthnum.horzAlign = "fullscreen";
self.healthnum.vertAlign = "fullscreen";
self.healthnum.x = x + 35;
self.healthnum.y = y - 12;
self.healthnum.alpha = 1;
self.healthnum.sort = 2;
self.healthnum.fontscale = 1.4;
self.healthnum.color = (0,1,0);

self.healthbar = newclienthudelem(self);
self.healthbar.alignX = "left";
self.healthbar.alignY = "middle";
self.healthbar.horzAlign = "fullscreen";
self.healthbar.vertAlign = "fullscreen";
self.healthbar.x = x;
self.healthbar.y = y;
self.healthbar.alpha = 1;
self.healthbar.sort = 2;
self.healthbar.color = (0,1,0);
self.healthbar setShader("white",self.maxwidthsize,6);

self.healthbarback = newclienthudelem(self);
self.healthbarback.alignX = "left";
self.healthbarback.alignY = "middle";
self.healthbarback.horzAlign = "fullscreen";
self.healthbarback.vertAlign = "fullscreen";
self.healthbarback.x = x;
self.healthbarback.y = y;
self.healthbarback.alpha = 0.5;
self.healthbarback.sort = 1;
self.healthbarback.color = (0,0,0);
self.healthbarback setShader("white",self.maxwidthsize,10);

while(1)
{
if(self.sessionstate != "playing" || !isDefined(self.health) || !isDefined(self.maxhealth))
{
self.healthword.alpha = 0;
self.healthnum.alpha = 0;
self.healthbar.alpha = 0;
self.healthbarback.alpha = 0;
self.healthwarning.alpha = 0;
wait 0.05;
continue;
}
self.healthword.alpha = 1;
self.healthnum.alpha = 1;
self.healthbar.alpha = 1;
self.healthbarback.alpha = 0.5;

width = self.health / self.maxhealth * 100;
if(width <= 0)
width = 1;
if (self.health <= basehealth)
{
green = (self.health/basehealth);
red = (1 - green);
self.healthbar.color = (red,green,0);
self.healthnum.color = (red,green,0);
}
else
{
self.healthbar.color = (0,1,0);
self.healthnum.color = (0,1,0);
}
self.healthbar setShader("white", width, 6);
self.healthnum setValue(self.health);
wait 0.05;
}
}


SO anyone can help me with them?

Quote:Steam-> "p2tK"



Where did you add it?
Add it BEFORE loop and waittill spawn
(thread i meant)

And delete a 'self endon("death");'

Code:
onspawn()
{
self endon("disconnect");
// Add it there
for(;;)
{
self waittill("spawned_player");

// DO Not add it there

}
}

It should help :/
Quote:onPlayerSpawned()
{
self endon("disconnect");
self thread hud_health();

Like this?
(10-19-2011, 17:10)p2tk Wrote: [ -> ]
Quote:onPlayerSpawned()
{
self endon("disconnect");
self thread hud_health();

Like this?

yes,
and delete a self endon("death"); in hud_health(); function.
(10-19-2011, 17:11)Se7en Wrote: [ -> ]and delete a self endon("death"); in hud_health(); function.

Why would he...?

@p2tk destroy the HuD element after the player's death.
No, there is 'alpha hide' ( and if self.health is less then 0 )
EDIT: Look at function
RE: Health Bar



[/Quote]:onPlayerSpawned()
{
self endon("disconnect");
self thread hud_health();


Like this?


yes,
and delete a self endon("death"); in hud_health(); function.
[/QUOTE]

This works good, no bug after respawn.

only one is no change color now.. but nvm Big Grin

Thx alot
(10-19-2011, 17:17)Se7en Wrote: [ -> ]No, there is 'alpha hide' ( and if self.health is less then 0 )
EDIT: Look at function

Oh, I didn't see that :p
(10-19-2011, 17:27)Rendflex Wrote: [ -> ]
(10-19-2011, 17:17)Se7en Wrote: [ -> ]No, there is 'alpha hide' ( and if self.health is less then 0 )
EDIT: Look at function

Oh, I didn't see that :p

=____________=
why not just delete after death?
Pages: 1 2