Posts: 3,324
Threads: 96
Joined: Sep 2013
Quote:
Originally Posted by kvann
pawn Код:
CMD:removeallcars(playerid) { foreach (new i : Vehicle) DestroyVehicle(i); SendClientMessage(playerid, 0xFFFFFFFF, "All vehicles destroyed!"); return 1; }
Using default iterators is resulting in server freeze because of the same thing: http://forum.sa-mp.com/showpost.php?...3&postcount=61 I guess I could temporarily fix it with a timer but I'd like to see a solution for it.
|
The solution is the same as the above, SafeRemove. Of course you need to store the ID and remove the vehicle AFTER removing from the iterator like this:
pawn Код:
stock SafeDestroyVehicle(veh, Iterator:iter<>, &next)
{
if(IsValidVehicle(veh))
Iter_SafeRemove(iter, veh, next);
return DestroyVehicle(veh);
}
//USE:
foreach (new i : Vehicle) SafeDestroyVehicle(i, Vehicle, i);
This SHOULD work. It may require a custom vehicle iterator, but it shouldn't because we are actually tricking y_iterate here (since DestroyVehicle is also going to call Iter_Remove, but Iter_Remove won't be receiving a valid vehicle ID because we already removed it).