08.08.2016, 22:28
Hey guys, working on a fuel system however I have a minor bug. When refueling regardless of how much fuel the vehicle has you will always pay $100, since Fuel cost is 1 and fuel max is 100, it's not getting the variable of fuel before filling up, just curious how would I get the fuel variable and then start fueling from there, with the variable number of fuel being anything from 1 to 100. I might be way over thinking this but I just wanted to ask. Here is my fueling callback.
PHP код:
public MainTimer()
{
new string[128], Float:x, Float:y, Float:z;
for(new i=0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
{
new vehicleid = GetPlayerVehicleID(i);
if(!IsBicycle(vehicleid) && CFuel[vehicleid] > 0)
{
CFuel[vehicleid] -= GetPlayerSpeed(i)/1000.0;
if(CFuel[vehicleid] <= 0)
{
ToggleEngine(vehicleid, VEHICLE_PARAMS_OFF);
GameTextForPlayer(i, "~r~out of fuel", 3000, 3);
SendClientMessage(i, COLOR_LIGHTRED, "This vehicle is out of fuel!");
}
}
}
if(RefuelTime[i] > 0 && GetPVarInt(i, "FuelStation"))
{
new vehicleid = GetPlayerVehicleID(i);
CFuel[vehicleid] += 2.0;
RefuelTime[i]--;
if(RefuelTime[i] == 0)
{
if(CFuel[vehicleid] == FuelMax) return SendClientMessage(i, COLOR_RED, "Error: Your vehicle cannot hold anymore fuel.");
if(CFuel[vehicleid] >= 100.0) CFuel[vehicleid] = 100.0;
new stationid = GetPVarInt(i, "FuelStation");
new cost = floatround(CFuel[vehicleid]-GetPVarFloat(i, "Fuel"))*FUEL_PRICE;
if(GetPlayerState(i) != PLAYER_STATE_DRIVER || CFuel[vehicleid] >= 100.0 || GetPlayerMoney(i) < cost || !IsPlayerInRangeOfPoint(i, 10.0, FuelStationPos[stationid][0], FuelStationPos[stationid][1], FuelStationPos[stationid][2]))
{
if(PlayerInfo[i][pAdmin] > 2)
{
new msg[24];
format(msg, sizeof(msg), "STATION ID %d", stationid);
SendClientMessage(i, COLOR_WHITE, msg);
}
if(GetPlayerMoney(i) < cost) cost = GetPlayerMoney(i);
GivePlayerCash(i, -cost);
format(string, sizeof(string), "~r~-$%d", cost);
GameTextForPlayer(i, string, 2000, 3);
format(string, sizeof(string), "You have paid $%d for the fuel.", cost);
SendClientMessage(i, COLOR_YELLOW, string);
SetPVarInt(i, "FuelStation", 0);
SetPVarFloat(i, "Fuel", 0.0);
}
else
{
RefuelTime[i] = 5;
format(string, sizeof(string), "~w~refueling...~n~~r~-$%d", cost);
GameTextForPlayer(i, string, 2000, 3);
}
}
}
if(TrackCar[i])
{
GetVehiclePos(TrackCar[i], x, y, z);
SetPlayerCheckpoint(i, x, y, z, 3);
}
}
}
return 1;
}