Will this loop cause any issues with lag? Vehicle Fuel.
#1

pawn Код:
public FuelUpdate()
{
    for(new i = 0;i<MAX_VEHICLES;i++)
    {
        if(GetVehicleModel(i))
        {
            new engine, lights, alarm, doors, bonnet, boot, objective;
            GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
            if(engine == 1)
            {
                if(VehFuel[i] > 0)
                {
                    VehFuel[i]--;
                }
                if(VehFuel[i] == 0)
                {
                    SetVehicleParamsEx(i,0,lights,alarm,doors,bonnet,boot,objective);
                    if(VehicleSQLID[i] > 0)
                    {
                        MySQL_SetInteger(VehicleSQLID[i], "VehFuel", VehFuel[i], "vehicles");
                    }
                }
            }
        }
    }
}

Title says all.

Basically, I know it's looping every single car, every 30 seconds. Is there a more efficient way of doing it?
Reply
#2

So basically why saving the vehicle fuel every 30 seconds while it did already save? Here is a small check.

Код:
native IsValidVehicle(vehicleid);

static
	bool:V_cansave[MAX_VEHICLES char];

public FuelUpdate()
{
	for (new i = 0; i != MAX_VEHICLES; i++)
	{
		if (!IsValidVehicle(i))
			continue;

		new 
			engine, 
			lights, 
			alarm, 
			doors, 
			bonnet, 
			boot, 
			objective
		;

		GetVehicleParamsEx(i, engine, lights, alarm, doors, bonnet, boot, objective);
		
		if (engine)
		{
			if (VehFuel[i] > 0) {
				V_cansave{i} = true;
				VehFuel[i]--;
			}

			if (!VehFuel[i])
			{
				SetVehicleParamsEx(i, 0, lights, alarm, doors, bonnet, boot, objective);
				
				if (VehicleSQLID[i] > 0) 
				{
					if (V_cansave{i})
					{
						V_cansave{i} = false;
						MySQL_SetInteger(VehicleSQLID[i], "VehFuel", 0, "vehicles");
					}
				}
			}
		}
	}
}
Reply
#3

And this won't cause lag?
Reply
#4

No It wont cause any lag
Reply
#5

Thanks a lot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)