[pawn]
#include <a_samp>
#include <progress>
new Bar:vhealth[MAX_PLAYERS] = {INVALID_BAR_ID, ...};
forward ProgressBar();
public OnFilterScriptInit()
{
SetTimer(\"ProgressBar\", 500, 1);
return 1;
}
public ProgressBar() //I prefer not to use OnPlayerUpdate with textdraws
{
for(new i; i < MAX_PLAYERS; i++) //I recommend foreach(Player, playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(IsPlayerInAnyVehicle(playerid) && vhealth[playerid] != INVALID_BAR_ID)
{
new Float:health;
GetVehicleHealth(vehicleid, health);
SetProgressBarValue(vhealth[playerid], health);
UpdateProgressBar(vhealth[playerid], playerid);
if(health >= 750 || health <= 1000)
{
SetProgressBarColor(vhealth[playerid], 0x00FF00FF);
} else if(health >= 500 || health <= 749) {
SetProgressBarColor(vhealth[playerid], 0xFFD500AA);
} else if(health >= 250 || health <= 499) {
SetProgressBarColor(vhealth[playerid], 0xFF0000AA);
}
}
}
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_DRIVER)
{
DestroyProgressBar(vhealth[playerid]);
vhealth[playerid] = INVALID_BAR_ID;
}
if(newstate == PLAYER_STATE_DRIVER)
{
vhealth[playerid] = CreateProgressBar(548.5, 36.0, _, _, 0x00FF00FF, 1000.0);
ShowProgressBarForPlayer(playerid, vhealth[playerid]);
}
return 1;
}
[/pawn]