SA-MP Forums Archive
Problem with Health bar. - 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)
+--- Thread: Problem with Health bar. (/showthread.php?tid=541066)



Problem with Health bar. - alanhutch - 09.10.2014

Hi.
I have created a Health Bar with some colors.
When you have between 100 and 60HP, the color is green, when you have from 60 to 30 HP it's yellow, and from 30 to 0 it's red...
But this does not work, it always show like a yellow bar with 0 HP...
Here's the include of the Bar, and the code.
https://sampforum.blast.hk/showthread.php?tid=113443
pawn Код:
//On OnPlayerConnect:
SetTimer("ProgressBar", 500, 1);
forward ProgressBar();
public ProgressBar() //I prefer not to use OnPlayerUpdate with textdraws
{
    for (new playerid; playerid < MAX_PLAYERS; playerid++) //I recommend foreach(Player, playerid)
    {
    new Float:health;
        GetPlayerHealth(playerid, health);
        if(health == 100 || health >= 60)
        {
        ShowProgressBarForPlayer(phealthsano[playerid]);
        SetProgressBarValue(phealthsano[playerid], health);
        UpdateProgressBar(phealthsano[playerid], playerid);
        HideProgressBarForPlayer(phealthmezzo[playerid]);
        HideProgressBarForPlayer(phealthmalato[playerid]);
        }
        else if(health < 60 || health >= 30)
        {
        ShowProgressBarForPlayer(phealthmezzo[playerid]);
        SetProgressBarValue(phealthmezzo[playerid]);
        UpdateProgressBar(phealthmezzo[playerid], playerid);
        HideProgressBarForPlayer(phealthsano[playerid]);
        HideProgressBarForPlayer(phealthmalato[playerid]);
        }
        else if(health < 30)
        {
        ShowProgressBarForPlayer(phealthmalato[playerid]);
        SetProgressBarValue(phealthmalato[playerid]);
        UpdateProgressBar(phealthmalato[playerid], playerid);
        HideProgressBarForPlayer(phealthsano[playerid]);
        HideProgressBarForPlayer(phealthmezzo[playerid]);
        }
    }
}
Help me please!


Re: Problem with Health bar. - Rudy_ - 09.10.2014

I don't see anything wrong, But try this
pawn Код:
//On OnPlayerConnect:
SetTimer("ProgressBar", 500, 1);
forward ProgressBar();
public ProgressBar() //I prefer not to use OnPlayerUpdate with textdraws
{
    for (new playerid; playerid < MAX_PLAYERS; playerid++) //I recommend foreach(Player, playerid)
    {
    new Float:health;
        GetPlayerHealth(playerid, health);
        if(health == 100 || health >= 60)
        {
        ShowProgressBarForPlayer(phealthsano[playerid]);
        SetProgressBarValue(phealthsano[playerid], health);
        UpdateProgressBar(phealthsano[playerid], playerid);
        HideProgressBarForPlayer(phealthmezzo[playerid]);
        HideProgressBarForPlayer(phealthmalato[playerid]);
        }
        else if(health < 60 || health >= 30)
        {
        ShowProgressBarForPlayer(phealthmezzo[playerid]);
        SetProgressBarValue(phealthmezzo[playerid]);
        UpdateProgressBar(phealthmezzo[playerid], playerid);
        HideProgressBarForPlayer(phealthsano[playerid]);
        HideProgressBarForPlayer(phealthmalato[playerid]);
        }
        else if(health < 30) || health >= 0)
        {
        ShowProgressBarForPlayer(phealthmalato[playerid]);
        SetProgressBarValue(phealthmalato[playerid]);
        UpdateProgressBar(phealthmalato[playerid], playerid);
        HideProgressBarForPlayer(phealthsano[playerid]);
        HideProgressBarForPlayer(phealthmezzo[playerid]);
        }
    }
}



Re: Problem with Health bar. - alanhutch - 09.10.2014

Quote:
Originally Posted by Rudy_
Посмотреть сообщение
I don't see anything wrong, But try this
pawn Код:
//On OnPlayerConnect:
SetTimer("ProgressBar", 500, 1);
forward ProgressBar();
public ProgressBar() //I prefer not to use OnPlayerUpdate with textdraws
{
    for (new playerid; playerid < MAX_PLAYERS; playerid++) //I recommend foreach(Player, playerid)
    {
    new Float:health;
        GetPlayerHealth(playerid, health);
        if(health == 100 || health >= 60)
        {
        ShowProgressBarForPlayer(phealthsano[playerid]);
        SetProgressBarValue(phealthsano[playerid], health);
        UpdateProgressBar(phealthsano[playerid], playerid);
        HideProgressBarForPlayer(phealthmezzo[playerid]);
        HideProgressBarForPlayer(phealthmalato[playerid]);
        }
        else if(health < 60 || health >= 30)
        {
        ShowProgressBarForPlayer(phealthmezzo[playerid]);
        SetProgressBarValue(phealthmezzo[playerid]);
        UpdateProgressBar(phealthmezzo[playerid], playerid);
        HideProgressBarForPlayer(phealthsano[playerid]);
        HideProgressBarForPlayer(phealthmalato[playerid]);
        }
        else if(health < 30) || health >= 0)
        {
        ShowProgressBarForPlayer(phealthmalato[playerid]);
        SetProgressBarValue(phealthmalato[playerid]);
        UpdateProgressBar(phealthmalato[playerid], playerid);
        HideProgressBarForPlayer(phealthsano[playerid]);
        HideProgressBarForPlayer(phealthmezzo[playerid]);
        }
    }
}
Same thing...


Re: Problem with Health bar. - Rudy_ - 09.10.2014

Does it show green? or only Yellow everytime


Re: Problem with Health bar. - yanir3 - 09.10.2014

Can you show the definition of how you used CreateProgressBar?
By the way, if you want to change color you need to use SetProgressBarColor and I don't see it anywhere in the code.


Re: Problem with Health bar. - Meta - 09.10.2014

ProgressBar stuff may be this:
https://sampforum.blast.hk/showthread.php?tid=537468


Re: Problem with Health bar. - tandytanz - 15.02.2015

pawn Код:
//On OnPlayerConnect:
SetTimer("ProgressBar", 500, 1);
forward ProgressBar();
public ProgressBar() //I prefer not to use OnPlayerUpdate with textdraws
{
    for (new playerid; playerid < MAX_PLAYERS; playerid++) //I recommend foreach(Player, playerid)
    {
    new Float:health;
        GetPlayerHealth(playerid, health);
        if(health == 100 && health >= 60)
        {
        ShowProgressBarForPlayer(phealthsano[playerid]);
        SetProgressBarValue(phealthsano[playerid], health);
        UpdateProgressBar(phealthsano[playerid], playerid);
        HideProgressBarForPlayer(phealthmezzo[playerid]);
        HideProgressBarForPlayer(phealthmalato[playerid]);
        }
        else if(health < 60 && health >= 30)
        {
        ShowProgressBarForPlayer(phealthmezzo[playerid]);
        SetProgressBarValue(phealthmezzo[playerid]);
        UpdateProgressBar(phealthmezzo[playerid], playerid);
        HideProgressBarForPlayer(phealthsano[playerid]);
        HideProgressBarForPlayer(phealthmalato[playerid]);
        }
        else if(health < 30) && health >= 0)
        {
        ShowProgressBarForPlayer(phealthmalato[playerid]);
        SetProgressBarValue(phealthmalato[playerid]);
        UpdateProgressBar(phealthmalato[playerid], playerid);
        HideProgressBarForPlayer(phealthsano[playerid]);
        HideProgressBarForPlayer(phealthmezzo[playerid]);
        }
    }
}