HealthBar Problem (TextDraw) - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: HealthBar Problem (TextDraw) (
/showthread.php?tid=114655)
HealthBar Problem (TextDraw) -
odyvan - 20.12.2009
![](http://s16.radikal.ru/i190/0912/bf/aa032e22c1e5.jpg)
Good day, on one server sa-mp, I saw an excellent indicator of HP, when you try to implement similar I am having errors due to which the script is not working properly, the old number remains in the new HP, that is not removed, help please and sorry for my English)
-
Код:
#include <a_samp>
new Text:hpbar[MAX_PLAYERS];
public OnFilterScriptInit()
{
for(new i; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
OnPlayerConnect(i);
}
}
return 1;
}
public OnFilterScriptExit()
{
for(new i; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
TextDrawDestroy(hpbar[i]);
}
}
return 1;
}
public OnPlayerConnect(playerid)
{
hpbar[playerid] = TextDrawCreate(558.000000,67.000000,"100 hp");
TextDrawAlignment(hpbar[playerid],0);
TextDrawBackgroundColor(hpbar[playerid],0x000000ff);
TextDrawFont(hpbar[playerid],1);
TextDrawLetterSize(hpbar[playerid],0.299999,0.799999);
TextDrawColor(hpbar[playerid],0xffffffff);
TextDrawSetOutline(hpbar[playerid],1);
TextDrawSetProportional(hpbar[playerid],1);
TextDrawSetShadow(hpbar[playerid],1);
return 1;
}
public OnPlayerDisconnect(playerid)
{
TextDrawDestroy(hpbar[playerid]);
return 1;
}
public OnPlayerDeath(playerid)
{
TextDrawHideForPlayer(playerid,hpbar[playerid]);
return 1;
}
public OnPlayerSpawn(playerid)
{
TextDrawSetString(hpbar[playerid],"100 hp");
TextDrawShowForPlayer(playerid,hpbar[playerid]);
return 1;
}
forward OnPlayerUpdate(playerid);
public OnPlayerUpdate(playerid)
{
new Float:hp;
new string[255];
GetPlayerHealth(playerid, hp);
format(string,255,"%.0f hp",hp);
TextDrawSetString(hpbar[playerid],string);
return 1;
}
Re: HealthBar Problem (TextDraw) -
LarzI - 20.12.2009
Try this:
pawn Код:
public OnPlayerUpdate(playerid)
{
new Float:hp;
new string[255];
GetPlayerHealth(playerid, hp);
format(string,255,"%.0f hp",hp);
TextDrawHideForPlayer(playerid, hpbar[playerid]);
TextDrawSetString(hpbar[playerid],string);
TextDrawShowForPlayer(playerid, hpbar[playerid]);
return 1;
}
I had a similar problem before, but this fixed it.