31.07.2015, 14:34
Hey guys im making a Progress bar for my server that will be identical to the health bar, the only problem is it wont update and stays at a solid position. if you could help it would be most appreciated.
Here is my entire code:
Here is my entire code:
pawn Code:
#include <a_samp>
#include <progress2>
new PlayerBar:vbar;
new VBTimer[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
vbar = CreatePlayerProgressBar(playerid, 320.0, 240.0, 55.5, 3.2, 0xFF0000FF, 100.0, BAR_DIRECTION_DOWN);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
DestroyPlayerProgressBar(playerid, vbar);
KillTimer(VBTimer[playerid]);
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER) // Exiting a vehicle.
{
HidePlayerProgressBar(playerid, vbar); // Hide the progress bar when a player exits the vehicle.
KillTimer(VBTimer[playerid]);
}
if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT) // Getting into a vehicle.
{
new Float:vhealth;
new veh = GetPlayerVehicleID(playerid);
GetVehicleHealth(veh, vhealth);
ShowPlayerProgressBar(playerid, vbar); // Show the progress bar when a player enters the vehicle.
SetPlayerProgressBarValue(playerid, vbar, vhealth);
VBTimer[playerid] = SetTimerEx("UpdateVehicleBar", 1000, true, "i", playerid);
}
if(newstate == PLAYER_STATE_WASTED && oldstate == PLAYER_STATE_DRIVER) // Dying in a vehcile.
{
HidePlayerProgressBar(playerid, vbar); // Hide the progress bar if the player dies in a vehicle.
KillTimer(VBTimer[playerid]);
}
return 1;
}
forward UpdateVehicleBar(playerid);
public UpdateVehicleBar(playerid)
{
new Float:vhealth;
new veh = GetPlayerVehicleID(playerid);
GetVehicleHealth(veh, vhealth);
SetPlayerProgressBarValue(playerid, vbar, vhealth);
return 1;
}