PDA

View Full Version : hp td


ivndosos
17/02/2018, 07:46 AM
I have my hp td, It's on onplayerupdate but sometimes it sortof flashes/fades, I cant really explain how

it dissapears and appears but like really really really quick, what causes it?

RogueDrifter
17/02/2018, 08:01 AM
I'd say that's lag if you weren't using any TextDrawHide/show repeatedly somewhere?

GRiMMREAPER
17/02/2018, 08:09 AM
Are you running the server on your own machine (localhost)?

ivndosos
17/02/2018, 08:37 AM
Yeah It's on local host.


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);
}

GRiMMREAPER
17/02/2018, 08:46 AM
Try a different approach. Untested and unsure if it works. Basically, the reason it is flashing is because you're updating the textdraws on OnPlayerUpdate instead of OnPlayerTakeDamage.

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;
}

ivndosos
17/02/2018, 08:51 AM
I didn't want to use it onplayerdamage because this

http://forum.sa-mp.com/showthread.php?t=649877

GRiMMREAPER
17/02/2018, 08:59 AM
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.


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);

}

Mugala
17/02/2018, 09:27 AM
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)

GRiMMREAPER
17/02/2018, 11:20 AM
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.

Mugala
17/02/2018, 11:54 AM
Why is the timer necessary? OnPlayerTakeDamage callback is called when a player takes damage, therefore a timer is redundant.

cuz when he uses SetPlayerHealth, OnPlayerTakeDamage isn't called.

PepsiCola23
17/02/2018, 11:59 AM
he can create something like UpdateHp that updates the textdraw

ivndosos
17/02/2018, 01:58 PM
cuz when he uses SetPlayerHealth, OnPlayerTakeDamage isn't called.

Is it possible to make it call?

Mugala
17/02/2018, 02:12 PM
Is it possible to make it call?

no it's not possible, I already posted what u need to do.
but there is another way, you can use custom function like SetPlayerHealthEx where u'll update a textdraw like OnPlayerTakeDamage.