Need help with my fuel system
#1

Hello,

My fuel system isnt working correctly.
I want it to say if the engine is on that they have to turn it off etc.

pawn Код:
command(refill, playerid, params[])
{
    #pragma unused params
    if(IsAtGasStation(playerid))
    {
        new PCar = GetClosestVehicle(playerid, 5);
        new engine,lights,alarm,doors,bonnet,boot,objective;
        GetVehicleParamsEx(PCar,engine,lights,alarm,doors,bonnet,boot,objective);
        if(IsPlayerConnected(playerid))
        {
            if(!IsPlayerInAnyVehicle(playerid))
            {
                if(engine == VEHICLE_PARAMS_OFF)
                {
                    if(Vehicles[PCar][Fuel] != 100)
                    {
                        ShowMenuForPlayer(Menu:Gas, playerid);
                    }
                    else
                    {
                        SCM(playerid, ADMINBLUE, "Your car is already full!");
                    }
                }
                else
                {
                    SCM(playerid, WHITE,"Your vehicle engine is still on!");
                }
            }
            else
            {
                SCM(playerid, WHITE,"You are still in a vehicle!");
            }
        }
    }
    else
    {
       SCM(playerid,0xFFFF00AA,".:: [ERROR]: You are not at a Gas Station! ::.");
    }
    return 1;
}
I also want it to check how much the car's fuel is and that minus 100, so that is the new fuel that gets added.
and that *3 but it doesn't work.

Menu reaction:
pawn Код:
public OnPlayerSelectedMenuRow(playerid, row)
{
    if(GetPlayerMenu(playerid) == Gas)
    {
        switch(row)
        {
            case 0:
            {
                TogglePlayerControllable(playerid,0);
                GameTextForPlayer(playerid,"~b~Petrol ~n~ ~w~Refueling vehicle ~n~~g~Please wait..",10000,3);
                RefillTimer = SetTimerEx("ReFill", 10000, false, "i", playerid);
                Tankuje[playerid] = 1;
            }
            case 1:
            {
                GameTextForPlayer(playerid,"~r~This function isn't working yet, sorry.",3500,3);
                TogglePlayerControllable(playerid,0);
            }
            case 2:
            {
                GameTextForPlayer(playerid,"~y~Have a nice day!",4000,3);
                HideMenuForPlayer(Gas,playerid);
            }
        }
    }
    return 1;
}
Public refill:
pawn Код:
public ReFill(playerid)
{
    new VehicleFuel, NewFuel, str[128];
    new PCar = GetClosestVehicle(playerid, 5);
    VehicleFuel = Vehicles[PCar][Fuel];
    NewFuel = 100-VehicleFuel;
    Vehicles[PCar][Fuel] = 100;
    GivePlayerMoney(playerid, -3*NewFuel);
    Player[playerid][Money] = -3*NewFuel;
    format(str, sizeof(str), "You refilled your vehicle with %d liters and the price was %d.", NewFuel, 3*NewFuel);
    SCM(playerid, ADMINBLUE, str);
    KillTimer(RefillTimer);
    TogglePlayerControllable(playerid,1);
}
Reply
#2

What you've shown is the script checking if the vehicle engine is on.
if(engine == VEHICLE_PARAMS_OFF)

Your vehicle fuel is this integer at the current time: Vehicles[PCar][Fuel].

I'm sorry but I can't really understand what you're trying to say.

My only suggestion is to set the fuel to 0 at this time:
PHP код:
            case 0// In here.
            
{
                
TogglePlayerControllable(playerid,0);
                
GameTextForPlayer(playerid,"~b~Petrol ~n~ ~w~Refueling vehicle ~n~~g~Please wait..",10000,3);
                
RefillTimer SetTimerEx("ReFill"10000false"i"playerid);
                
Tankuje[playerid] = 1;
            } 
So that once the ten seconds has passed. You will have fuel again.
Reply
#3

I want it to check if the vehicle engine is off, if not that it sends a msg " turn off the engine", and when they are refilling (at public refill) it needs to check how much fuel is needed till its 100 and that x3 as pice..
Reply
#4

You want when you try to refill your car engine to be off and if it isn't off to send error message?
Reply
#5

Indeed, and then comes the second bug, When Im refilling with 92 fuel left, (8 fuel needed till 100%) it sais: You refilled your car with 100 liters for 300dollar...

it should say you refilled your car with 8 liters for 24dollar.
Reply
#6

PHP код:
#define MaxFuel 100
// This goes inside your public ReFill(playerid)
new Amount MaxFuel Vehicles[PCar][Fuel];
new 
RefuelPrice = (Amount *3) / MaxFuel;
if (
GivePlayerMoney(playerid, -RefuelPrice))
{
     
// Working code in here.
}
else
{
    
//You don't have enough money.

Reply
#7

Worked thanks, rep+ for ya
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)