Custom Healthbar -
Dynamic - 04.09.2013
Hey gents,
Basically I'm working on a custom health system which should be having his own bar, I'm so far that I have my own bar and what I am trying to script is that the bar goes down when for example the health is 90, 80, 70 etc.. Although I've been scripting it but I am getting NO WAY to get it work so please help me out on this one.
Код:
public OnPlayerSpawn(playerid)
{
new Bar:life = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 100.0);
ShowProgressBarForAll(life);
GetPlayerHealth(playerid,health);
if (health < 90.0)
{
SetProgressBarValue(life, 90.0);
UpdateProgressBar(life, playerid);
}
if (health < 80.0)
{
SetProgressBarValue(life, 80.0);
UpdateProgressBar(life, playerid);
}
if (health < 70.0)
{
SetProgressBarValue(life, 70.0);
UpdateProgressBar(life, playerid);
}
if (health < 60.0)
{
SetProgressBarValue(life, 60.0);
UpdateProgressBar(life, playerid);
}
if (health < 50.0)
{
SetProgressBarValue(life, 50.0);
UpdateProgressBar(life, playerid);
}
if (health < 40.0)
{
SetProgressBarValue(life, 40.0);
UpdateProgressBar(life, playerid);
}
if (health < 30.0)
{
SetProgressBarValue(life, 30.0);
UpdateProgressBar(life, playerid);
}
if (health < 20.0)
{
SetProgressBarValue(life, 20.0);
UpdateProgressBar(life, playerid);
}
if (health < 10.0)
{
SetProgressBarValue(life, 10.0);
UpdateProgressBar(life, playerid);
}
if (health < 5.0)
{
SetProgressBarValue(life, 0.0);
UpdateProgressBar(life, playerid);
}
return 1;
}
Another attempt:
Код:
public OnPlayerSpawn(playerid)
{
new Bar:a = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 100.0);
new Bar:b = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 90.0);
new Bar:c = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 80.0);
new Bar:d = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 70.0);
new Bar:e = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 60.0);
new Bar:f = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 50.0);
new Bar:g = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 40.0);
new Bar:h = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 30.0);
new Bar:i = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 20.0);
new Bar:j = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 10.0);
new Bar:k = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 5.0);
ShowProgressBarForAll(a);
GetPlayerHealth(playerid,health);
if (health < 90.0)
{
HideProgressBarForAll(a);
ShowProgressBarForAll(b);
UpdateProgressBar(b, playerid);
}
if (health < 80.0)
{
HideProgressBarForAll(b);
ShowProgressBarForAll©;
UpdateProgressBar(c, playerid);
}
if (health < 70.0)
{
HideProgressBarForAll©;
ShowProgressBarForAll(d);
UpdateProgressBar(d, playerid);
}
if (health < 60.0)
{
HideProgressBarForAll(d);
ShowProgressBarForAll(e);
UpdateProgressBar(e, playerid);
}
if (health < 50.0)
{
HideProgressBarForAll(e);
ShowProgressBarForAll(f);
UpdateProgressBar(f, playerid);
}
if (health < 40.0)
{
HideProgressBarForAll(f);
ShowProgressBarForAll(g);
}
if (health < 30.0)
{
HideProgressBarForAll(g);
ShowProgressBarForAll(h);
}
if (health < 20.0)
{
HideProgressBarForAll(h);
ShowProgressBarForAll(i);
}
if (health < 10.0)
{
HideProgressBarForAll(i);
ShowProgressBarForAll(j);
}
if (health < 5.0)
{
HideProgressBarForAll(j);
ShowProgressBarForAll(k);
}
return 1;
}
Thanks in advance! This has really been a pain in the ass for me and I do NOT understand why it is not working. :<
Re: Custom Healthbar -
Isolated - 04.09.2013
What's not working about it?
Just out of interest, try this code.
pawn Код:
// Out of callback
new Bar: Life[MAX_PLAYERS];
public OnPlayerSpawn(playerid)
{
Life[playerid] = CreateProgressBar(547.00, 53.00, 59.50, 8.19, 1735555583, 100.0);
ShowBarForPlayer(playerid, Life[playerid]);
new Float: Health;
GetPlayerHealth(playerid, Health);
SetProgressBarValue(Life[playerid], Health)
UpdateProgressBar(Life[playerid], playerid);
return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
new Float: Health;
SetProgressBarValue(Life[playerid], GetPlayerHealth(playerid, Health) - amount);
UpdateProgressBar(Life[playerid], playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
DestroyProgressBar(Life[playerid]);
return 1;
}
Re: Custom Healthbar -
Dynamic - 04.09.2013
Well, just like yours .. If I get hit once the bar goes all the way empty and then doesn't function anymore. It doesn't update properly apparantly.
Re: Custom Healthbar -
Pottus - 04.09.2013
Get the Player progress bar include your using a old version, another thing is you want to always add some values to the progress bar there is a problem with very low values and the left border.
Re: Custom Healthbar -
Dynamic - 04.09.2013
I've downloaded the include today from this thread:
https://sampforum.blast.hk/showthread.php?tid=113443
I've downloaded ofcourse the new version, although maybe there's another one? I don't know.
And yes, I've noticed the issue with low values too, for example: If I lose 10HP I lose the entire bar and it does not function anymore after..
Thanks in advance for your help guys.
Re: Custom Healthbar -
Pottus - 04.09.2013
You should use this version of it.
https://gist.github.com/Southclaw/5979661