Need help with fuel
#1

Guys, I got a little problem with this cmd, it works actually how I wanted it to work but there is one thing that I need help with. Once I steel fuel from a car I get the fuel in the can, but then I type the cmd again and then the gas can status is 0 while it was full before that . I hope you guys can keep up. Here are the codes.
pawn Код:
CMD:stealfuel(playerid, params[])
{
    if(PlayerInfo[playerid][pCan] == 1 && PlayerInfo[playerid][pSiphon] == 1)
    {
        new closestcar = GetClosestCar(playerid);
        new string[128];
        if(IsPlayerInRangeOfVehicle(playerid, closestcar, 7.0))
        {
            if(Fuel[closestcar] == 0)
            {
                format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank",RPN(playerid));
                ProxDetector(30.0, playerid, string, COLOR_PURPLE);
                SendClientMessage(playerid, COLOR_YELLOW,"This vehicle is out of fuel.");
            }
            else if(Fuel[closestcar] > 0)
            {
                if(PlayerInfo[playerid][pCanFuel] == 20) return SendClientMessage(playerid, COLOR_YELLOW,"Your gascan is full.");
                new Float:FillAmount = 20 - PlayerInfo[playerid][pCanFuel];

                    if((Fuel[closestcar] - FillAmount) < 0)
                    {
                         PlayerInfo[playerid][pCanFuel] += Fuel[closestcar];
                         Fuel[closestcar] = 0.0;
                         format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan, but extracts nothing from the empty gastank.",RPN(playerid));
                         ProxDetector(30.0, playerid, string, COLOR_PURPLE);
                    }
                    else
                    {
                        PlayerInfo[playerid][pCanFuel] += FillAmount;
                        Fuel[closestcar] -= FillAmount;
                        format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan.",RPN(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE);
                    }
            }
        }
        else
        {
        SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You aren't near any vehicle.");
        }
    }
    else
    {
    SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}Make sure you got a gascan and a siphon in order to steal fuel.");
    }
    return 1;
}
Reply
#2

pawn Код:
new Float:FillAmount = 20; // try to remove the  PlayerInfo[playerid][pCanFuel] this should be fixed somehow.

                    if((Fuel[closestcar] - FillAmount) < 0)
                    {
                         PlayerInfo[playerid][pCanFuel] += Fuel[closestcar];
                         Fuel[closestcar] = 0.0;
                         format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan, but extracts nothing from the empty gastank.",RPN(playerid));
                         ProxDetector(30.0, playerid, string, COLOR_PURPLE);
                    }
                    else
                    {
                        PlayerInfo[playerid][pCanFuel] += FillAmount;
                        Fuel[closestcar] -= FillAmount;
                        format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan.",RPN(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE);
                    }
Reply
#3

Nope, not working, giving weird amounts of fuel now instead of 20.
Reply
#4

Simplifying it a bit...moving some stuff around. Does this do the same thing?
pawn Код:
CMD:stealfuel(playerid, params[])
{
    if(PlayerInfo[playerid][pCan] == 1 && PlayerInfo[playerid][pSiphon] == 1)
    {
        if(PlayerInfo[playerid][pCanFuel] >= 20) return SendClientMessage(playerid, COLOR_YELLOW,"Your gascan is full.");
       
        new closestcar = GetClosestCar(playerid);
        new string[128];
        if(IsPlayerInRangeOfVehicle(playerid, closestcar, 7.0))
        {
            if(Fuel[closestcar] <= 0)
            {
                format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan, but extracts nothing from the empty gastank.",RPN(playerid));
                ProxDetector(30.0, playerid, string, COLOR_PURPLE);
            }
            else
            {
                new Float:FillAmount = 20 - PlayerInfo[playerid][pCanFuel];

                PlayerInfo[playerid][pCanFuel] += FillAmount;
                Fuel[closestcar] -= FillAmount;
                format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan.",RPN(playerid));
                ProxDetector(30.0, playerid, string, COLOR_PURPLE);
               
                if(Fuel[closestcar] < 0) Fuel[closestcar] = 0.0;
                if(PlayerInfo[playerid][pCanFuel] > 20) PlayerInfo[playerid][pCanFuel]=20;

            }
        }
        else SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You aren't near any vehicle.");
    }
    else SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}Make sure you got a gascan and a siphon in order to steal fuel.");
    return 1;
}
Reply
#5

Well, I tried that but it's not working properly tho, like if a vehicle got only 5 fuel in a car I get 20 fuel. My code isn't doing that but somehow it's automaticly back to 0 after I try to stealfuel the second time.
Reply
#6

Bump
Reply
#7

This should work for you.

pawn Код:
CMD:stealfuel(playerid, params[])
{
    if(PlayerInfo[playerid][pCan] == 1 && PlayerInfo[playerid][pSiphon] == 1)
    {
        if(PlayerInfo[playerid][pCanFuel] < 20.0)
        {
            new closestcar = GetClosestCar(playerid);
            new string[128];
            if(IsPlayerInRangeOfVehicle(playerid, closestcar, 7.0))
            {
                if(Fuel[closestcar] < 1.0)
                {
                    format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan, but extracts nothing from the empty gastank.",RPN(playerid));
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE);
                }
                else
                {
                    new Float:FillAmount = 20.0 - PlayerInfo[playerid][pCanFuel];
                    if(Fuel[closestcar] - FillAmount < 0.0) FillAmount = Fuel[closestcar];
                    PlayerInfo[playerid][pCanFuel] += FillAmount;
                    Fuel[closestcar] -= FillAmount;
                    format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan.",RPN(playerid));
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE);
                }
            }
            else SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You aren't near any vehicle.");
        }
        else SendClientMessage(playerid, COLOR_YELLOW,"Your gascan is full.");
    }
    else SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}Make sure you got a gascan and a siphon in order to steal fuel.");
    return 1;
}
Reply
#8

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
This should work for you.

pawn Код:
CMD:stealfuel(playerid, params[])
{
    if(PlayerInfo[playerid][pCan] == 1 && PlayerInfo[playerid][pSiphon] == 1)
    {
        if(PlayerInfo[playerid][pCanFuel] < 20.0)
        {
            new closestcar = GetClosestCar(playerid);
            new string[128];
            if(IsPlayerInRangeOfVehicle(playerid, closestcar, 7.0))
            {
                if(Fuel[closestcar] < 1.0)
                {
                    format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan, but extracts nothing from the empty gastank.",RPN(playerid));
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE);
                }
                else
                {
                    new Float:FillAmount = 20.0 - PlayerInfo[playerid][pCanFuel];
                    if(Fuel[closestcar] - FillAmount < 0.0) FillAmount = Fuel[closestcar];
                    PlayerInfo[playerid][pCanFuel] += FillAmount;
                    Fuel[closestcar] -= FillAmount;
                    format(string,sizeof(string),"* %s opens the bottom of the vehicles gas tank, uses their siphon to drain the gasoline into the gascan.",RPN(playerid));
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE);
                }
            }
            else SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You aren't near any vehicle.");
        }
        else SendClientMessage(playerid, COLOR_YELLOW,"Your gascan is full.");
    }
    else SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}Make sure you got a gascan and a siphon in order to steal fuel.");
    return 1;
}

So this is what we're dealing with, I tried your code but the results are same , I set the fuel of the vehicle to 10. You can clearly see at the image. Then I steal I get 10 fuel I try again and there is no fuel, it's going all great till this point. I set it back to 10, steal and my gascan is all off sudden 0. And then the second time when the vehicle is supposed to be 0 it's giving me the 20. So this means only one thing, my gascan fuel went back into the plane then I took it back.
Reply
#9

Bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)