float-int problem?
#1

Hello! Why does it returns me ingame the "You don't have enough money message", even if I do have enough money?

PHP код:
CMD:refill(playeridparams[])
{
    new 
Float:v=100.0;
    
v-=CarFuel[GetPlayerVehicleID(playerid)];
    
v/=100.0;
    
v*=BusinessInfo[23][bFee];
    if(
GetPlayerMoney(playerid) >= floatround(v))
    {
        
formatfillstringsizeof(fillstring), "You payed {FFFFFF}%d"ORANGESV"$ to refill your car's fuel."floatround(v));
        
BusinessInfo[23][bMoney] += floatround(v);
        
GivePlayerTheMoney(playerid, - floatround(v));
        
SCM(playeridORANGESfillstring);
        foreach(
Playeri)
        {
            if(
GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
            {
                
KillTimer(CarTimer[playerid]);
                
TogglePlayerControllable(i0);
                
FillTimer[playerid] = SetTimerEx("Fill"250false"i"i);
            }
        }
    }
    else 
SCM(playeridCOLOR_DGREY"You don't have enough money.");
    return 
1;

Reply
#2

So basically you are checking its equal to or greater then you need to do is

PHP код:
if(GetPlayerMoney(playerid) >= 100)// this means < is greater and = this is equal and it will check if floatround money is greater then getplayermoney or equal to floatroundthen it will send that message
{
             
//it will check for money if he have 100 or above then account will be performed
}
else
{
          
// here if player money is below then 100 it will send message you dont have enough money

Reply
#3

why you use floatround here ? and the condition is oke, but i think the flotround not work correctly.
Reply
#4

I want to get an int number from his money, not float)
Reply
#5

Quote:
Originally Posted by SumX
Посмотреть сообщение
Hello! Why does it returns me ingame the "You don't have enough money message", even if I do have enough money?

PHP код:
CMD:refill(playeridparams[])
{
    new 
Float:v=100.0;
    
v-=CarFuel[GetPlayerVehicleID(playerid)];
    
v/=100.0;
    
v*=BusinessInfo[23][bFee];
    if(
GetPlayerMoney(playerid) >= floatround(v))
    {
        
formatfillstringsizeof(fillstring), "You payed {FFFFFF}%d"ORANGESV"$ to refill your car's fuel."floatround(v));
        
BusinessInfo[23][bMoney] += floatround(v);
        
GivePlayerTheMoney(playerid, - floatround(v));
        
SCM(playeridORANGESfillstring);
        foreach(
Playeri)
        {
            if(
GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid))
            {
                
KillTimer(CarTimer[playerid]);
                
TogglePlayerControllable(i0);
                
FillTimer[playerid] = SetTimerEx("Fill"250false"i"i);
            }
        }
    }
    else 
SCM(playeridCOLOR_DGREY"You don't have enough money.");
    return 
1;

You multiply variable BusinessInfo [23] [bMoney] *= floatround (v);

But in format(...);

BusinessInfo[23][bMoney] += floatround(v);

In this message displays do not have enough money

NOTE: Be careful when calculating
And if you do not believe debugging
Reply
#6

No Logo, he is using [bFee] to multiply, and [bMoney] to increase.

pawn Код:
CMD:refill(playerid, params[])
{
    new car = GetPlayerVehicleID(playerid);
    if(car)
    {
        new Float:v = (((100.0 - ((0.0 <= CarFuel[car] <= 100.0) ? (CarFuel[car]) : (100.0))) / 100.0) * BusinessInfo[23][bFee]), round = floatround(v);
        if(GetPlayerMoney(playerid) < round) return SCM(playerid, COLOR_DGREY, "You don't have enough money.");
        new fstr[70];
        format(fstr, sizeof(fstr), "You paid {FFFFFF}%d"ORANGESV"$ to refill your car's fuel.", round);
        BusinessInfo[23][bMoney] += round;
        GivePlayerTheMoney(playerid, -round);
        SCM(playerid, ORANGES, fstr);
        KillTimer(CarTimer[playerid]);
        FillTimer[playerid] = SetTimerEx("Fill", 250, false, "i", playerid);
        foreach(Player, i)
        {
            if(GetPlayerVehicleID(i) == car)
                TogglePlayerControllable(i, 0);
        }
    }
    //else SCM(playerid, COLOR_DGREY, "You are not in a vehicle.");
    return 1;
}
You also fail to check if the player is in a vehicle when using /refill.

I have an issue with this line:
pawn Код:
FillTimer[playerid] = SetTimerEx("Fill", 250, false, "i", playerid);
What parameter is meant to be passed through this? I'm assuming 'playerid' here, but it didn't belong in the loop, so I took it out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)