Fuel decreases even though velocity is 0
#1

Topic explains everything. This timer is called every 6 seconds

PHP код:
public timer_update()
{
    for(new 
i=0;i<MAX_PLAYERS;i++)
    {
        new 
Float:Velocity[3];
        new 
vid GetPlayerVehicleID(i);
          
GetVehicleVelocity(vidVelocity[0], Velocity[1], Velocity[2]);
        if(
Velocity[0] == && Velocity[1] == && Velocity[2] == 0) return 0;
        if (
isrefuelling[i]) return 0;
        if (
GetPlayerVehicleSeat(i) == 0)
        {
            if(
Engine[i] == 1)
            {
                
fuel[vid] = fuel[vid] - 1;
                if (
fuel[vid]<1)
                {
                    
fuel[vid] = 0;
                    new 
veh GetPlayerVehicleID(i);
                    new 
engine,lights,alarm,doors,bonnet,boot,objective;
                    
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
                    
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
                    
GameTextForPlayer(i,"~r~You are out of ~w~fuel~r~!",5000,4);
                    
Engine[i] = 0;
                }
            }
        }
        new 
string[128];
        
format(string,sizeof string,"~b~Fuel: ~w~%i%"fuel[vid]);
        
PlayerTextDrawSetString(ivehFuel[i],string);
    }
    return 
1;

Reply
#2

I am not a pawn expert but maybe you shouldn't compare Floats with Integers (e.g. Velocity[0] == 0).
Try to change this to Velocity[0] == 0.0.
Reply
#3

You shouldn't compare floating point values with the equality operator anyway. Floating point values are not exact due the way they work and rounding errors may occur. For example, 3.6 will be read back as 3.5999999046325684. This is fine for most purposes because you don't need this exact precision but when comparing them they are not the same.

You should try printing the individual values of the velocity and see what they actually contain.
Reply
#4

This timer will stop (crash) when someone is not in vehicle. You are not checking if vehicle id is valid before using vid variable. Also, you are returning 0 in loop - use continue; instead.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)