
#include <a_samp>
#include <a_npc>
new Text:InfoBox;
new IBoxString[128];
new ITimer[999];
new PID[999];
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Vehicle Health Script ");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
KillTimer(ITimer[PID[playerid]]);
TextDrawHideForPlayer(PID[playerid], InfoBox);
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
InfoBox = TextDrawCreate(200.0, 360.0, " ");
TextDrawUseBox(InfoBox,0);
TextDrawTextSize(InfoBox, 440, 410);
TextDrawBoxColor(InfoBox,0x00000066);
TextDrawSetOutline(InfoBox,1);
TextDrawLetterSize(InfoBox,0.5,1.2);
TextDrawSetShadow(InfoBox,0);
PID[playerid] = playerid;
ITimer[PID[playerid]] = SetTimer("UInfoBox", 100, 1);
}
else
{
KillTimer(ITimer[PID[playerid]]);
TextDrawHideForPlayer(PID[playerid], InfoBox);
}
return 1;
}
forward UInfoBox();
public UInfoBox()
{
new vehicleid = GetPlayerVehicleID(PID[playerid]);
new Float:VHealth;
GetVehicleHealth(vehicleid, VHealth);
VHealth = (VHealth/10);
format(IBoxString, 128, "~r~Vehicle Health: ~y~%.1f~n~~r~", VHealth);
TextDrawHideForPlayer(PID[playerid], InfoBox);
TextDrawSetString(InfoBox, IBoxString);
TextDrawShowForPlayer(PID[playerid], InfoBox);
}
#include <a_samp>
#include <a_npc>
new Text:InfoBox[MAX_PLAYERS];
new ITimer[MAX_PLAYERS];
new IBoxString[MAX_PLAYERS][128]; // as we use it as global, we don't want any conflicts with healths of other players
new Float:VHealth[MAX_VEHICLES];
forward UInfoBox(playerid); // defined player id removes need of variable PID[];
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Vehicle Health Script ");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
KillTimer(ITimer[playerid]);
TextDrawHideForPlayer(playerid, InfoBox[playerid]);
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
InfoBox[playerid] = TextDrawCreate(200.0, 360.0, " ");
TextDrawUseBox(InfoBox[playerid],0);
TextDrawTextSize(InfoBox[playerid], 440, 410);
TextDrawBoxColor(InfoBox[playerid],0x00000066);
TextDrawSetOutline(InfoBox[playerid],1);
TextDrawLetterSize(InfoBox[playerid],0.5,1.2);
TextDrawSetShadow(InfoBox[playerid],0);
ITimer[playerid] = SetTimerEx("UInfoBox", 250, 1,"i",playerid); // changed the timer to 250, no need top be faster unless u use it for speed detection
}
else
{
KillTimer(ITimer[playerid]);
TextDrawHideForPlayer(playerid, InfoBox[playerid]);
}
return 1;
}
public UInfoBox(playerid)
{
GetVehicleHealth(GetPlayerVehicleID(playerid), VHealth[GetPlayerVehicleID(playerid)]);
format(IBoxString[playerid], sizeof(IBoxString[])-1, "~r~Vehicle Health: ~y~%.1f~n~~r~", VHealth[GetPlayerVehicleID(playerid)]/10);
TextDrawHideForPlayer(playerid, InfoBox[playerid]);
TextDrawSetString(InfoBox[playerid], IBoxString[playerid]);
TextDrawShowForPlayer(playerid, InfoBox[playerid]);
}


|
Originally Posted by TMasters.tk
Remove %, its not soposed to be there, as this is special timer case.
I made a tiny mistake there, i seted 'i' but should been "i" ... Also seted that Text:Box to [MAX_PLAYERS] althought ther eis no need to be so, it just to be sure for no other player conflict I updated the script, if you dont make any changes it should work |

#include <a_samp>
#include <a_npc>
new Text:InfoBox[MAX_PLAYERS];
new ITimer[MAX_PLAYERS];
new IBoxString[MAX_PLAYERS][128];
new Float:VHealth[MAX_VEHICLES];
forward UInfoBox(playerid);
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Vehicle Health Script ");
print(" Credits to: ExoSanty, TMasters.tk ");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
KillTimer(ITimer[playerid]);
TextDrawHideForPlayer(playerid, InfoBox[playerid]);
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
InfoBox[playerid] = TextDrawCreate(200.0, 360.0, " ");
TextDrawUseBox(InfoBox[playerid],0);
TextDrawTextSize(InfoBox[playerid], 440, 410);
TextDrawBoxColor(InfoBox[playerid],0x00000066);
TextDrawSetOutline(InfoBox[playerid],1);
TextDrawLetterSize(InfoBox[playerid],0.5,1.2);
TextDrawSetShadow(InfoBox[playerid],0);
ITimer[playerid] = SetTimerEx("UInfoBox", 250, 1,"i",playerid);
}
else
{
KillTimer(ITimer[playerid]);
TextDrawHideForPlayer(playerid, InfoBox[playerid]);
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(ITimer[playerid]);
TextDrawHideForPlayer(playerid, InfoBox[playerid]);
return 1;
}
public UInfoBox(playerid)
{
GetVehicleHealth(GetPlayerVehicleID(playerid), VHealth[GetPlayerVehicleID(playerid)]);
format(IBoxString[playerid], sizeof(IBoxString[])-1, "~r~Vehicle Health: ~y~%.1f~n~~r~", VHealth[GetPlayerVehicleID(playerid)]/10);
TextDrawHideForPlayer(playerid, InfoBox[playerid]);
TextDrawSetString(InfoBox[playerid], IBoxString[playerid]);
TextDrawShowForPlayer(playerid, InfoBox[playerid]);
return 1;
}