Portal SAMP
[Ajuda] Erro na float? - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] Erro na float? (/showthread.php?tid=1596)



Erro na float? - guigowbr - 03/09/2021

Olá rapazes! 


Meu sistema de Gasolina está em Float, todo veiculo tem VehicleData[c][vFuel] = 100.0;

https://imgur.com/a/3HaMHN2

Porém o TextDrawn carrega 112, como arrumar isto?

Essa é minha função que mostra a Velocidade e a Gasolina
Código PHP:
    format(stringsizeof(string), "Gasolina: %d"VehicleData[vehicleid][vFuel]); //%03d
    
PlayerTextDrawSetString(playeridviewgasolina[playerid], string);
    
PlayerTextDrawShow(playeridviewgasolina[playerid]); 

Está é a função que diminui a gasolina quando ligado o veiculo
Código PHP:
forward FuelTimer(vehicleid);
public 
FuelTimer(vehicleid)
{
    new enginelightsalarmdoorsbonnetbootobjective;
    
GetVehicleParamsEx(vehicleidenginelightsalarmdoorsbonnetbootobjective);
    if(
engine 0)
    {
    
    VehicleData[vehicleid][vFuel] -= 0.08;
    
    return 1;
    }
    if(
VehicleData[vehicleid][vFuel] <= 0)
    {
    
    VehicleData[vehicleid][vFuel] = 0.00;
        
SetVehicleParamsEx(vehicleid00alarmdoorsbonnetbootobjective);
         
KillTimer(VehicleData[vehicleid][vTimer]);
        for(new 
0MAX_PLAYERSi++) // Se der algo problema na gasolina, tirar isso
        
{
            if(
IsPlayerInVehicle(ivehicleid) && GetPlayerVehicleSeat(i) == 0)
            {
                
SendClientMessage(i, -1"Veículo sem combutível!");
                break;
            }
        }
    }
    return 
1;




RE: Erro na float? - SrBlue - 03/09/2021

(03/09/2021 22:16)guigowbr Escreveu: Olá rapazes! 


Meu sistema de Gasolina está em Float, todo veiculo tem VehicleData[c][vFuel] = 100.0;

https://imgur.com/a/3HaMHN2

Porém o TextDrawn carrega 112, como arrumar isto?

Essa é minha função que mostra a Velocidade e a Gasolina
Código PHP:
    format(stringsizeof(string), "Gasolina: %d"VehicleData[vehicleid][vFuel]); //%03d
    
PlayerTextDrawSetString(playeridviewgasolina[playerid], string);
    
PlayerTextDrawShow(playeridviewgasolina[playerid]); 

Está é a função que diminui a gasolina quando ligado o veiculo
Código PHP:
forward FuelTimer(vehicleid);
public 
FuelTimer(vehicleid)
{
    new enginelightsalarmdoorsbonnetbootobjective;
    
GetVehicleParamsEx(vehicleidenginelightsalarmdoorsbonnetbootobjective);
    if(
engine 0)
    {
    
    VehicleData[vehicleid][vFuel] -= 0.08;
    
    return 1;
    }
    if(
VehicleData[vehicleid][vFuel] <= 0)
    {
    
    VehicleData[vehicleid][vFuel] = 0.00;
        
SetVehicleParamsEx(vehicleid00alarmdoorsbonnetbootobjective);
         
KillTimer(VehicleData[vehicleid][vTimer]);
        for(new 
0MAX_PLAYERSi++) // Se der algo problema na gasolina, tirar isso
        
{
            if(
IsPlayerInVehicle(ivehicleid) && GetPlayerVehicleSeat(i) == 0)
            {
                
SendClientMessage(i, -1"Veículo sem combutível!");
                break;
            }
        }
    }
    return 
1;



tenta utilizar:

Código PHP:
format(stringsizeof(string), "Gasolina: %d%"VehicleData[vehicleid][vFuel]); //%03d 



RE: Erro na float? - ProKillerPa - 03/09/2021

Voce esta utilizando %d ao inves de usar %f.

Lembre-se, %d = INT, %f = FLOAT.

Código PHP:
format(stringsizeof(string), "Gasolina: %f%"VehicleData[vehicleid][vFuel]); //%03d 

Abraços


RE: Erro na float? - guigowbr - 03/09/2021

(03/09/2021 22:16)guigowbr Escreveu: Olá rapazes! 


Meu sistema de Gasolina está em Float, todo veiculo tem VehicleData[c][vFuel] = 100.0;

https://imgur.com/a/3HaMHN2

Porém o TextDrawn carrega 112, como arrumar isto?

Essa é minha função que mostra a Velocidade e a Gasolina
Código PHP:
    format(stringsizeof(string), "Gasolina: %d"VehicleData[vehicleid][vFuel]); //%03d
    
PlayerTextDrawSetString(playeridviewgasolina[playerid], string);
    
PlayerTextDrawShow(playeridviewgasolina[playerid]); 

Está é a função que diminui a gasolina quando ligado o veiculo
Código PHP:
forward FuelTimer(vehicleid);
public 
FuelTimer(vehicleid)
{
    new enginelightsalarmdoorsbonnetbootobjective;
    
GetVehicleParamsEx(vehicleidenginelightsalarmdoorsbonnetbootobjective);
    if(
engine 0)
    {
    
    VehicleData[vehicleid][vFuel] -= 0.08;
    
    return 1;
    }
    if(
VehicleData[vehicleid][vFuel] <= 0)
    {
    
    VehicleData[vehicleid][vFuel] = 0.00;
        
SetVehicleParamsEx(vehicleid00alarmdoorsbonnetbootobjective);
         
KillTimer(VehicleData[vehicleid][vTimer]);
        for(new 
0MAX_PLAYERSi++) // Se der algo problema na gasolina, tirar isso
        
{
            if(
IsPlayerInVehicle(ivehicleid) && GetPlayerVehicleSeat(i) == 0)
            {
                
SendClientMessage(i, -1"Veículo sem combutível!");
                break;
            }
        }
    }
    return 
1;


Amigo, infelizmente não mudou nada.


RE: Erro na float? - SrBlue - 03/09/2021

então tente utilizar:
format(string, sizeof(string), "Gasolina: %0f", VehicleData[vehicleid][vFuel]);


RE: Erro na float? - ProKillerPa - 03/09/2021

Manda a função inteira onde voce usa esse format pra alterar a string da txd.


RE: Erro na float? - xbruno1000x - 03/09/2021

Existe chance do VehicleData[vehicleid][vFuel] estar sendo aumentado em algum lugar?


RE: Erro na float? - guigowbr - 03/09/2021

Pessoal eu não deixei mais a vFuel como Float e deu certo.

O sistema é o seguinte, o player liga o veiculo e chama uma função de 1 em um segundo, perdendo -1 de gasolina.

Está funcionando tudo corretamente, porém isso daria apenas 100 segundos de combustível.  Alguém tem uma sugestão? Se eu deixar em Float buga novamente.

---------------------------------------------------

Código PHP:
forward FuelTimer(vehicleid);
public 
FuelTimer(vehicleid)
{
    new enginelightsalarmdoorsbonnetbootobjective;
    
GetVehicleParamsEx(vehicleidenginelightsalarmdoorsbonnetbootobjective);
    if(
engine 0)
    {
    
    VehicleData[vehicleid][vFuel] -= 1;
    }
    if(
VehicleData[vehicleid][vFuel] <= 0)
    {
    
    VehicleData[vehicleid][vFuel] = 0;
        
SetVehicleParamsEx(vehicleid00alarmdoorsbonnetbootobjective);
         
KillTimer(VehicleData[vehicleid][vTimer]);
        for(new 
0MAX_PLAYERSi++) // Se der algo problema na gasolina, tirar isso
        
{
            if(
IsPlayerInVehicle(ivehicleid) && GetPlayerVehicleSeat(i) == 0)
            {
                
SendClientMessage(i, -1"Sua gasolina acabou!");
                
SetVehicleParamsEx(vehicleid00alarmdoorsbonnetbootobjective);
                break;
            }
        }
    }
    return 
1;


Esse aqui é o Código que edita o TextDrawn ( meu velocimetro ).

Código PHP:
forward ProcessGasolina(playerid);
public 
ProcessGasolina(playerid)
{
    new vehicleid GetPlayerVehicleID(playerid);
    if(!IsPlayerInVehicle(playeridvehicleid))
    {
        PlayerTextDrawHide(playeridviewgasolina[playerid]);
        PlayerTextDrawHide(playeridviewlataria[playerid]);
        return 
1;
    }
    new 
string[14], string2[22];
    
format(stringsizeof(string), "Gasolina: %d%"VehicleData[vehicleid][vFuel]);//%03d
    
PlayerTextDrawSetString(playeridviewgasolina[playerid], string);
    
PlayerTextDrawShow(playeridviewgasolina[playerid]);
     if(
GetPlayerSpeed(playeridtrue) >= 150)
    {
        
format(string2,sizeof(string2),"Velocidade: %d Km/h",GetPlayerSpeed(playeridtrue));
        
PlayerTextDrawSetString(playeridviewlataria[playerid], string2);
        
PlayerTextDrawShow(playeridviewlataria[playerid]);
    }
    else
    {
        
format(string2,sizeof(string2),"Velocidade: %d Km/h",GetPlayerSpeed(playeridtrue));
        
PlayerTextDrawSetString(playeridviewlataria[playerid], string2);
        
PlayerTextDrawShow(playeridviewlataria[playerid]);
    }
    return 
1;




RE: Erro na float? - Um cara ai - 03/09/2021

Eu queria saber porque no format o float esta sendo tratado como um valor inteiro '-'

COMO ESTA:
format(string, sizeof(string), "%d", valor_float);

COMO CORRIGIR:
format(string, sizeof(string), "%f", valor_float);

OU:
format(string, sizeof(string), "%d", floatround(valor_float));