SA-MP Forums Archive
How To Make Max Fuel? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How To Make Max Fuel? (/showthread.php?tid=527732)



How To Make Max Fuel? - kloning1 - 24.07.2014

How To Make Max Fuel in vehicle??

its like Realistic :3 right every vehicle has a different fuel

This SS/ Exlampe



Re: How To Make Max Fuel? - coole210 - 24.07.2014

Try and just use a timer and a variable I guess?


Re: How To Make Max Fuel? - kloning1 - 24.07.2014

look pic , there restrictions of fuel *fuel capacity


Re: How To Make Max Fuel? - coole210 - 24.07.2014

If you wanna make a fuel capacity per vehicle model you can set that all up yourself, or you can use this one with a 30 max capacity just like your SS.

pawn Код:
new Float:Fuel[MAX_VEHICLES];
new FuelTimer[MAX_VEHICLES] = -1;
new VehicleOccupied[MAX_VEHICLES] = -1;
#define MAX_FUEL 30.0 // Max fuel capacity
#define FUEL_TIMER_MIN 1 // Minutes per fuel depletion (1 minute loses 1 fuel)

public OnVehicleSpawn(vehicleid)
{
    if(FuelTimer[vehicleid] != -1) KillTimer(FuelTimer[vehicleid]);
    Fuel[vehicleid] = MAX_FUEL;
    SetTimerEx("Fuel_down", FUEL_TIMER_MIN * 60000, true, "i", vehicleid);
    VehicleOccupied[vehicleid] = -1;
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    KillTimer(FuelTimer[vehicleid]);
    Fuel[vehicleid] = 0.0;
    return 1;
}

forward Fuel_down(vehicleid);
public Fuel_down(vehicleid)
{
    Fuel[vehicleid] -= 1.0;
    if(Fuel[vehicleid] <= 1 && VehicleOccupied[vehicleid] != -1) RemovePlayerFromVehicle(VehicleOccupied[vehicleid]);
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        if(Fuel[GetPlayerVehicleID(playerid)] <= 0) RemovePlayerFromVehicle(GetPlayerVehicleID(playerid));
        else VehicleOccupied[GetPlayerVehicleID(playerid)] = playerid;
    }
    if(oldstate == PLAYER_STATE_DRIVER && newstate != PLAYER_STATE_DRIVER)
    {
        VehicleOccupied[GetPlayerVehicleID(playerid)] = -1;
    }
    return 1;
}



Re: How To Make Max Fuel? - Juvanii - 24.07.2014

I see that this is wrong! if u make the timer under OnVehicleSpawn callback, it will decrease the vehicle's fuel even with no driver in the vehicle. So you better use it under OnPlayerStateChange like:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        FuelTimer[playerid] = SetTimerEx("Fuel_Down", FUEL_TIMER_MIN * 60000, true, "i", playerid);
    }
    return 1;
}



Re: How To Make Max Fuel? - kloning1 - 24.07.2014

but, every car is different fuels limits >,<


Re: How To Make Max Fuel? - Juvanii - 24.07.2014

Quote:
Originally Posted by kloning1
Посмотреть сообщение
but, every car is different fuels limits >,<
so? what do u want exactly?


Re: How To Make Max Fuel? - kloning1 - 24.07.2014

so gini, I would * imagine: v LOL

hm, fuel, like in the real world,
did you see? each vehicle must have a fuel capacity will vary,

* so? Can you help?


Re: How To Make Max Fuel? - Juvanii - 24.07.2014

if u mean that you want every vehicle model has different max fuel capacity, i think you could make it under OnGameModeInIt callback by looping all the vehicles then make a fuel capacity to each vehicle model but it'll take so much time.


Re: How To Make Max Fuel? - kloning1 - 24.07.2014

well as that, (y)
function-function what should be learned ??