SA-MP Forums Archive
This sum won't calculate properly? - 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: This sum won't calculate properly? (/showthread.php?tid=323772)



This sum won't calculate properly? - Dokins - 06.03.2012

The issue is the first part.

pawn Код:
if(amount > sum) return SendClientMessage(playerid, COLOUR_GREY, "Your vehicle cannot hold this much fuel."); // This part will not return if I put the amount > sum, i.e If I put 60% instead of 50% it will still fuel the vehicle.


pawn Код:
CMD:refuel(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOUR_GREY, "You are not in a vehicle.");
    printf("Checked if in vehicle");
    new string[128];
    if(!IsPlayerInRangeOfPoint(playerid, 20.0, -240.2907,1209.9883,19.7422)&& !IsPlayerInRangeOfPoint(playerid, 50.0,-1327.7439,2675.7014,50.0625) && !IsPlayerInRangeOfPoint(playerid, 10.0, 609.0861,1698.3657,6.9922)) return SendClientMessage(playerid, COLOUR_GREY, "You must be at a Gas Station to refuel.");
        new vehicleid = GetPlayerVehicleID(playerid);
        new amount, sum, num;
       
        num = 100;
        sum = num -= VehFuel[vehicleid]; //This is the sum.

        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        if(engine == 1) return SendClientMessage(playerid, COLOUR_GREY, "Please turn your engine off before refuelling.");
        if(amount > sum) return SendClientMessage(playerid, COLOUR_GREY, "Your vehicle cannot hold this much fuel."); // This part will not return if I put the amount > sum, i.e If I put 60% instead of 50% it will still fuel the vehicle.
        if(VehFuel[vehicleid] == num)return SendClientMessage(playerid, COLOUR_GREY, "Your vehicle's fuel tank is full.");
       

        format(string, sizeof(string), "Usage: /refuel [amount] - Use /refuel %d to fill the tank. (You have %d percent fuel left.) (Cost's $2 per %%)", sum, VehFuel[vehicleid]);
        if(sscanf(params, "d", amount)) return SendClientMessage(playerid, COLOUR_GREY, string);


        RefuelTimer[playerid] = SetTimerEx("RefuelUpdate", 1000, true, "i", playerid);
        RefuelAmount[playerid] = amount;
        printf("Executed timer and set fuel amount");
        format(string, sizeof(string), "* %s has begun refuelling the vehicle. *", GetNameEx(playerid));
        ProxDetector(10.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
   
    return 1;
}



Re: This sum won't calculate properly? - Dokins - 06.03.2012

Nevermind, noticed the problem, it gets the amount after.