rejenorst 18 Posted April 9, 2016 This is just a quick script I am currently using to either spawn units with specific equipment changes or to change the equipment of an existing unit. There are better scripts out there that are likely much more efficient but thought I'd upload it for anyone wanting it. The script still needs testing. If you have any problems with it, please post the inputs and I'll try and replicate then fix he problem. UPDATE 19.08.2016: Have updated script so that if primary weapon is replaced then unit will select primary weapon and if units need to reload after script launch they will reload all their weapons. Input arguements: 0: group (if planning on spawning units otherwise set as grpNull or anything as it is only used in spawning) 1: existing unit or spawn array eg: ["B_Soldier_SL_F",_startPos,[],_placementRadius,"FORM"] 2: Items array eg: [["HEAD","H_Watchcap_blk"]]. The first string is the reference string so my script knows which code to execute and the second is the classname. In some cases if class name is left "" it will just remove the current item type. 3: Optional Boolean either true or false (True by default). Determines whether inventory is automatically transferred from old to newly spawned vest/uniform/backpack. To change the appearance of a unit only; you can do this: (adds a cap to head, a silencer to primary weapon and a vest the items of which will be automatically transferred to the new vest. Can be turned off): [grpNull,player,[["HEAD","H_Watchcap_blk"],["ATTP","muzzle_snds_H"],["VEST","V_PlateCarrier1_rgr"]]] call rej_fnc_spawnUnit; You can either use it as a function by placing this in the init (Make sure you change the sqf name appropriately): ///////////////////////// //-- Spawn functions --// ///////////////////////// rej_fnc_spawnUnit = compile preProcessFileLineNumbers "rej_spawnunit.sqf"; Spawning a group with SF helmet, specific vests and no goggles with a placement radius of 25 meters and Sergeant and two Corporal ranks: //////////////////////// //-- Create group 1 --// //////////////////////// _group = createGroup WEST; _groupType = [ [_group,["B_Soldier_SL_F",_startPos,[],25,"FORM"],[["ATTP","muzzle_snds_H"],["HEAD","H_HelmetSpecB"],["VEST","V_PlateCarrier1_rgr"],["GOOGLES",""],["RANK","SERGEANT"]]], [_group,["B_Soldier_TL_F",_startPos,[],25,"FORM"],[["ATTP","muzzle_snds_H"],["HEAD","H_HelmetSpecB"],["VEST","V_PlateCarrier1_rgr"],["GOOGLES",""],["RANK","CORPORAL"]]], [_group,["B_soldier_LAT_F",_startPos,[],25,"FORM"],[["ATTP","muzzle_snds_H"],["HEAD","H_HelmetSpecB"],["VEST","V_PlateCarrier1_rgr"],["GOOGLES",""],["RANK","CORPORAL"]]], [_group,["B_soldier_M_F",_startPos,[],25,"FORM"],[["ATTP","muzzle_snds_H"],["HEAD","H_HelmetSpecB"],["VEST","V_PlateCarrier1_rgr"],["GOOGLES",""]]], [_group,["B_medic_F",_startPos,[],25,"FORM"],[["ATTP","muzzle_snds_H"],["HEAD","H_HelmetSpecB"],["VEST","V_PlateCarrier1_rgr"],["GOOGLES",""]]], [_group,["B_soldier_AR_F",_startPos,[],25,"FORM"],[["ATTP","muzzle_snds_H"],["HEAD","H_HelmetSpecB"],["VEST","V_PlateCarrier1_rgr"],["GOOGLES",""]]], [_group,["B_Soldier_A_F",_startPos,[],25,"FORM"],[["ATTP","muzzle_snds_H"],["HEAD","H_HelmetSpecB"],["VEST","V_PlateCarrier1_rgr"],["GOOGLES",""]]] ]; {_x call rej_fnc_spawnUnit} forEach _groupType; String codes: ATTH = HandGun attachementATTP = Primary weapon attachementATTS = Secondary weapon attachmentBACK = BackpackFACE = Setface. String should be the face you want for unit.GOOGLES = GooglesHEAD = Helmet/headgearITEM = items (Adds item eg:. ["ITEM",<insert classname>,2]. See MAG for similar input description.)MAG = Magazine eg: ["MAG","20Rnd_762x51_Mag",2] 3rd input is the number of magazinesNVG = Night vission gogglesNAME = setName command. Eg: ["NAME",["Ben Kerry","Ben","Kerry"]]NAMESOUND = setNameSound command. Eg: ["NAMESOUND","dixon"]PITCH = Voice pitch. setPitch command. EG: ["PITCH",1] RANK = setRank command. EG: ["RANK","CORPORAL"] SPEAKER = setspeaker command. EG ["SPEAKER","NoVoice"];UNI = Set UniformVEST = set vestWEAPH = set Handgun weapon (Magazines of previous weapon will be removed)WEAPP = Set primary weapon (Magazines of previous weapon will be removed)WEAPS = Set secondary weapon (Magazines of previous weapon will be removed) NOTE: For items and magazines the script will check if it can add the item to the unit before placing it in inventory. EDIT: 10/04/2016 Fixed googles not being removed properly when adding an array specifying GOOGLES as "". The script itself: /////////////////////////////////////// //-- Rejenorst's unit spawn script --// /////////////////////////////////////// _group = _this select 0; _unitSpawnInfo = _this select 1; _unitEquipment = _this select 2; _reAddItems = true; if (count _this > 3) then { _reAddItems = _this select 3; }; ////////////////////////////////////////////////////////////////////////// //-- Define variables and check if unit exists or needs to be spawned --// ////////////////////////////////////////////////////////////////////////// private["_unit"]; if (typename _unitSpawnInfo == "OBJECT") then { _unit = _unitSpawnInfo; } else { _unitType = _unitSpawnInfo select 0; _unitSpawnPos = _unitSpawnInfo select 1; _unitMarkers = _unitSpawnInfo select 2; _unitPlacementRadius = _unitSpawnInfo select 3; _unitSpecial = _unitSpawnInfo select 4; _unit = _group createUnit [_unitType,_unitSpawnPos,_unitMarkers,_unitPlacementRadius,_unitSpecial]; //["SoldierWB", position player, [], 100, "FORM"] }; ////////////////////////////////////////////////// //-- Check if unit has been spawned or exists --// ////////////////////////////////////////////////// if (isNil "_unit") then { _unit = objNull; }; /////////////////////// //-- Add equipment --// /////////////////////// if (!isNull _unit) then { private["_magCount","_magArray"]; _itemTransferArray = []; _magazinesAmmoFull = magazinesAmmoFull _unit; //////////////////////// //-- Add unit items --// //////////////////////// _arrayCount = (count _unitEquipment) - 1; if (_arrayCount >= 0) then { for "_i" from 0 to _arrayCount do { _itemArray = _unitEquipment select _i; _itemString = toUpper (_itemArray select 0); _item = _itemArray select 1; _checkItem = [_unit,_itemString,_item] call { _unit = _this select 0; _itemString = _this select 1; _item = _this select 2; if (_itemString == "ATTH") exitWith {_unit addHandgunItem _item}; if (_itemString == "ATTP") exitWith {_unit addPrimaryWeaponItem _item}; if (_itemString == "ATTS") exitWith {_unit addSecondaryWeaponItem _item}; if (_itemString == "BACK") exitWith { _itemsToTransfer = backpackItems _unit; removeBackPack _unit; if (_item != "") then { _unit addBackPack _item; }; {if (_unit canAddItemToBackpack _x) then {_unit addItemToBackpack _x};} forEach _itemsToTransfer; }; if (_itemString == "FACE") exitWith {_unit setFace _item;}; if (_itemString == "GOOGLES") exitWith { removeGoggles _unit; if (_item != "") then { _unit addGoggles _item; }; }; if (_itemString == "HEAD") exitWith { removeHeadgear _unit; if (_item != "") then { _unit addHeadgear _item; }; }; if (_itemString == "ITEM") exitWith { _itemCount = 0; if (count _itemArray > 2) then { _itemCount = (_itemArray select 2) - 1; }; if (_itemCount >= 0) then { for "_a" from 0 to _itemCount do { if (_unit canAdd _item) then { _unit addItem _item; }; }; _a = nil; }; }; if (_itemString == "MAG") exitWith { _magazineCount = 0; if (count _itemArray > 2) then { _magazineCount = (_itemArray select 2) - 1; }; if (_magazineCount >= 0) then { for "_a" from 0 to _magazineCount do { if (_unit canAdd _item) then { _unit addMagazine _item; }; }; _a = nil; }; }; if (_itemString == "NVG") exitWith { _assignedItems = assignedItems _unit; {if (_x find "NVGoggles" > (-1)) then {_unit unassignItem _x;_unit removeItem _x};} forEach _assignedItems; if (_item != "") then { _unit addItem _item; }; }; if (_itemString == "NAME") exitWith {_unit setName _item}; if (_itemString == "NAMESOUND") exitWith {_unit setNameSound _item}; if (_itemString == "PITCH") exitWith {_unit setPitch _item}; if (_itemString == "RANK") exitWith {_unit setRank _item}; if (_itemString == "SPEAKER") exitWith {_unit setSpeaker _item}; if (_itemString == "UNI") exitWith { _itemsToTransfer = uniformItems _unit; removeUniform _unit; if (_item != "") then { _unit forceAddUniform _item; }; if (_reAddItems) then { {if (_unit canAddItemToUniform _x) then {_unit addItemToUniform _x};} forEach _itemsToTransfer; }; }; if (_itemString == "VEST") exitWith { _itemsToTransfer = vestItems _unit; removeVest _unit; if (_item != "") then { _unit addVest _item; }; if (_reAddItems) then { {if (_unit canAddItemToVest _x) then {_unit addItemToVest _x};} forEach _itemsToTransfer; }; }; if (_itemString == "WEAPH") exitWith { if (handgunWeapon _unit != "") then { _magArray = getArray (configfile >> "CfgWeapons" >> (handgunWeapon _unit) >> "magazines"); _magCount = (count _magArray) - 1; _unit removeWeapon (handgunWeapon _unit); }; if (_item != "") then { _unit addWeapon _item; }; if (!isNil "_magCount") then { if (_magCount >= 0) then { for "_a" from 0 to _magCount do { _mag = _magArray select _a; _unit removeMagazines _mag; }; _a = nil; _magCount = nil; _magArray = nil; }; }; }; if (_itemString == "WEAPP") exitWith { if (primaryWeapon _unit != "") then { _magArray = getArray (configfile >> "CfgWeapons" >> (primaryWeapon _unit) >> "magazines"); _magCount = (count _magArray) - 1; _unit removeWeapon (primaryWeapon _unit); }; if (_item != "") then { _unit addWeapon _item; _unit selectWeapon _item; }; if (!isNil "_magCount") then { if (_magCount >= 0) then { for "_a" from 0 to _magCount do { _mag = _magArray select _a; _unit removeMagazines _mag; }; _a = nil; _magCount = nil; _magArray = nil; }; }; }; if (_itemString == "WEAPS") exitWith { if (secondaryWeapon _unit != "") then { _magArray = getArray (configfile >> "CfgWeapons" >> (secondaryWeapon _unit) >> "magazines"); _magCount = (count _magArray) - 1; _unit removeWeapon (secondaryWeapon _unit); }; if (_item != "") then { _unit addWeapon _item; }; if (!isNil "_magCount") then { if (_magCount >= 0) then { for "_a" from 0 to _magCount do { _mag = _magArray select _a; _unit removeMagazines _mag; }; _a = nil; _magCount = nil; _magArray = nil; }; }; }; }; }; }; _i = nil; if (needReload _unit == 1) then {reload _unit}; }; 1 Share this post Link to post Share on other sites
rejenorst 18 Posted August 19, 2016 UPDATE 19.08.2016: Have updated script so that if primary weapon is replaced then unit will select primary weapon and if units need to reload after script launch they will reload all their weapons. Also tested with a moveincargo comand shortly after and still seems to reload weapon though you may hear a reload noise. An example of adding a weapon, optic for primary gun and magazines to player (group is left grpNull since your not spawning a unit): [grpNull,player,[["WEAPP","arifle_SPAR_01_blk_F"],["ATTP","optic_Aco"],["MAG","30Rnd_556x45_Stanag",6]]] call rej_fnc_spawnUnit; Share this post Link to post Share on other sites
dr death jm 117 Posted August 19, 2016 Nice... Thanks for sharing ... Ill try this out . Share this post Link to post Share on other sites
rejenorst 18 Posted August 22, 2016 22/08/2016 Interchanged the command used for adding uniforms. Have replaced it with forceAddUniform so that you can add enemy uniforms as well. EDIT: Also fixed handgun not removing properly if using ["WEAPH",""] or adding new handgun. Share this post Link to post Share on other sites