Merge pull request #822 from vbawol/2nd

Fix SpawnVehicle #821
This commit is contained in:
vbawol
2013-12-02 14:35:09 -08:00

View File

@@ -212,38 +212,33 @@ BuildingList = [];
} forEach (MarkerPosition nearObjects ["building",DynamicVehicleArea]); } forEach (MarkerPosition nearObjects ["building",DynamicVehicleArea]);
spawn_vehicles = { spawn_vehicles = {
private ["_weights","_isOverLimit","_isAbort","_counter","_index","_vehicle","_velimit","_qty","_isAir","_isShip","_position","_dir","_istoomany","_veh","_objPosition","_marker","_iClass","_itemTypes","_cntWeights","_itemType","_num","_allCfgLoots"]; private ["_random","_lastIndex","_weights","_index","_vehicle","_velimit","_qty","_isAir","_isShip","_position","_dir","_istoomany","_veh","_objPosition","_marker","_iClass","_itemTypes","_cntWeights","_itemType","_num","_allCfgLoots"];
if (isDedicated) then { if (isDedicated) then {
_isOverLimit = true; while {count AllowedVehiclesList > 0} do {
_isAbort = false; // BIS_fnc_selectRandom replaced because the index may be needed to remove the element
_counter = 0; _index = floor random count AllowedVehiclesList;
while {_isOverLimit} do { _random = AllowedVehiclesList select _index;
waitUntil{!isNil "BIS_fnc_selectRandom"}; _vehicle = _random select 0;
_index = AllowedVehiclesList call BIS_fnc_selectRandom; _velimit = _random select 1;
_vehicle = _index select 0;
_velimit = _index select 1;
_qty = {_x == _vehicle} count serverVehicleCounter; _qty = {_x == _vehicle} count serverVehicleCounter;
// If under limit allow to proceed // If under limit allow to proceed
if(_qty <= _velimit) then { if (_qty <= _velimit) exitWith {};
_isOverLimit = false;
};
// counter to stop after 5 attempts // vehicle limit reached, remove vehicle from list
_counter = _counter + 1; // since elements cannot be removed from an array, overwrite it with the last element and cut the last element of (as long as order is not important)
_lastIndex = (count AllowedVehiclesList) - 1;
if(_counter >= 5) then { if (_lastIndex != _index) then {
_isOverLimit = false; AllowedVehiclesList set [_index, AllowedVehiclesList select _lastIndex];
_isAbort = true;
}; };
AllowedVehiclesList resize _lastIndex;
}; };
if (_isAbort) then { if (count AllowedVehiclesList == 0) then {
diag_log("DEBUG: unable to find suitable vehicle to spawn"); diag_log("DEBUG: unable to find suitable vehicle to spawn");
} else { } else {