Formula Issue
#1

Basically I was working on a /fuel script and none of the mathematics seem to be working properly:

pawn Код:
command(fuel, playerid, vehicleid, params[])
{
    new fuelamount;
    new neededfuel = MAX_FUEL - Vehicles[vehicleid][Fuel];
    if(sscanf(params, "d", fuelamount))
    {
        SendClientMessage(playerid, ERROR, "SYNTAX: /fuel [amount]");
    }
    else
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new calculation = REFUEL_COST / fuelamount;
            if(fuelamount > neededfuel)
            {
                SendClientMessage(playerid, ERROR, "Your vehicle cannot hold that much fuel!");
            }
            else
            {
                if(Player[playerid][Money] < calculation)
                {
                    SendClientMessage(playerid, ERROR, "You do not have enough money to refuel your vehicle.");
                }
                else
                {
                    new calculation2 = Player[playerid][Money] -= calculation;
                    new timertime = fuelamount * 1000;
                    SetPlayerMoney(playerid, calculation2);
                    TogglePlayerControllable(playerid, false);
                    SetTimerEx("Fueling", timertime, false, "i", playerid);
                    new ifuel = Vehicles[vehicleid][Fuel] + fuelamount;
                    Vehicles[vehicleid][Fuel] = ifuel;
                }
            }
        }
    }
    return 1;
}
I am completely clueless on what I am doing wrong. ??
Reply
#2

I expect that REFUEL_COST is for 100%, isnt it ?

Than its an easy cross-multiplication
Код:
100% fuel = REFULE_COST
fuelamount = calculation
pawn Код:
new calculation = (fuelamount * REFULE_COST) / 100;
Also I noticed that you create variables before you need it
pawn Код:
//
    new neededfuel = /* */; // not needed here
    if() { } else {
        if() {
            new calculation = /* */; // not needed here
            // neededfuel first time used
            if() { } else {
                // calculation first time used
                if() { } else {
                }
            }
        }
    }
Reply
#3

I am still getting warnings from those lines stating "Tag Mismatch" which is why the script hadn't been working before.
Reply
#4

show the warnings and mark the line with it, also nearly most warnings doesnt affect the result
Reply
#5

pawn Код:
C:\Documents and Settings\Nmader\Desktop\Lost Life Roleplay\gamemodes\Lost.pwn(19021) : warning 213: tag mismatch
C:\Documents and Settings\Nmader\Desktop\Lost Life Roleplay\gamemodes\Lost.pwn(19040) : warning 213: tag mismatch
pawn Код:
command(fuel, playerid, vehicleid, params[])
{
    new fuelamount;
    if(sscanf(params, "d", fuelamount))
    {
        SendClientMessage(playerid, ERROR, "SYNTAX: /fuel [amount]");
    }
    else
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new neededfuel = (MAX_FUEL - Vehicles[vehicleid][Fuel]); //line 19021
            if(fuelamount > neededfuel)
            {
                SendClientMessage(playerid, ERROR, "Your vehicle cannot hold that much fuel!");
            }
            else
            {
                new calculation = (fuelamount * REFUEL_COST) / 100;
                if(Player[playerid][Money] < calculation)
                {
                    SendClientMessage(playerid, ERROR, "You do not have enough money to refuel your vehicle.");
                }
                else
                {
                    new calculation2 = (Player[playerid][Money] - calculation);
                    new timertime = (fuelamount * 1000);
                    SetPlayerMoney(playerid, calculation2);
                    TogglePlayerControllable(playerid, false);
                    SetTimerEx("Fueling", timertime, false, "i", playerid);
                    new ifuel = (Vehicles[vehicleid][Fuel] + fuelamount); //line 19040
                    Vehicles[vehicleid][Fuel] = ifuel;
                }
            }
        }
    }
    return 1;
}
Reply
#6

all variables need to be int, most probably Vehicle[vehicleid][Fuel] is a float and MAX_FUEL could also be a float
Reply
#7

Replace

pawn Код:
new ifuel = (Vehicles[vehicleid][Fuel] + fuelamount); //line 19040
Vehicles[vehicleid][Fuel] = ifuel;
with

pawn Код:
Vehicles[vehicleid][Fuel] = floatround(Vehicles[vehicleid][Fuel] + fuelamount);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)