SA-MP Forums Archive
Fuel - 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: Fuel (/showthread.php?tid=450596)



Fuel - RALL0 - 13.07.2013

Hey guys, I got this problem for a while now and I could not manage to solve it. The problem is that this code isn't working properly. I want that the gascan can only contain 20 maximum and if there is less then 20 in a vehicle that it takes what is in the vehicle. 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;
}



Re: Fuel - RALL0 - 13.07.2013

Anyone please?


AW: Fuel - Macronix - 13.07.2013

Can you show me the GetClosestCar function?


Re: Fuel - RALL0 - 13.07.2013

There is actually nothing wrong with that, the thing thats not working properly is that if I stealfuel for the first time it's all working fine and then the second time it's getting messed up.
Here is it tho.
pawn Код:
stock GetDistanceToCar(playerid, veh, Float: posX = 0.0, Float: posY = 0.0, Float: posZ = 0.0) {

    new
        Float: Floats[2][3];

    if(posX == 0.0 && posY == 0.0 && posZ == 0.0) {
        if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid, Floats[0][0], Floats[0][1], Floats[0][2]);
        else GetVehiclePos(GetPlayerVehicleID(playerid), Floats[0][0], Floats[0][1], Floats[0][2]);
    }
    else {
        Floats[0][0] = posX;
        Floats[0][1] = posY;
        Floats[0][2] = posZ;
    }
    GetVehiclePos(veh, Floats[1][0], Floats[1][1], Floats[1][2]);
    return floatround(floatsqroot((Floats[1][0] - Floats[0][0]) * (Floats[1][0] - Floats[0][0]) + (Floats[1][1] - Floats[0][1]) * (Floats[1][1] - Floats[0][1]) + (Floats[1][2] - Floats[0][2]) * (Floats[1][2] - Floats[0][2])));
}

stock GetClosestCar(playerid, exception = INVALID_VEHICLE_ID) {

    new
        Float: Distance,
        target = -1,
        Float: vPos[3];

    if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid, vPos[0], vPos[1], vPos[2]);
    else GetVehiclePos(GetPlayerVehicleID(playerid), vPos[0], vPos[1], vPos[2]);

    for(new v; v < MAX_VEHICLES; v++) if(GetVehicleModel(v) >= 400) {
        if(v != exception && (target < 0 || Distance > GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]))) {
            target = v;
            Distance = GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]);
        }
    }
    return target;
}



AW: Fuel - Macronix - 13.07.2013

Is FillAmount really a float value and not an integer value? Also with the Fuel of the vehicle. You could try to change the float to an integer.
And maybe add "printf" to some of the lines to get the error


Re: Fuel - RALL0 - 13.07.2013

Yea, they're both float, last time I changed them they would give me weird value's.


AW: Fuel - Macronix - 14.07.2013

Can you tell me what exactly happens when you do the command the first time and the time after?
And please add "printf" to the command at some positions for checking how much you got in your fuelcan, how much fuel the vehicle got left and how much it fills your fuelcan.


Re: Fuel - RALL0 - 14.07.2013


Well, you can see that I get 10 fuel the first time the second time it dumps the gascan fuel into the airplane and the third time it takes everything back.


AW: Fuel - Macronix - 14.07.2013

Well, i think the problem is at the calculation of the fuel... you can try to add a "floatround" at the Floats.
pawn Код:
new Float:FillAmount = floatround(20 - PlayerInfo[playerid][pCanFuel]);



Re: Fuel - RALL0 - 14.07.2013

It's doing the same thing, is there any easier way to perform this command?