OnVehicleUpdate (License exam)
#1

I have an issue where failing the license exam only works with DMV_Vehicle[1] and not 2,3,4, etc.
I'm probably missing something quite obvious but I need y'all s help.
Thanks in advance.

PHP код:
function:OnVehicleUpdate()
{
    new
        
Float:vehicle_health
    
;
    for (new 
1GetVehiclePoolSize(); <= ji++)
    for (new 
0sizeof dmv_vehiclesi++)
    {
        
GetVehicleHealth(ivehicle_health);
        if(
== dmv_vehicles[q])
        {
            if(
vehicle_health <= 850)
            {
                new 
playerid CheckDriver(i);
                
StopDriverstest(playerid);
                
SCM(playerid, -1"You're too reckless! You failed your driversexam.");
            }
            return 
1;
        }
        if(
vehicle_health <= 300)
        {
            
SetVehicleHealth(i300);
            
ToggleVehicleEngine(ifalse); VehicleInfo[i][eVehicleEngineStatus] = false;
        }
        if(
VehicleInfo[i][eVehicleFuel] <= 0)
         {
             
ToggleVehicleEngine(ifalse); VehicleInfo[i][eVehicleEngineStatus] = false;
          }
    }
    return 
1;

Reply
#2

Код:
for (new q = 0; i < sizeof dmv_vehicles; i++)
Reply
#3

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
Код:
for (new q = 0; i < sizeof dmv_vehicles; i++)
Ah well, yes indeed.
I still have the issue that this only works for dmv_vehicles[0] tough.
PHP код:
if(vehicle_health <= 850

      new 
playerid CheckDriver(i); 
      
StopDriverstest(playerid); 
      
SCM(playerid, -1"You're too reckless! You failed your driversexam."); 

return 
1
Reply
#4

Maybe this?

pawn Код:
CheckDriver(q);
Reply
#5

Quote:
Originally Posted by Dignity
Посмотреть сообщение
Maybe this?

pawn Код:
CheckDriver(q);
Nope. But thanks for thinking with me!
Reply
#6

The return always stops the whole function on the first time a DMV vehicle was found (including the outer loop which should not be stopped).

Furthermore you can optimize this a lot by moving the health checks on non-DMV vehicles out of the second loop.

Код:
for (new i = 1, j = GetVehiclePoolSize(); i <= j; i++)
{
    GetVehicleHealth(i, vehicle_health);

    if(vehicle_health <= 300)
    {
        SetVehicleHealth(i, 300);
        ToggleVehicleEngine(i, false); VehicleInfo[i][eVehicleEngineStatus] = false;
    }
    if(VehicleInfo[i][eVehicleFuel] <= 0)
    {
        ToggleVehicleEngine(i, false); VehicleInfo[i][eVehicleEngineStatus] = false;
    }

    for (new q = 0; q < sizeof dmv_vehicles; q++)
    {
        if(i == dmv_vehicles[q])
        {
            if(vehicle_health <= 850)
            {
                new playerid = CheckDriver(i);
                StopDriverstest(playerid);
                SCM(playerid, -1, "You're too reckless! You failed your driversexam.");
            }

            break;
        }
    } 
}
Reply
#7

Quote:
Originally Posted by NaS
Посмотреть сообщение
The return always stops the whole function on the first time a DMV vehicle was found (including the outer loop which should not be stopped).

Furthermore you can optimize this a lot by moving the health checks on non-DMV vehicles out of the second loop.

Код:
for (new i = 1, j = GetVehiclePoolSize(); i <= j; i++)
{
    GetVehicleHealth(i, vehicle_health);

    if(vehicle_health <= 300)
    {
        SetVehicleHealth(i, 300);
        ToggleVehicleEngine(i, false); VehicleInfo[i][eVehicleEngineStatus] = false;
    }
    if(VehicleInfo[i][eVehicleFuel] <= 0)
    {
        ToggleVehicleEngine(i, false); VehicleInfo[i][eVehicleEngineStatus] = false;
    }

    for (new q = 0; q < sizeof dmv_vehicles; q++)
    {
        if(i == dmv_vehicles[q])
        {
            if(vehicle_health <= 850)
            {
                new playerid = CheckDriver(i);
                StopDriverstest(playerid);
                SCM(playerid, -1, "You're too reckless! You failed your driversexam.");
            }

            break;
        }
    } 
}
Hero! Thank you very much. I'll Rep you when I can do so again.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)