HealthBar Problem (TextDraw)
#1


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;
}
Reply
#2

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


Forum Jump:


Users browsing this thread: 1 Guest(s)