Thread: Health bar
View Single Post
  #2  
Old 11-03-2011, 02:35 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Quote:
Originally Posted by callimuc View Post
Well I´m trying to make a health bar in a gani. I was looking around the forums for help and my result was this:

PHP Code:
SCRIPT
function onPlayerEnters() {
  
hideimgs(2003000);
  
temp.pl findplayer(player.account);
  
with (findimg(200)) {
    
player.2/16;
    
player.1.75;
    
image "pirate_healthbar.png";
    
width maxWidth;
    
height maxHeight;
    
attachtoowner true;
  }
  
with (findimg(201+pl.id)) {
    
player.10/16;
    
player.1.75 3/16;
    
image "pirate_healthbar-progress.png";
    
width getimgwidth(image);
    
height getimgheight(image);
    
attachtoowner true;
  }
  
part=(pl.clientr.health_hearts/pl.clientr.health_fullhearts)*findimg(201+pl.id).width;
  
changeimgpart(201+pl.idfindimg(201+pl.id).width-part0partfindimg(201+pl.id).height); 
}
SCRIPTEND 
I know it´s not updating constantly but thats not my problem. My problem is that it shows the clients hp in the correct form. But the bar at the other players keeps saying that the player has 100% health even when it´s not true.

How can I fix it?
There are atleast 2 key problems here.

First, you cannot read clientr. variables of other players on your own client. This is where health would need to be stored as part of an attribute.
So essentially this is attempting to show a bar with 0 width, which actually shows the entire bar and makes it look as if it's 100% full.

The second problem is that even if you had HP working properly you don't seem to have a mechanism for updating the display upon HP being changed, unless you're just re-initialising the gani as part of the attribute upon players being damaged?

On a side note it is pointless to be doing pl = findplayer(player.account); as you already have the player object. You also do not need to be referring to pl.id as part of the display index as these displays are on the gani attribute of each player and cannot collide. This also means you do not need to be doing hideimgs(200, 3000); .
Reply With Quote