rejenorst 18 Posted November 19, 2016 This script is intended to be used if you want a group to board in cargo positions only in a convoy that has another group assigned as drivers. It will assign each unit where there is room and will calculate how many units have already been assigned to a particular vehicle vs the cargo spaces available (for own group only. If another group is assigned to cargo and in the process of boarding this will not work correctly). If you're looking for units to command vehicles in a convoy your best off using addvehicle command. This is just for assigning units to cargo of vehicles driven by other groups. There are likely way better more efficient scripts out there and this one still needs more testing. INPUT: _hasBoarded = [_group,_assignedVehicles] call rej_fnc_assignCargo; _group = the group you want to assign to cargo. _assignedVehicles = An array of vehicles you want group to board. Return Value Example: 0: Boolean. True if all alive units have boarded. Will return false if units are still in the process of boarding. 1: Boolean: True if there wasn't enough cargo spaces for all units. Meaning boarding has failed and should not be continued,You may need to unassignVehicle any units that have boarded. 2: Number of alive units counted 3: Number of boarded units counted. 2 and 3 should be equal if 0 == true. 0 should be false if 1 is true. Script: //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //-- This Script Will Check For Available Cargo Positions In One Or More Vehicles Within An Array And Assign Units Not Currently In The Vehicle To Get In Cargo --// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// _targetGroup = _this select 0; _vehicles = _this select 1; _vehicleCount = (count _vehicles) - 1; copytoclipboard str(_targetGroup); _units = units _targetGroup; _aliveUnits = 0; _boardedUnits = 0; _returnVar = [false,false,_aliveUnits,_boardedUnits]; _unitCount = (count _units) - 1; if (_unitCount >= 0) then { for [{_a = 0},{(_a <= _unitCount)},{_a = _a + 1}] do { _unit = _units select _a; if (lifeState _unit find "DEAD" < 0) then { _aliveUnits = _aliveUnits + 1; if ((not (vehicle _unit in _vehicles)) && (currentCommand _unit != "GET IN")) then { if (_vehicleCount >= 0) then { _vehiclePositionFound = false; for [{_b = 0},{(_b <= _vehicleCount) && (!_vehiclePositionFound)},{_b = _b + 1}] do { _vehicle = _vehicles select _b; _emptyPositions = _vehicle emptyPositions "CARGO"; _alreadyAssignedCargoPositions = 0; {if ((_unit != _x) && (assignedVehicle _x == _vehicle) && (vehicle _x != _vehicle)) then {_alreadyAssignedCargoPositions = _alreadyAssignedCargoPositions + 1};} forEach _units; if (_emptyPositions - _alreadyAssignedCargoPositions > 0) then { _unit assignAsCargo _vehicle; [_unit] orderGetIn true; _vehiclePositionFound = true; }; }; _b = nil; if (!_vehiclePositionFound) then { _returnVar set [1,true]; }; }; } else { if (vehicle _unit in _vehicles) then { _boardedUnits = _boardedUnits + 1; }; }; }; }; _a = nil; if (_boardedUnits == _aliveUnits) then { _returnVar set [0,true]; _returnVar set [2,_aliveUnits]; _returnVar set [3,_boardedUnits]; }; }; _returnVar Put this in init.sqf: rej_fnc_assignCargo = compile preProcessFileLineNumbers "rej_commandscript\functions\rej_fnc_assigncargo.sqf"; To Check if group has boarded (can be used in a loop to check progress of boarding): _hasBoarded = [_group,_assignedVehicles] call rej_fnc_assignCargo; if ((_hasBoarded select 0) && (not (_hasBoarded select 1))) then { //-- Boarding completed --// } else { if (_hasBoarded select 1) then { //-- Boarding has failed --// }; }; 1 Share this post Link to post Share on other sites
rejenorst 18 Posted November 20, 2016 Fixed a variable inconsistency in script that would result in script not working. Apologies for that. Share this post Link to post Share on other sites
rejenorst 18 Posted November 27, 2016 Fixed a flaw in script that would result in only one vehicle being checked rather than all the vehicles in array. EDIT: *FIXED 17/12/2016 - Problem with unit excluding itself from the assigned cargo list. This could result in unit not finding an available position. This should be fixed now and seems to work better in my test. Share this post Link to post Share on other sites