SA-MP Forums Archive
How to make fuel go down when player is out of the vehicle - 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 fuel go down when player is out of the vehicle (/showthread.php?tid=349343)



How to make fuel go down when player is out of the vehicle - Geniuss - 08.06.2012

How would i make the car lose fuel when the player is out of the vehicle

pawn Код:
public timer_fuel_lower()
{
    new engine, lights, alarm, doors, bonnet, boot, objective;
    for(new i=0;i<MAX_PLAYERS;i++) { //loop for all players
        new PlayerVehicle = GetVehicleFileID(GetPlayerVehicleID(i));
        if (isrefuelling[i]) continue; //stop when a player is already refuelling
        new vid = GetPlayerVehicleID(i); //getting vehicle ID
        if (GetPlayerVehicleSeat(i) == 0 && EngineOn[vid] == 1 || IsPlayerInHotWiredCar == 1 || Vehicles[PlayerVehicle][CarGroup] >= 0 && Vehicles[PlayerVehicle][CarGroup] == Player[i][Group]) { //if the player is a driver (it should only lower the fuel when theres an driver!)
            fuel[vid] = fuel[vid] -1; //lowering fuel value
            if (fuel[vid]<1) //if fuel is empty
            {
                GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
                fuel[vid] = 0; //setting fuel to 0 (else the timer will set it to -1 -2 -3 etc before removing player)
                SetVehicleParamsEx(vid, 0, lights, alarm, doors, bonnet, boot, 0);
                SendClientMessage(i, WHITE, "This vehicle is out of fuel");
            }
        }
        new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //preparing string with next fuel value
        TextDrawSetString(td_fuel[i],string); //updating textdraw
    }
    return 1;
}
If you need mode code just ask

Thank You


Re: How to make fuel go down when player is out of the vehicle - [KHK]Khalid - 08.06.2012

hmm what about looping through all the vehicles and check if they have no drivers/passengers then lower their fuel?


Re: How to make fuel go down when player is out of the vehicle - Geniuss - 08.06.2012

Quote:
Originally Posted by HellSphinX
Посмотреть сообщение
hmm what about looping through all the vehicles and check if they have no drivers/passengers then lower their fuel?
Sorry could you give me a idea on how to do that


Re: How to make fuel go down when player is out of the vehicle - [KHK]Khalid - 08.06.2012

yea sure

pawn Код:
// use this to check if a vehicle has drivers/passengers

stock DoesVehHasDriversOrPassengers(vehicleid)
{
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(GetPlayerState(p) == PLAYER_STATE_DRIVER || GetPlayerState(p) == PLAYER_STATE_PASSENGER)
        {
            if(GetPlayerVehicleID(p) == vehicleid)
            {
                return 1;
            }
        }
    }
    return 0;
}
// This code checks if a vehicle has no drivers/passengers then lowers its fuel

for(new veh = 0; veh < MAX_VEHICLES; veh ++)
{
    if(!DoesVehHasDriversOrPassengers(veh))
    {
        fuel[veh] --;
    }
}



Re: How to make fuel go down when player is out of the vehicle - Geniuss - 08.06.2012

Quote:
Originally Posted by HellSphinX
Посмотреть сообщение
yea sure

pawn Код:
// use this to check if a vehicle has drivers/passengers

stock DoesVehHasDriversOrPassengers(vehicleid)
{
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(GetPlayerState(p) == PLAYER_STATE_DRIVER || GetPlayerState(p) == PLAYER_STATE_PASSENGER)
        {
            if(GetPlayerVehicleID(p) == vehicleid)
            {
                return 1;
            }
        }
    }
    return 0;
}
// This code checks if a vehicle has no drivers/passengers then lowers its fuel

for(new veh = 0; veh < MAX_VEHICLES; veh ++)
{
    if(!DoesVehHasDriversOrPassengers(veh))
    {
        fuel[veh] --;
    }
}
Would this work

pawn Код:
// use this to check if a vehicle has drivers/passengers

stock DoesVehHasDriversOrPassengers(vehicleid)
{
    for(new p = 0; p < MAX_PLAYERS; p++)
    {
        if(GetPlayerState(p) == PLAYER_STATE_DRIVER || GetPlayerState(p) == PLAYER_STATE_PASSENGER)
        {
            if(GetPlayerVehicleID(p) == vehicleid)
            {
                return 1;
            }
        }
    }
    return 0;
}
// This code checks if a vehicle has no drivers/passengers then lowers its fuel

for(new veh = 0; veh < MAX_VEHICLES; veh ++)
{
    if(!DoesVehHasDriversOrPassengers(veh))
    {
            if(EngineIsOn[veh] == 1)
            {
               fuel[veh] --;
            }
    }
}



Re: How to make fuel go down when player is out of the vehicle - [KHK]Khalid - 08.06.2012

Yea why not? This will check if a vehicle has no drivers AND its engine turned on this is the only difference.