Vehicle health help...
#1

The following code works fine to get the vehicle health for the first user in the game, as soon as an other player spawns or gets a vehicle all things go wrong
I can't figure it out how to make it work for multiple players...
I must somehow make it remember the correct timer for the correct user, right? Any idea's?

Код:
#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);
}
Reply


Messages In This Thread
Vehicle health help... - by ExoSanty - 19.11.2009, 04:57
Re: Vehicle health help... - by TMasters - 19.11.2009, 06:33
Re: Vehicle health help... - by ExoSanty - 19.11.2009, 09:37
Re: Vehicle health help... - by TMasters - 19.11.2009, 09:51
Re: Vehicle health help... - by ExoSanty - 19.11.2009, 10:07
Re: Vehicle health help... - by ExoSanty - 19.11.2009, 11:29
Re: Vehicle health help... - by TMasters - 19.11.2009, 14:57

Forum Jump:


Users browsing this thread: 1 Guest(s)