Any help getting this to work please?
#1

Hi, i have been trying to get this to work for ages now and i just don't think i can actually progress on it xD

I was wondering if anyone could help me out please;

My problem is that I want a vehicles 'fuel' to lower as long as the engine is running. I currently have it so that if you're in the vehicle and the engine is on, the fuel lowers but i want it so that if you're in the vehicle or not in the vehicle, the fuel lowers. (Basically just as long as the engine is running and theres more than 0 fuel).
It seems if i get one part working; the other part fails

Also, when the fuel hits 0; the engine turns off but if i type /e(my cmd to start the engine), it will run for a second as if it had like 1fuel leftover. I also tried to tweak this but everything else stopped lol

If anyone could help me out it would be awesome Thanks to anyone who replies;

ALL RELATED CODE:
pawn Код:
new bool:ISENGINEON = false;

new fuel[MAX_VEHICLES]; //fuel per vehicle
forward timer_fuel_lower(playerid); //timer for lowering the fuel value
forward timer_refuel(playerid); //timer to refuel vehicle
new isrefuelling[MAX_PLAYERS] = 0; //bool to check if player is already refuelling
new Text:td_fuel[MAX_PLAYERS]; //textdraw with fuel
code in OnGameModeInit
pawn Код:
for(new i=0;i<MAX_VEHICLES;i++)
    {
        fuel[i] = 100; //sets every car's fuel to 100 in a loop
   }
SetTimer("timer_fuel_lower",1000,true); //sets the timer to drop the fuel
pawn Код:
public timer_fuel_lower()
{
    for(new i=0;i<MAX_PLAYERS;i++) { //loop for all players
        if (isrefuelling[i]) continue; //stop when a player is already refuelling
        new vid = GetPlayerVehicleID(i); //getting vehicle ID
        new engine,lights,alarm,doors,bonnet,boot,objective;
        GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
        if(engine == 1)
        {
            //if (GetPlayerVehicleSeat(i) == 0) { //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] == 0) //if fuel is empty
                {
                    engine = 0;
                    SetVehicleParamsEx(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)
                    //RemovePlayerFromVehicle(i); //remove player out of vehicle
                    GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4); //show text
                    //new string[125];format(string,sizeof string,"Fuel:%i",fuel[vid]); //preparing string with next fuel value
                    //TextDrawSetString(td_fuel[i],string); //updating textdraw
                }
        }
        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;
}

public timer_refuel(playerid)
{
    new vid = GetPlayerVehicleID(playerid);
    fuel[vid] = fuel[vid] = 100; //restoring fuel to 100
    isrefuelling[playerid] = 0;//resetting anti-spam thingy :3
    TextDrawSetString(td_fuel[playerid],"Fuel:100"); //small update on textdraw
    TogglePlayerControllable(playerid,1); //unfreeze player
}
This is my /engine command. I say /e above because i just return /engine if the user types /e.
pawn Код:
CMD:engine(playerid, params[])
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)//Checks if the player is the driver
    {
        new string[128];
        new vehicle = GetPlayerVehicleID(playerid);
        new engine,lights,alarm,doors,bonnet,boot,objective;
        GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
        if(engine == 1)//If the engine is off
        {
            format(string, sizeof(string), "%s turns the key in the ignition, turning the engine off.", GetName(playerid), params);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective);
            ISENGINEON =false;
        }
        else//Else is the engine is on
        {

            SetVehicleParamsEx(vehicle,1,0,alarm,doors,bonnet,boot,objective);
            format(string, sizeof(string), "%s places the key in the vehicles ignition and turns it, starting the engine.", GetName(playerid), params);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            ISENGINEON = true;
        }
    }
    return 1;
}
Thanks to anyone who can help really This has been driving me crazy.
Reply
#2

Well, you want to every vehicle fuel to decrease even if there is no player inside. First you need to loop through all vehicles (however I'd suggest to create iterator of fuelable vehicles, then you'd skip a lot of unnecessary iterations).

(In your engine command the comments should be swapped)

pawn Код:
else//Else is the engine is on
{
    //add this
    if(0 == fuel[vehicle]) {
        //Send some message that there is no fuel, or something
        return 1;
    }
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
snip
Thanks man it fixed the problem when you could drive for a second if you did /e after the fuel hit 0.

Do you know how I would fix the problem when the fuel must go down if the engine is on(when someone is a driver, passenger or not in the vehicle at all?)
Also, the TextDraw that shows the fuel bar works for some players and not for others, it seems like it's random on when you enter a vehicle

Thanks

My /e cmd looks like this now, is that correct?
pawn Код:
CMD:engine(playerid, params[])
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)//Checks if the player is the driver
    {
        new string[128];
        new vehicle = GetPlayerVehicleID(playerid);
        new engine,lights,alarm,doors,bonnet,boot,objective;
        GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
        if(engine == 1)//If the engine is on
        {
            if(0 == fuel[vehicle]) // if theres no
            {
                //Send some message that there is no fuel, or something
                SCM(playerid,-1,"There is no fuel!");
                return 1;
            }
            format(string, sizeof(string), "%s turns the key in the ignition, turning the engine off.", GetName(playerid), params);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            SetVehicleParamsEx(vehicle,0,0,alarm,doors,bonnet,boot,objective);
            ISENGINEON =false;
        }
        else//Else is the engine is off
        {
            SetVehicleParamsEx(vehicle,1,0,alarm,doors,bonnet,boot,objective);
            format(string, sizeof(string), "%s places the key in the vehicles ignition and turns it, starting the engine.", GetName(playerid), params);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            ISENGINEON = true;
        }
    }
    return 1;
}
Reply
#4

Nope. Now your comments are right, so think about it - you want to stop starting the engine on when there is no fuel, not disabling it.

pawn Код:
if(engine == 1)
{
    //(...)
}
else
{
    if(0 == fuel[vehicle])
    {
            SCM(playerid,-1,"There is no fuel!");
            return 1;
        }
    //(...)
}
Reply
#5

Ooh i see, didn't even notice it xD

Thanks, should that fix the problem when the fuel stops going down if I get out of the car? (When the car has no driver or passenger, the fuel stops going down.)

Thanks again.
Reply
#6

Nope. This will require you to rewrite whole system - currently you are looping through players and cars they're in - you don't cover unmanned vehicles now.
Reply
#7

Ok thanks alot for the help man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)