SA-MP Forums Archive
Fuel being set to an absurd amount instead of 100 - 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 being set to an absurd amount instead of 100 (/showthread.php?tid=634734)



Fuel being set to an absurd amount instead of 100 - oSAINTo - 25.05.2017

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.


Re: Fuel being set to an absurd amount instead of 100 - oSAINTo - 25.05.2017

bump


Re: Fuel being set to an absurd amount instead of 100 - Threshold - 25.05.2017

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


Re: Fuel being set to an absurd amount instead of 100 - oSAINTo - 25.05.2017

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.


Re: Fuel being set to an absurd amount instead of 100 - Toroi - 25.05.2017

Show the textdraw code.


Re: Fuel being set to an absurd amount instead of 100 - oSAINTo - 26.05.2017

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]);
        }
    }




Re: Fuel being set to an absurd amount instead of 100 - Toroi - 26.05.2017

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.


Re: Fuel being set to an absurd amount instead of 100 - Rosie - 26.05.2017

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


Re: Fuel being set to an absurd amount instead of 100 - StrikerZ - 26.05.2017

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.