breeze 0 Posted July 25, 2016 Hello Guys, I am back to playing Arma after a very long reprieve and as I age I forget stuff. Not to mention things change a lot. Anyways I usually try to learn by UnPboing other missions and grabbing scripts and trying to make them work together as well as some reading. So I play my 1st mission the other night which I really enjoyed, and I come across these scripts. Get Loadout I have some questions and I am hoping you can shed some light on these so I can use them, AUTHOR: aeroson NAME: get_loadout.sqf VERSION: 3.4 DOWNLOAD & PARTICIPATE: https://github.com/aeroson/a3-loadout http://forums.bistudio.com/showthread.php?148577-GET-SET-Loadout-(saves-and-loads-pretty-much-everything) DESCRIPTION: I guarantee backwards compatibility. These scripts allows you set/get (load/save)all of the unit's gear, including: uniform, vest, backpack, contents of it, all quiped items, all three weapons with their attachments, currently loaded magazines and number of ammo in magazines. All this while preserving order of items. Useful for saving/loading loadouts. Ideal for revive scripts where you have to set exactly the same loadout to newly created unit. Uses workaround with placeholders to add vest/backpack items, so items stay where you put them. PARAMETER(S): 0 : target unit 1 : (optional) array of options, default [] : "ammo" will save ammo count of partially emptied magazines "repetitive" intended for repetitive use, will not use selectWeapon, means no visible effect on solder, but will not save magazines of assigned items such as laser designator batteries The Parameters do not list any types of weapons so this is basically just turning things on and off, and the Load out is defined by the mission maker at the time of making the mission which can now be done in the eden editor arsenal?? RETURNS: Array : array of strings/arrays containing target unit's loadout, to be used by fnc_set_loadout.sqf addAction support: Saves player's loadout into global var loadout */ private ["_target","_options","_saveMagsAmmo","_isRepetitive","_isOnFoot","_currentWeapon","_currentMode","_isFlashlightOn","_isIRLaserOn","_magazinesAmmo","_loadedMagazines","_saveWeaponMagazines","_getMagsAmmo","_backPackItems","_assignedItems","_data"]; _options = []; // addAction support if(count _this < 4) then { #define PARAM_START private ["_PARAM_INDEX"]; _PARAM_INDEX=0; #define PARAM_REQ(A) if (count _this <= _PARAM_INDEX) exitWith { systemChat format["required param '%1' not supplied in file:'%2' at line:%3", #A ,__FILE__,__LINE__]; }; A = _this select _PARAM_INDEX; _PARAM_INDEX=_PARAM_INDEX+1; #define PARAM(A,B) A = B; if (count _this > _PARAM_INDEX) then { A = _this select _PARAM_INDEX; }; _PARAM_INDEX=_PARAM_INDEX+1; PARAM_START PARAM_REQ(_target) PARAM(_options,[]) } else { _target = player; }; _saveMagsAmmo = "ammo" in _options; _isRepetitive = "repetitive" in _options; _isOnFoot = vehicle _target == _target; _currentWeapon = ""; _currentMode = ""; _isFlashlightOn = false; _isIRLaserOn = false; _magazinesAmmo = magazinesAmmoFull _target; // save weapon mode and muzzle if(_isOnFoot) then { _currentWeapon = currentMuzzle _target; _currentMode = currentWeaponMode _target; _isFlashlightOn = _target isFlashlightOn _currentWeapon; _isIRLaserOn = _target isIRLaserOn _currentWeapon; } else { _currentWeapon = currentWeapon _target; }; _loadedMagazines=[]; // universal weapon saving _saveWeaponMagazines = { private ["_weapon","_magazines","_muzzles","_saveMagazine"]; _weapon = _this select 0; _magazines = []; _saveMagazine = { // find, save and eat mag for _weapon private ["_weapon","_magazine","_ammo"]; _weapon = _this select 0; _magazine = ""; _ammo = 0; { if((_x select 4)==_weapon) then { _magazine = _x select 0; _ammo = _x select 1; _x = -1; }; } forEach _magazinesAmmo; _magazinesAmmo = _magazinesAmmo - [-1]; if(_magazine!="") then { if(_saveMagsAmmo) then { _magazines set [count _magazines, [_magazine, _ammo]]; } else { _magazines set [count _magazines, _magazine]; }; }; }; if(_weapon != "") then { [_weapon] call _saveMagazine; _muzzles = configFile>>"CfgWeapons">>_weapon>>"muzzles"; if(isArray(_muzzles)) then { { // add one mag for each muzzle if (_x != "this") then { [_x] call _saveMagazine; }; } forEach getArray(_muzzles); }; }; _loadedMagazines set [count _loadedMagazines, _magazines]; }; // save loaded mags for each weapon separetely, since some weapons can use same magazines [primaryWeapon _target] call _saveWeaponMagazines; [handgunWeapon _target] call _saveWeaponMagazines; [secondaryWeapon _target] call _saveWeaponMagazines; _getMagsAmmo = { // default function with _saveMagsAmmo == false _this select 0; }; if(_saveMagsAmmo) then { // check if input array contains magazine, if it does, find it add ammo count _getMagsAmmo = { private ["_items","_location","_item","_itemIndex"]; _items = _this select 0; _location = _this select 1; { _item = _x; _itemIndex = _forEachIndex; { if((_x select 4)==_location && (_x select 0)==_item) then { _items set[_itemIndex, [_item, _x select 1]]; _x = -1; }; } forEach _magazinesAmmo; _magazinesAmmo = _magazinesAmmo - [-1]; } forEach _items; _items; }; }; // get backpack items _cargo = getbackpackcargo (unitbackpack _target); _backpacks = []; { for "_i" from 1 to ((_cargo select 1) select _foreachindex) do { _backpacks set [count _backpacks, _x]; }; } foreach (_cargo select 0); _backPackItems = (backpackitems _target) + _backpacks; // get assigned items, headgear and goggles is not part of assignedItems _assignedItems = assignedItems _target; _headgear = headgear _target; _goggles = goggles _target; if((_headgear != "") && !(_headgear in _assignedItems)) then { _assignedItems set [count _assignedItems, _headgear]; }; if((_goggles != "") && !(_goggles in _assignedItems)) then { _assignedItems set [count _assignedItems, _goggles]; }; /* // use this once magazinesAmmoFull is fixed and shows magazines of assignedItems // get magazines of everything else except weapons, most likely assigned items // only ["Uniform","Vest","Backpack"] locations remain, weapon locations have already been eaten _magazines = []; { if(_x select 2) then { if(_saveMagsAmmo) then { _magazines set[count _magazines, [_x select 0, _x select 1]]; } else { _magazines set[count _magazines, _x select 0]; }; _x = -1; }; } forEach _magazinesAmmo; _magazinesAmmo = _magazinesAmmo - [-1]; _loadedMagazines set [3, _magazines]; */ // old method using selectWeapon, cycles and tries to selectWeapon all assigned items if(!_isRepetitive) then { private ["_weaponHasChanged"]; _weaponHasChanged = false; // get magazines of all assigned items _magazines = []; { _target selectWeapon _x; if(currentWeapon _target==_x) then { _weaponHasChanged = true; _magazine = currentMagazine _target; if(_magazine != "") then { if(_saveMagsAmmo) then { _magazines set[count _magazines, [_magazine, _target ammo _x]]; } else { _magazines set[count _magazines, _magazine]; }; }; }; } forEach _assignedItems; _loadedMagazines set [3, _magazines]; // select back originaly selected weapon and mode, only if weapon has changed if(_weaponHasChanged) then { if(_isOnFoot) then { if(_currentWeapon != "" && _currentMode != "") then { _muzzles = 0; while{ (_currentWeapon != currentMuzzle _target || _currentMode != currentWeaponMode _target ) && _muzzles < 200 } do { _target action ["SWITCHWEAPON", _target, _target, _muzzles]; _muzzles = _muzzles + 1; }; if(_isFlashlightOn) then { _target action ["GunLightOn"]; } else { _target action ["GunLightOff"]; }; if(_isIRLaserOn) then { _target action ["IRLaserOn"]; } else { _target action ["IRLaserOff"]; }; }; } else { _currentMode = ""; }; if(_currentMode == "") then { if(_currentWeapon=="") then { _target action ["SWITCHWEAPON", _target, _target, 0]; } else { _target selectWeapon _currentWeapon; }; }; }; }; _data = [ _assignedItems, //0 [] primaryWeapon _target, //1 "" primaryWeaponItems _target, //2 [] handgunWeapon _target, //3 "" handgunItems _target, //4 [] secondaryWeapon _target, //5 "" secondaryWeaponItems _target, //6 [] uniform _target, //7 "" [uniformItems _target, "Uniform"] call _getMagsAmmo, //8 ["magazine without ammo count",["magazine with ammo count",30], ....] vest _target, //9 "" [vestItems _target, "Vest"] call _getMagsAmmo, //10 backpack _target, //11 "" [_backPackItems, "Backpack"] call _getMagsAmmo, //12 _loadedMagazines, //13 (optional) [[primary mags],[handgun mags],[secondary mags],[other mags]] _currentWeapon, //14 (optional) "" _currentMode //15 (optional) "" ]; // addAction support if(count _this < 4) then { _data; } else { loadout = _data; //playSound3D ["A3\Sounds_F\sfx\ZoomOut.wav", _target]; }; My other questions are How can I Turn Items on and off as in this script the helmet and glasses do not work,, Because they are not an assigned item, So can I turn any item on and off in this?? Do I need to?? Or can I just arm my guy in the arsenal add these scripts and they should work well?? Thanks in advance Breeze Share this post Link to post Share on other sites
jwllorens 43 Posted July 25, 2016 https://community.bistudio.com/wiki/getUnitLoadout https://community.bistudio.com/wiki/setUnitLoadout Don't worry, I made a complicated script to get and set unit loadouts before I realized those two commands existed too. Use those commands. They do everything you want, including adding half empty magazines and stuff with the right bullet count. So these two commands are perfect for something like a revive script where the unit is actually completely killed and not put into an incapacitated state. If you are trying to load a hardcoded inventory to put on an AI, then these commands may not be the best idea. The array format they use isn't final, so a hardcoding an array of items and calling setUnitLoadout on it might not work in the future if BIS changes the way the commands work. If you want to look at how I did the script version before realizing we had those commands, take a look at this: comment "------------------------------------------------------------------------------------------------------------- Function to spawn an infantry unit. Can spawn WEST or EAST unit. Uses loadout templates to equip the soldier with a custom loadout. Also sets the AI skills for the unit. Arguments: group, class, position, kitUpgrade, skillUpgrade group = group to add the unit to. class = string name for class loadout definition file. position = position array to spawn the unit at. kitUpgrade = array defining whether to upgrade weapons and night vision. [bool, bool] skillUpgrade = a number to increase all base skills by Return: unit unit = the unit that was created. ---------------------------------------------------------------------------------------------------------------------"; params [ ["_grp", grpNull, [grpNull], 1], ["_cls", "EMPTY", [""], 1], ["_pos", [0,0,0], [[]], 3], ["_kitUp", [false,false], [[]], 2], ["_sklUp", 0, [0], 1] ]; comment "------------------------------------------------------------------------------------------------------------- Retrieve an array defined in AILoadouts\SoldierClassName.sqf. This array contains the base soldier classname, an array of custom equipment, and an array of individual skills. ---------------------------------------------------------------------------------------------------------------------"; _info = [(side _grp),(_kitUp select 0),(_kitUp select 1)] call (compile loadFile (format ["AILoadouts\%1.sqf", (toLower _cls)])); _ldt = _info select 1; comment "------------------------------------------------------------------------------------------------------------- Create the unit, turn off damage. Sleep ensures that remainder of script runs after default engine randomization has completed to prevent conflicts or overriding intended behavior (mostly ensures that headgear is spawned properly). ---------------------------------------------------------------------------------------------------------------------"; _unit = _grp createUnit [(_info select 0),_pos, [], 0, "CAN_COLLIDE"]; _unit setVariable ["BIS_enableRandomization", false]; sleep 0.05; comment "------------------------------------------------------------------------------------------------------------- Remove all default equipment and items from the unit. ---------------------------------------------------------------------------------------------------------------------"; removeAllWeapons _unit; removeAllItems _unit; removeAllAssignedItems _unit; removeUniform _unit; removeVest _unit; removeBackpack _unit; removeHeadgear _unit; removeGoggles _unit; comment "------------------------------------------------------------------------------------------------------------- Add equipment and items from _classInfo. ---------------------------------------------------------------------------------------------------------------------"; if ((_ldt select 0)!= "EMPTY") then {_unit addHeadgear (_ldt select 0);}; if ((_ldt select 1)!= "EMPTY") then {_unit addGoggles (_ldt select 1);}; if ((_ldt select 2)!= "EMPTY") then {_unit forceAddUniform (_ldt select 2);}; {for "_i" from 1 to (_x select 1) do { if ((_x select 0)!= "EMPTY") then { _unit addItemToUniform (_x select 0);}; }; true } count (_ldt select 3); if ((_ldt select 4)!= "EMPTY") then {_unit addVest (_ldt select 4);}; {for "_i" from 1 to (_x select 1) do { if ((_x select 0)!= "EMPTY") then { _unit addItemToVest (_x select 0);}; }; true } count (_ldt select 5); if ((_ldt select 6)!= "EMPTY") then {_unit addBackpack (_ldt select 6);}; {for "_i" from 1 to (_x select 1) do { if ((_x select 0)!= "EMPTY") then { _unit addItemToBackpack (_x select 0);}; }; true } count (_ldt select 7); {if (_x != "EMPTY") then { _unit addWeapon _x;}; true } count ([_ldt select 8] + (_ldt select 10)); {if (_x != "EMPTY") then { _unit addPrimaryWeaponItem _x;}; true } count (_ldt select 9); {if (_x != "EMPTY") then { _unit linkItem _x;}; true } count (_ldt select 11); comment "------------------------------------------------------------------------------------------------------------- Set individual skills of unit. Skills are retrieved from _info, then incremented by _sklUp. ---------------------------------------------------------------------------------------------------------------------"; {_unit setSkill [_x, (((_info select 2) select _forEachIndex) +_sklUp)];} forEach ["aimingAccuracy", "aimingShake", "aimingSpeed", "commanding", "courage", "reloadSpeed", "spotDistance", "spotTime"]; comment "------------------------------------------------------------------------------------------------------------- Add a killed event handler to unit for cleanup, turn damage back on now that setup is complete, and return the unit object from the function. ---------------------------------------------------------------------------------------------------------------------"; _unit addEventHandler ["killed", {_this spawn JFNC_Cleanup;}]; _unit allowDamage true; _unit Then I have a folder called AILoadouts, and inside I have some sqf files named "rifleman.sqf" "grenadier.sqf" ect. params [["_side", west, [west], 1], ["_wUp", false, [true], 1], ["_nv", false, [true], 1]]; _info = switch (_side) do { case (west): { _baseSoldier = "B_T_Soldier_F"; _helmet = selectRandom ["H_HelmetB_light"]; _facewear = selectRandom ["EMPTY","G_Lowprofile","G_Aviator","G_Sport_Blackred"]; _uniform = selectRandom ["U_B_T_Soldier_F"]; _uniformItems = ([[["EMPTY",0]],[["EMPTY",0]]] select _wUp) + [["FirstAidKit", 1], ["16Rnd_9x21_Mag",3]]; _vest = selectRandom ["V_PlateCarrier1_rgr"]; _vestItems = ([[["30Rnd_556x45_Stanag_red",8]],[["30Rnd_65x39_caseless_mag",8]]] select _wUp) + [["HandGrenade", 2], ["SmokeShell", 2]]; _backpack = selectRandom ["EMPTY"]; _backpackItems = ([[["EMPTY",0]],[["EMPTY",0]]] select _wUp) + [["EMPTY",0]]; _rifle = ["arifle_SPAR_01_khk_F","arifle_MX_khk_F"] select _wUp; _attachments = ([["acc_flashlight"],["acc_pointer_IR"]] select _nv) + ["optic_ERCO_khk_F"]; _secondaryWeapons = ["hgun_P07_khk_F"]; _gear = [["ItemMap", "ItemCompass", "ItemWatch", "ItemRadio"], ["ItemMap", "ItemCompass", "ItemWatch", "ItemRadio", "NVGoggles_INDEP"]] select _nv; [_baseSoldier,[_helmet, _facewear, _uniform, _uniformItems, _vest, _vestItems, _backpack, _backpackItems, _rifle, _attachments, _secondaryWeapons, _gear]]; }; case (east): { _baseSoldier = "O_T_Soldier_F"; _helmet = selectRandom ["H_HelmetSpecO_ghex_F"]; _facewear = selectRandom ["G_Balaclava_oli"]; _uniform = selectRandom ["U_O_T_Soldier_F"]; _uniformItems = ([[["EMPTY",0]],[["EMPTY",0]]] select _wUp) + [["FirstAidKit", 1], ["16Rnd_9x21_Mag",3]]; _vest = selectRandom ["V_HarnessO_ghex_F"]; _vestItems = ([[["30Rnd_580x42_Mag_F",8]],[["30Rnd_65x39_caseless_green",8]]] select _wUp) + [["HandGrenade", 2], ["SmokeShell", 2]]; _backpack = selectRandom ["EMPTY"]; _backpackItems = ([[["EMPTY",0]],[["EMPTY",0]]] select _wUp) + [["EMPTY",0]]; _rifle = ["arifle_CTAR_blk_F","arifle_Katiba_F"] select _wUp; _attachments = ([["acc_flashlight"],["acc_pointer_IR"]] select _nv) + ["optic_Arco_blk_F"]; _secondaryWeapons = ["hgun_Rook40_F"]; _gear = [["ItemMap", "ItemCompass", "ItemWatch", "ItemRadio"], ["ItemMap", "ItemCompass", "ItemWatch", "ItemRadio", "O_NVGoggles_ghex_F"]] select _nv; [_baseSoldier,[_helmet, _facewear, _uniform, _uniformItems, _vest, _vestItems, _backpack, _backpackItems, _rifle, _attachments, _secondaryWeapons, _gear]]; }; }; comment "------------------------------------------------------------------------------------------------------------- array format: [aimingAccuracy, aimingShake, aimingSpeed, commanding, courage, reloadSpeed, spotDistance, spotTime] ---------------------------------------------------------------------------------------------------------------------"; _skill = [0.55,0.55,0.55,0.5,0.5,0.5,0.5,0.5]; _info pushBack _skill; _info Share this post Link to post Share on other sites