Fuel being set to an absurd amount instead of 100
#1

PHP код:
case 0:
            {
                if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
                {
                    
ShowErrorDialog(playerid"You are not driving a vehicle.");
                    return 
1;
                }
                new 
vehicleid GetPlayerVehicleID(playerid);
                if(
IsBicycle(vehicleid))
                {
                    
ShowErrorDialog(playerid"Your vehicle doesn't have a fuel tank!");
                    return 
1;
                }
                if(
Fuel[vehicleid] >= 100.0)
                {
                    
ShowErrorDialog(playerid"Your vehicle fuel tank is full.");
                    
isrefuelling[playerid] = 0;
                    return 
1;
                }
                if(
GetPlayerMoney(playerid) < FUEL_PRICE)
                {
                    
ShowErrorDialog(playerid"You don't have enough money.");
                    return 
1;
                }
                
RefuelTime[playerid] = 5;
                
SetPVarFloat(playerid"Fuel"Fuel[vehicleid]);
                
GameTextForPlayer(playerid"~g~refueling..."20003);
                
isrefuelling[playerid] = 1;
            } 
PHP код:
if(RefuelTime[i] > && GetPVarInt(i"FuelStation"))
            {
                new 
vehicleid GetPlayerVehicleID(i);
                
RefuelTime[i]--;
                if(
RefuelTime[i] == 0)
                {
                    new 
stationid GetPVarInt(i"FuelStation");
                    new    
cost 100 Fuel[vehicleid] * 3;
                    new 
vid GetPlayerVehicleID(i);
                    
Fuel[vid] = 100.0;
                    if(
GetPlayerState(i) != PLAYER_STATE_DRIVER    || !IsPlayerInRangeOfPoint(i10.0FuelStationPos[stationid][0], FuelStationPos[stationid][1], FuelStationPos[stationid][2]))
                    {
                        
GivePlayerMoney(i, -cost);
                        
format(stringsizeof(string), "~r~-$%d"cost);
                        
GameTextForPlayer(istring20003);
                        
format(stringsizeof(string), "You have paid $%d for the fuel."cost);
                        
isrefuelling[i] = 0;
                        
Fuel[vid] = 100.0;
                        
SendClientMessage(iCOLOR_WHITEstring);
                        
SetPVarInt(i"FuelStation"0);
                        
SetTimer("SpeedoUpdate",100,1);
                    }
                }
            } 
I have it where you refuel your car with the /refuel command. That command brings up a dialog and the first option(case 0) is to buy gas. Everything works now except for the fuel being set to 100. It gets set to some number in the 100,000 thousand range. I can't figure out why.
Reply
#2

bump
Reply
#3

And how exactly do you know it is getting set to over 100? I don't see any debug messages.
Reply
#4

Quote:
Originally Posted by Threshold
Посмотреть сообщение
And how exactly do you know it is getting set to over 100? I don't see any debug messages.
I have a text-draw and it updates itself to the fuel amount.
Reply
#5

Show the textdraw code.
Reply
#6

PHP код:
public SpeedoUpdate()
{
    for(new 
0;i<MAX_PLAYERS;i++)
    {
        if(
IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
        {
            new 
Float:x,Float:y,Float:z,string[24];
            new 
vid GetPlayerVehicleID(i);
            
TextDrawShowForPlayer(i,box[i]);
            
TextDrawShowForPlayer(i,speed[i]);
            
GetVehicleVelocity(vid,x,y,z);
            
format(string,sizeof(string),"Speed: %dmph\nFuel:%i",floatround(floatsqroot(((x*x)+(y*y))+(z*z))*156.666667), Fuel[vid]);
            
TextDrawSetString(speed[i], string);
        }
        if(!
IsPlayerInAnyVehicle(i))
        {
            
TextDrawHideForPlayer(i,box[i]);
            
TextDrawHideForPlayer(i,speed[i]);
        }
    }

Reply
#7

your Fuel variable is a float, hence you should use %f instead of %i when formatting. The latter is for integer numbers. That's where your magical numbers come from.
Reply
#8

Hi,
After reading over your code, I've found that you set your fuel to "100.0" which is a float. However in your textdraw code, you call the fuel as an integer which is probably why you are getting a really large number on the textdraw. I think by changing the %i to %f would simply fix the issue.

Edit: nvm just a few seconds late lmao
Reply
#9

Quote:
Originally Posted by Rosie
Посмотреть сообщение
Hi,
After reading over your code, I've found that you set your fuel to "100.0" which is a float. However in your textdraw code, you call the fuel as an integer which is probably why you are getting a really large number on the textdraw. I think by changing the %i to %f would simply fix the issue.

Edit: nvm just a few seconds late lmao
1 minute difference lol.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)