18.04.2018, 19:21
I created a textdraw for fuel system. Everything is working fine for one player. But after driving the second vehicle, the previous value of fuel is overlapping with new one and both the values are decreasing together.
Function:
PHP код:
new fueltimer[MAX_VEHICLES];
PHP код:
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;
}
PHP код:
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;
}
PHP код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
KillTimer(fueltimer[vehicleid]);
TextDrawHideForPlayer(playerid, VehicleMeter[playerid]);
return 1;
}
PHP код:
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;
}