Fuel Consumption
#1

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;
}

Reply
#2

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
Reply
#3

is GetPlayerSpeed a stock or public?
Reply
#4

It's a stock function.

https://sampwiki.blast.hk/wiki/Function
Reply
#5

"stock" isn't even needed.
Never will be.
Reply
#6

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
Reply
#7

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

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

Yes.
Reply
#10

are you driving?

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


Forum Jump:


Users browsing this thread: 1 Guest(s)