SA-MP Forums Archive
Need help with a CMD - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help with a CMD (/showthread.php?tid=449514)



Need help with a CMD - RALL0 - 09.07.2013

Guys, I got a little problem over here with /stealfuel. Using the cmd the first time is fine, everythig works as I wanted to. But then the second time I use the CMD the fuel that was already in my gascan goes back into the vehicle, 3rd time I use the CMD it reverses and takes the fuel of the vehicle, here are the codes tho.
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;
}



Re: Need help with a CMD - RALL0 - 09.07.2013

BUMP


Re: Need help with a CMD - Calabresi - 09.07.2013

Can you turn this code;

pawn Код:
if(PlayerInfo[playerid][pCanFuel] == 20) return SendClientMessage(playerid, COLOR_YELLOW,"Your gascan is full.");
To;

pawn Код:
if(PlayerInfo[playerid][pCanFuel] >= 20) return SendClientMessage(playerid, COLOR_YELLOW,"Your gascan is full.");
And tell us if it still does the same thing?


Re: Need help with a CMD - RALL0 - 09.07.2013

I tried that, if the vehicle fuel is 5 it somehow extracts 20 out of it.


Re: Need help with a CMD - Misiur - 09.07.2013

Code itself seems fine.
Quote:

But then the second time I use the CMD the fuel that was already in my gascan goes back into the vehicle

How do you know that?
The problem might lay in floats precision.

A little refactored version of the code
pawn Код:
CMD:stealfuel(playerid, params[])
{
    #define CAPACITY (20.0)
    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);
                return SendClientMessage(playerid, COLOR_YELLOW,"This vehicle is out of fuel.");
            }
           
            if(PlayerInfo[playerid][pCanFuel] >= CAPACITY) return SendClientMessage(playerid, COLOR_YELLOW,"Your gascan is full.");
           
            new Float:FillAmount = CAPACITY - PlayerInfo[playerid][pCanFuel];
            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));
            if((Fuel[closestcar] - FillAmount) < 0) {
                FillAmount = Fuel[closestcar];
                strcat(string, ", but extracts nothing from the empty gastank.");
            }
            PlayerInfo[playerid][pCanFuel] += FillAmount;
            Fuel[closestcar] -= FillAmount;
            return ProxDetector(30.0, playerid, string, COLOR_PURPLE);
        }
        else return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You aren't near any vehicle.");
    }
    else return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}Make sure you got a gascan and a siphon in order to steal fuel.");
}



Re: Need help with a CMD - RALL0 - 09.07.2013

Well, this time I get a much different result but not close to the one I wanted it to be.
This did not happen with my code and I am sure that it did put the fuel back the second time I tried.


Re: Need help with a CMD - RALL0 - 09.07.2013

Anyone?


Re: Need help with a CMD - RALL0 - 09.07.2013

BUMP


Re: Need help with a CMD - RALL0 - 09.07.2013

BUMP


Re: Need help with a CMD - RALL0 - 10.07.2013

BUMP