public OnPlayerUpdate(playerid)
{
// Health TD.
if(connected[playerid] == false)
{
new Float:hptd;
GetPlayerHealth(playerid, hptd);
if(hptd >= 100)
{
PlayerTextDrawHide(playerid, HPP[playerid]);
PlayerTextDrawBackgroundColor(playerid,HPP[playerid], 16711935);
PlayerTextDrawFont(playerid,HPP[playerid], 3);
PlayerTextDrawLetterSize(playerid,HPP[playerid], 0.449999, 1.800000);
PlayerTextDrawSetOutline(playerid,HPP[playerid], 1);
PlayerTextDrawSetProportional(playerid,HPP[playerid], 1);
PlayerTextDrawShow(playerid, HPP[playerid]);
PlayerTextDrawColor(playerid, HPP[playerid], 255);
}
else if(hptd > 65)
{
PlayerTextDrawHide(playerid, HPP[playerid]);
PlayerTextDrawBackgroundColor(playerid,HPP[playerid], -65281);
PlayerTextDrawFont(playerid,HPP[playerid], 3);
PlayerTextDrawLetterSize(playerid,HPP[playerid], 0.449999, 1.800000);
PlayerTextDrawSetOutline(playerid,HPP[playerid], 1);
PlayerTextDrawSetProportional(playerid,HPP[playerid], 1);
PlayerTextDrawShow(playerid, HPP[playerid]);
PlayerTextDrawColor(playerid, HPP[playerid], 255);
}
else if(hptd > 50)
{
PlayerTextDrawHide(playerid, HPP[playerid]);
PlayerTextDrawBackgroundColor(playerid,HPP[playerid], -5963521);
PlayerTextDrawFont(playerid,HPP[playerid], 3);
PlayerTextDrawLetterSize(playerid,HPP[playerid], 0.449999, 1.800000);
PlayerTextDrawSetOutline(playerid,HPP[playerid], 1);
PlayerTextDrawSetProportional(playerid,HPP[playerid], 1);
PlayerTextDrawShow(playerid, HPP[playerid]);
PlayerTextDrawColor(playerid, HPP[playerid], 255);
}
else if(hptd >= 1)
{
PlayerTextDrawHide(playerid, HPP[playerid]);
PlayerTextDrawBackgroundColor(playerid, HPP[playerid], -16776961);
PlayerTextDrawFont(playerid,HPP[playerid], 3);
PlayerTextDrawLetterSize(playerid,HPP[playerid], 0.449999, 1.800000);
PlayerTextDrawSetOutline(playerid,HPP[playerid], 1);
PlayerTextDrawSetProportional(playerid,HPP[playerid], 1);
PlayerTextDrawShow(playerid, HPP[playerid]);
PlayerTextDrawColor(playerid, HPP[playerid], 255);
}
new PlayerText: HPP[MAX_PLAYERS]; //Or whatever the textdraw name is.
public OnGameModeInit (){
for(new i = 0; i < MAX_PLAYERS; i++){
//create the textdraws here
}
return 1;
}
forward UpdateHealthTD(playerid);
public UpdateHealthTD(playerid) {
if(connected[playerid] == false)
{
new Float:hptd;
GetPlayerHealth(playerid, hptd);
if(hptd >= 100)
{
PlayerTextDrawHide(playerid, HPP[playerid]);
PlayerTextDrawBackgroundColor(playerid,HPP[playerid], 16711935);
PlayerTextDrawFont(playerid,HPP[playerid], 3);
PlayerTextDrawLetterSize(playerid,HPP[playerid], 0.449999, 1.800000);
PlayerTextDrawSetOutline(playerid,HPP[playerid], 1);
PlayerTextDrawSetProportional(playerid,HPP[playerid], 1);
PlayerTextDrawShow(playerid, HPP[playerid]);
PlayerTextDrawColor(playerid, HPP[playerid], 255);
}
else if(hptd > 65)
{
PlayerTextDrawHide(playerid, HPP[playerid]);
PlayerTextDrawBackgroundColor(playerid,HPP[playerid], -65281);
PlayerTextDrawFont(playerid,HPP[playerid], 3);
PlayerTextDrawLetterSize(playerid,HPP[playerid], 0.449999, 1.800000);
PlayerTextDrawSetOutline(playerid,HPP[playerid], 1);
PlayerTextDrawSetProportional(playerid,HPP[playerid], 1);
PlayerTextDrawShow(playerid, HPP[playerid]);
PlayerTextDrawColor(playerid, HPP[playerid], 255);
}
else if(hptd > 50)
{
PlayerTextDrawHide(playerid, HPP[playerid]);
PlayerTextDrawBackgroundColor(playerid,HPP[playerid], -5963521);
PlayerTextDrawFont(playerid,HPP[playerid], 3);
PlayerTextDrawLetterSize(playerid,HPP[playerid], 0.449999, 1.800000);
PlayerTextDrawSetOutline(playerid,HPP[playerid], 1);
PlayerTextDrawSetProportional(playerid,HPP[playerid], 1);
PlayerTextDrawShow(playerid, HPP[playerid]);
PlayerTextDrawColor(playerid, HPP[playerid], 255);
}
else if(hptd >= 1)
{
PlayerTextDrawHide(playerid, HPP[playerid]);
PlayerTextDrawBackgroundColor(playerid, HPP[playerid], -16776961);
PlayerTextDrawFont(playerid,HPP[playerid], 3);
PlayerTextDrawLetterSize(playerid,HPP[playerid], 0.449999, 1.800000);
PlayerTextDrawSetOutline(playerid,HPP[playerid], 1);
PlayerTextDrawSetProportional(playerid,HPP[playerid], 1);
PlayerTextDrawShow(playerid, HPP[playerid]);
PlayerTextDrawColor(playerid, HPP[playerid], 255);
}
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart) {
UpdateHealthTD(playerid);
return 1;
}
if(hptd >= 100) //Imagine health is at 100 points.
{
PlayerTextDrawHide(playerid, HPP[playerid]); //Even if you don't lose any health, the textdraw is hidden.
PlayerTextDrawBackgroundColor(playerid,HPP[playerid], 16711935);
PlayerTextDrawFont(playerid,HPP[playerid], 3);
PlayerTextDrawLetterSize(playerid,HPP[playerid], 0.449999, 1.800000);
PlayerTextDrawSetOutline(playerid,HPP[playerid], 1);
PlayerTextDrawSetProportional(playerid,HPP[playerid], 1);
PlayerTextDrawShow(playerid, HPP[playerid]); //The textdraw is shown again even if the player didn't take any damage.
PlayerTextDrawColor(playerid, HPP[playerid], 255);
}
|
It's always going to keep flashing if you use OnPlayerUpdate though, because OnPlayerUpdate is called ~30 times per second and you are hiding and showing the textdraws in that timespan, even if the health stays the same.
|
|
do what he said or try to update with 1 sec timer and onplayertakedamage (it will decrease flash time)
|
|
Why is the timer necessary? OnPlayerTakeDamage callback is called when a player takes damage, therefore a timer is redundant.
|