[Tutorial] Vehicle System "Engine & Lights".
#8

In that for-loop, shouldn't you check if the vehicle exists first before setting parameters on it?
You "might" get unexpected results if you're trying to set vehicleparameters on a non-existing vehicle.

Also, use GetVehicleParamsEx first, as some people may create vehicles and set objective to 1 for example when the server starts.
Setting all default values would overwrite all those settings.

Finally, place "new engine, lights, alarm, doors, bonnet, boot, objective; // Required variables." outside the loop.
It has no use to re-create the variables 2000 times (for each iteration of the loop).
Just create them once, then enter the loop.

pawn Code:
new engine, lights, alarm, doors, bonnet, boot, objective; // Required variables.
for(new i; i < MAX_VEHICLES; i++) // This is the loop if i is smaller then MAX VEHICLES it will continue.
{
    if (GetVehicleModel(i) != 0) // Check if the vehicle exists
    {
        GetVehicleParamsEx(i, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(i, 0, 0, alarm, doors, bonnet, boot, objective); // Keep all parameters, but turn engine and lights off
    }
}
return 1;
// Put the code above at end of InGameInit().
Reply


Messages In This Thread
Vehicle System "Engine & Lights". - by Gogeta - 08.11.2014, 19:54
Re: Vehicle System "Engine & Lights". - by sammp - 08.11.2014, 19:58
Re: Vehicle System "Engine & Lights". - by Gogeta - 08.11.2014, 20:00
Re: Vehicle System "Engine & Lights". - by MrBlake - 07.12.2014, 08:06
Re: Vehicle System "Engine & Lights". - by LivingLikeYouDo - 07.12.2014, 11:57
Re: Vehicle System "Engine & Lights". - by n0minal - 07.12.2014, 14:04
Re: Vehicle System "Engine & Lights". - by MrBlake - 07.12.2014, 15:57
Re: Vehicle System "Engine & Lights". - by PowerPC603 - 07.12.2014, 16:27

Forum Jump:


Users browsing this thread: 2 Guest(s)