SA-MP Forums Archive
Fuel Consumption - 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: Fuel Consumption (/showthread.php?tid=600274)



Fuel Consumption - eikzdej - 06.02.2016

Hi! How can i make this code like if the Vehicle Engine is turned off, the gas consumption stops.

I tried this but didn't worked.

Quote:

public timer_fuel_lower()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
new vid = GetPlayerVehicleID(i);

if (isrefuelling[i]) continue;

if (GetPlayerVehicleSeat(i) == 0)
{
if (Engine[vid] == 1)
fuel[vid] = fuel[vid] -1;
else
fuel[vid] = fuel[vid] -0;

if (fuel[vid] < 1)
{
fuel[vid] = 0;
}
}
}
return 1;
}




Re: Fuel Consumption - itsCody - 06.02.2016

Detect if the engine is off then kill the timer.
Or detect if the vehicle is moving by using some speed script
if((speed) > 1) Fuel --;

Could try something like
PHP код:
public timer_fuel_lower()
{
    for(new 
0MAX_PLAYERSi++)
    {
        new 
vid GetPlayerVehicleID(i);
        new 
speed GetPlayerSpeed(ifalse)
        if(
isrefuelling[i]) continue;
        
        if(
fuel[vid] > 0)
        {
            if((
speed) > 1fuel[vid] --;
            if(
fuel[vid] >= && fuel[vid] <= 15 && GetPlayerState(i) == PLAYER_STATE_DRIVER)
            {
                
SendClientMessage(i, -1"Vehicle low on fuel");
            }
        }
        
        if(
fuel[vid] <= 0)
        {
            
fuel[vid] = 0;
            
// Turn the engine off here.
        
}
    }
    return 
1;
}
GetPlayerSpeed(playeridbool:kmh false)
{
    new 
Float:Vx,Float:Vy,Float:Vz,Float:rtn;
    if(
IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid), VxVyVz); else GetPlayerVelocity(playeridVxVyVz);
    
rtn floatsqroot(floatabs(floatpower(Vx Vy Vz2)));
    return 
kmh?floatround(rtn 100 1.61):floatround(rtn 100);

If you get errors post them cause this is untested and yeah


Re: Fuel Consumption - eikzdej - 06.02.2016

is GetPlayerSpeed a stock or public?


Re: Fuel Consumption - FreAkeD - 06.02.2016

It's a stock function.

https://sampwiki.blast.hk/wiki/Function


Re: Fuel Consumption - itsCody - 06.02.2016

"stock" isn't even needed.
Never will be.


Re: Fuel Consumption - Sew_Sumi - 06.02.2016

Quote:
Originally Posted by eikzdej
Посмотреть сообщение
is GetPlayerSpeed a stock or public?
Quote:
Originally Posted by FreAkeD
Посмотреть сообщение
No such thing... It's just a function.

https://sampforum.blast.hk/showthread.php?tid=570635


Re: Fuel Consumption - eikzdej - 06.02.2016

Quote:
Originally Posted by itsCody
Посмотреть сообщение
"stock" isn't even needed.
Never will be.
No Errors during compile, but the consumption is not working.


Re: Fuel Consumption - itsCody - 06.02.2016

Quote:
Originally Posted by eikzdej
Посмотреть сообщение
No Errors during compile, but the consumption is not working.
What is exactly the issue? Does it not decrease?


Re: Fuel Consumption - eikzdej - 06.02.2016

Yes.


Re: Fuel Consumption - itsCody - 06.02.2016

are you driving?

The script I fixed up is meant so when you drive the fuel goes down by 1.