07.12.2014, 16:27
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.
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().