[HELP] Fuel
#1

I put a system engine, but when I stop the engine, the fuel decreases 3-4% then increase at 100%.

Exmeple: i have fuel 80%, when i stop the engine, decreases at 76% then increase at 100%. Why?

pawn Код:
if (newkeys & KEY_NO)
    {
        if(GetPlayerState(playerid) == 2)
        {
             //This part here is defining the vehicle ID that the player is currently in.
            new engine, lights, alarm, doors, bonnet, boot, objective; //This is defining the vehicles current items.
            GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);//This is checking the vehicle's engine/lights/alarm/doors/bonnet/boot/objective status.
            if(Engine[vehicle] == 0) //This is checking if the engine of the vehicle, is turned off or not.
            {
                Engine[vehicle] = 1; //This is setting the global variable that you created at the beginning.
                SetVehicleParamsEx(vehicle, 1, lights, alarm, doors, bonnet, boot, 0); //This is setting the vehicles engine to be on.
                GameTextForPlayer(playerid, "~w~ENGINE ~g~ON...", 1000, 6);
            }
            else
            {
                Engine[vehicle] = 0; //This is setting the global variable that you created at the beginning.
                SetVehicleParamsEx(vehicle, 0, lights, alarm, doors, bonnet, boot, 0); //This is setting the vehicles engine to be on.
                GameTextForPlayer(playerid, "~w~ENGINE ~r~OFF...", 1000, 6);
            }
        }
    }
pawn Код:
public CheckGas()
{
    new string[256];
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
            {
                new vehicle = GetPlayerVehicleID(i);
                if(Gas[vehicle] >= 1)
                {
                    if(Gas[vehicle] <= 10) { PlayerPlaySound(i, 1085, 0.0, 0.0, 0.0); }
                    if(gGas[i] == 1) {
                    format(string, sizeof(string), "~b~~n~~n~~n~~n~~n~~n~~n~~n~~n~Fuel:~w~ %d% %",Gas[vehicle]);
                    GameTextForPlayer(i,string,15500,3); }
                    if(IsAPlane(vehicle) || IsABoat(vehicle) || IsABmx(vehicle)) { Gas[vehicle]++; }
                    Gas[vehicle]--;
                }
                else
                {
                    NoFuel[i] = 1;
                    TogglePlayerControllable(i, 0);
                    GameTextForPlayer(i,"~r~~n~~n~~n~~n~~n~~n~~n~~n~No fuel in Vehicle~n~Use /exit to leave the vehicle",1500,3);
                }
            }
        }
    }
    return 1;
}
Reply
#2

Nobody can help me?
Reply
#3

pawn Код:
if (newkeys & KEY_NO)
    {
        if(GetPlayerState(playerid) == 2)
        {
             //This part here is defining the vehicle ID that the player is currently in.
            new engine, lights, alarm, doors, bonnet, boot, objective; //This is defining the vehicles current items.
            GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);//This is checking the vehicle's engine/lights/alarm/doors/bonnet/boot/objective status.
            if(Engine[vehicle] == 0) //This is checking if the engine of the vehicle, is turned off or not.
            {
                Engine[vehicle] = 1; //This is setting the global variable that you created at the beginning.
                SetVehicleParamsEx(vehicle, 1, lights, alarm, doors, bonnet, boot, 0); //This is setting the vehicles engine to be on.
                GameTextForPlayer(playerid, "~w~ENGINE ~g~ON...", 1000, 6);
            }
            else
            {
                Engine[vehicle] = 0; //This is setting the global variable that you created at the beginning.
                SetVehicleParamsEx(vehicle, 0, lights, alarm, doors, bonnet, boot, 0); //This is setting the vehicles engine to be on.
                GameTextForPlayer(playerid, "~w~ENGINE ~r~OFF...", 1000, 6);
            }
        }
    }
i don't see anything wrong here though

well maybe the checkgas() is loading more than 1 time ?
Reply
#4

Mean?
Reply
#5

Hello Try at first

PHP код:
public CheckGas()
{
    new 
string[256];
    for (new 
i=0i<=MAX_PLAYERSi++) {
        new 
vehicle GetPlayerVehicleID(i);
        new 
engine,lights,alarm,doors,bonnet,boot,objective;
        
GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
        if(
engine >= 1) {
            if(
Gas[vehicle] >= 1) {
                
format(stringsizeof(string), "~b~~n~~n~~n~~n~~n~~n~~n~~n~~n~Fuel:~w~ %d% %",Gas[vehicle]);
                
GameTextForPlayer(i,string,15500,3); }
                
Gas[vehicle]--;
            }
            else {
                
NoFuel[i] = 1;
                
TogglePlayerControllable(i0);
                
GameTextForPlayer(i,"~r~~n~~n~~n~~n~~n~~n~~n~~n~No fuel in Vehicle~n~Use /exit to leave the vehicle",1500,3);
            }
        }
    }
    return 
1;

make sur your timer is

PHP код:
new var;
var = 
SetTimer("CheckGas"TIMEheretrue); 
Reply
#6

what I replace "TIMEhere"?
Reply
#7

Number ''15000''
Reply
#8

Код:
error 010: invalid function or declaration
LINE:
pawn Код:
return 1;
Reply
#9

remove bracket

PHP код:
public CheckGas()
{
    new 
string[256];
    for (new 
i=0i<=MAX_PLAYERSi++) {
        new 
vehicle GetPlayerVehicleID(i);
        new 
engine,lights,alarm,doors,bonnet,boot,objective;
        
GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
        if(
engine >= 1) {
            if(
Gas[vehicle] >= 1) {
                
format(stringsizeof(string), "~b~~n~~n~~n~~n~~n~~n~~n~~n~~n~Fuel:~w~ %d% %",Gas[vehicle]);
                
GameTextForPlayer(i,string,15500,3); }
                
Gas[vehicle]--;
            }
            else {
                
NoFuel[i] = 1;
                
TogglePlayerControllable(i0);
                
GameTextForPlayer(i,"~r~~n~~n~~n~~n~~n~~n~~n~~n~No fuel in Vehicle~n~Use /exit to leave the vehicle",1500,3);
            }
        }
        return 
1;

Reply
#10

SOLVED !

pawn Код:
public CheckGas()
{
    new string[256];
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerConnected(i))
        {
            new vehicle = GetPlayerVehicleID(i);
            if(Engine[vehicle] == 1)
            {
                if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
                {
                    if(Gas[vehicle] >= 1)
                    {
                        if(Gas[vehicle] <= 10) { PlayerPlaySound(i, 1085, 0.0, 0.0, 0.0); }
                        if(gGas[i] == 1) {
                        format(string, sizeof(string), "",Gas[vehicle]);
                        GameTextForPlayer(i,string,15500,3); }
                        if(IsAPlane(vehicle) || IsABoat(vehicle) || IsABmx(vehicle)) { Gas[vehicle]++; }
                        Gas[vehicle]--;
                    }
                    else
                    {
                        NoFuel[i] = 1;
                        TogglePlayerControllable(i, 0);
                        GameTextForPlayer(i,"~r~~n~~n~~n~~n~~n~~n~~n~~n~No fuel in Vehicle~n~Use /exit to leave the vehicle",1500,3);
                    }
                }
            }
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)