Quote:
Originally Posted by callimuc
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(200, 3000); temp.pl = findplayer(player.account); with (findimg(200)) { x = player.x + 2/16; y = player.y - 1.75; image = "pirate_healthbar.png"; width = maxWidth; height = maxHeight; attachtoowner = true; } with (findimg(201+pl.id)) { x = player.x + 10/16; y = player.y - 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.id, findimg(201+pl.id).width-part, 0, part, findimg(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); .