new fueltimer[MAX_VEHICLES];
public OnPlayerConnect(playerid)
{
VehicleMeter[playerid] = TextDrawCreate(498.000000, 140.000000, " ");
TextDrawBackgroundColor(VehicleMeter[playerid], 255);
TextDrawFont(VehicleMeter[playerid], 1);
TextDrawLetterSize(VehicleMeter[playerid], 0.389999, 1.299999);
TextDrawColor(VehicleMeter[playerid], 0xFFFFFFFF);
TextDrawSetOutline(VehicleMeter[playerid], 1);
TextDrawSetProportional(VehicleMeter[playerid], 1);
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new vid = GetPlayerVehicleID(playerid);
if(newstate == PLAYER_STATE_DRIVER)
{
TextDrawShowForPlayer(playerid, VehicleMeter[playerid]);
fueltimer[vid] = SetTimerEx("DecreaseFuel", 1000, 1, "ii", playerid, vid);
}
else
{
TextDrawHideForPlayer(playerid, VehicleMeter[playerid]);
KillTimer(fueltimer[vid]);
}
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
KillTimer(fueltimer[vehicleid]);
TextDrawHideForPlayer(playerid, VehicleMeter[playerid]);
return 1;
}
public DecreaseFuel(playerid, vehicleid) // Decreases fuel by 0.035 (Whole fuel finishes in almost 50 minutes)
{
new engine, lights, alarm, doors, bonnet, boot, objective, string[128];
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
if(IsBicycle(vehicleid) == 1 || IsValidDealershipVehicle(vehicleid) == 1 || engine == 0)
return 1;
else
{
if(Vehicle[vehicleid][vFuel] <= 0)
{
ToggleEngine(vehicleid, VEHICLE_PARAMS_OFF);
SendClientMessage(playerid, COLOR_LIGHTRED, "Your vehicle is out of fuel.");
KillTimer(fueltimer[vehicleid]);
}
format(string, sizeof(string), "Fuel: %d%%", floatround(Vehicle[vehicleid][vFuel]));
TextDrawSetString(VehicleMeter[playerid], string);
Vehicle[vehicleid][vFuel] -= 0.035;
}
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
fueltimer[vehicleid] = SetTimerEx("DecreaseFuel", 1000, 1, "ii", playerid, vehicleid);
VehicleMeter[playerid] = CreatePlayerTextDraw(playerid, 498.000000, 140.000000, " ");
PlayerTextDrawBackgroundColor(playerid, VehicleMeter[playerid], 255);
PlayerTextDrawFont(playerid, VehicleMeter[playerid], 1);
PlayerTextDrawLetterSize(playerid, VehicleMeter[playerid], 0.389999, 1.299999);
PlayerTextDrawColor(playerid, VehicleMeter[playerid], 0xFFFFFFFF);
PlayerTextDrawSetOutline(playerid, VehicleMeter[playerid], 1);
PlayerTextDrawSetProportional(playerid, VehicleMeter[playerid], 1);
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
KillTimer(fueltimer[vehicleid]);
PlayerTextDrawDestroy(playerid, VehicleMeter[playerid]);
return 1;
}
That's why you should use player textdraws.. Also destroy them onplayerexitvehicle instead of hiding them. Create the textdraw again for the new vehicle onplayerentervehicle. You should also restore all the values you use to calculate when the player enters a vehicle.
|
wtf are you even doing, to you understand?
when you write code, first and most important thing is to understand what this code is doing. |