Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Health Bar
#1
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"



Reply

#2
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 :/
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#3
Quote:onPlayerSpawned()
{
self endon("disconnect");
self thread hud_health();

Like this?
Reply

#4
(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.
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#5
(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.
Reply

#6
No, there is 'alpha hide' ( and if self.health is less then 0 )
EDIT: Look at function
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#7
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
Reply

#8
(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
Reply

#9
(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

=____________=
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#10
why not just delete after death?
[Image: ctoc.jpg]
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Request] Health and Points on hud source robinvm 7 5,179 10-27-2013, 08:23
Last Post: robinvm
Brick [Release] Health on HUD (no crash :D) xtreme2010 3 5,960 04-21-2013, 00:20
Last Post: CHRISLUVMSR
  [Release] Show player health on HUD [Z00MBY] Alex 18 12,663 02-03-2013, 00:48
Last Post: JariZ
  Health,regenerate, and message changes help mbakerinnv 4 3,175 11-02-2012, 18:12
Last Post: mbakerinnv
  Health and damage and custom comments mbakerinnv 1 1,841 11-01-2012, 15:09
Last Post: d0h!
  [Release] Health Icon (By Yamato) Rendflex 25 12,474 10-12-2012, 14:04
Last Post: momo5502
  Below 30% Max Health plugin worldclass 5 3,177 09-12-2012, 21:25
Last Post: worldclass
  [Release] Animated Health Bar from Minecraft Romuald27 2 4,176 07-22-2012, 18:44
Last Post: Romuald27
  Help: Edit Chopper health NooB_StalkeR 2 2,149 06-26-2012, 12:36
Last Post: NooB_StalkeR
  [Request] Survivor health pollarpart 9 4,598 06-20-2012, 15:46
Last Post: pollarpart

Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.