chewihomster 0 Posted April 19 I have been using a script provided by Shaanig03 that allows a player to spawn squadmates in the vehicle that they are in, it fills commander driver and gunner roles with AI squadmembers, it does not fill passenger seats, the problem i an having is some of the vehicles im using have 8 gunner seats to the script is spawning a full squad of ten. I am trying to figure out a way to limit the amount of sqaudmembers to 3 or 4 to help save some performance. I have this so far, but it does not seem to be working. I am very new to Scripting _maxSquadSize = 3; checkSquadSize = { private["_playerGroup"]; _playerGroup = group player; _numUnits = count units _playerGroup; while {_numUnits > _maxSquadSize} do { _unitToRemove = units _playerGroup select (_numUnits - 1); _unitToRemove leaveVehicle; deleteVehicle _unitToRemove; _numUnits = count units _playerGroup; }; }; Share this post Link to post Share on other sites
Shaanig03 18 Posted April 20 yo, we meet again heheheheh, and.. are you calling that function using "call"?, it's not a good idea to use while loop in a "call" function, while you can use it but I think you have to provide a way to end the loop or your game might freeze, use "for" loop instead https://community.bistudio.com/wiki/for and I also modified the code, also you should look into these functions: "exitWith", "_forEachIndex" in forEach loop, to achieve putting a limit on how much units are spawning, also commented out the changes spawnAssistantUnits = { params ["_veh","_unitGrp","_unitClass",["_maxGunnerCount", -1]]; // if provided object is not a vehicle, exit if (_veh isKindOf "Man") exitWith {}; // get commander seat, gunner seats, driver seat private _commander = commander _veh; private _turrets = allTurrets _veh; private _driver = driver _veh; // spawn commander if there is no unit in commander seat if (isNull _commander) then { private _unit = _unitGrp createUnit ["B_Soldier_F", getPos _veh, [], 0, "FORM"]; _unit assignAsCommander _veh; [_unit] orderGetIn true; _unit moveInCommander _veh; // if vehicle doesn't have a commander seat, delete unit if (vehicle _unit == _unit) then { deleteVehicle _unit; }; }; // spawn driver if there is no unit in driver seat if (isNull _driver) then { private _unit = _unitGrp createUnit ["B_Soldier_F", getPos _veh, [], 0, "FORM"]; _unit assignAsDriver _veh; [_unit] orderGetIn true; _unit moveInDriver _veh; // if vehicle doesn't have a driver seat, delete unit if (vehicle _unit == _unit) then { deleteVehicle _unit; }; }; // get current full crew of the vehicle private _fullCrew = fullCrew _veh; // get occupied turret paths private _occupied_turret_paths = []; { private _x_seatType =_x select 1; private _x_turretPath =_x select 3; _occupied_turret_paths pushBack str(_x_turretPath); } forEach _fullCrew; // spawn units for gunners empty { private _x_str_turret = str(_x); // _forEachIndex is the looping index of forEach, since it starts from zero we add +1 // https://community.bistudio.com/wiki/forEach _looping_turret_count = _forEachIndex + 1; // note that were looping through each turret and spawning a unit for it // so we can make the use of _forEachIndex to check the looping turret's index and if turret count reaches max gunner count // we make exit the forEach loop by calling exitWith {} https://community.bistudio.com/wiki/exitWith if (_maxGunnerCount != -1 && _looping_turret_count > _maxGunnerCount) exitWith {}; // if max gunner count is assigned && max count reaches, exit loop // if turret gunner doesn't have a unit assigned if (!(_x_str_turret in _occupied_turret_paths)) then { // then spawn unit private _unit = _unitGrp createUnit ["B_Soldier_F", getPos _veh, [], 0, "FORM"]; _unit assignAsTurret [_veh, _x]; [_unit] orderGetIn true; _unit moveInTurret [_veh, _x]; }; } forEach _turrets; }; Share this post Link to post Share on other sites