RyanTurner 23 Posted May 19, 2020 Good afternoon to everyone, I've been here for a while to figure how to I get the information (ammo, grenades, etc..) of the current vest and transfer/paste into the new vest. { if ((side _x) == West) then // For every units in Blufor { if ((vest _x == "V_PlateCarrierGL_rgr") or (vest _x == "V_PlateCarrierSpec_rgr")) then // If they have X or Y Vest { removeVest _x; // Remove the Current Vest _x addVest "V_PlateCarrier1_rgr"; // Change to the Plate Carrier }; }; } forEach allUnits; Before removing the Current vest, I would like to copy the content and transfer it to the new one. Current Vest: 4x 30Rnd_65x39_caseless_mag 2x 30Rnd_65x39_caseless_mag_Tracer 3x 16Rnd_9x21_Mag 2x HandGrenade 2x B_IR_Grenade 1x SmokeShell 1x SmokeShellGreen 1x SmokeShellBlue 1x SmokeShellOrange 2x Chemlight_green New Vest: <Empty> Share this post Link to post Share on other sites
pierremgi 4836 Posted May 19, 2020 The simplest way: You must save the content of the vest in a variable : _oldContent = vestItems _x then, use addIemToVest after adding vest: { private _unit = _x; if (vest _unit == "V_PlateCarrierGL_rgr" or vest _unit == "V_PlateCarrierSpec_rgr") then { _oldContent = vestItems _unit; removeVest _unit; _unit addVest "V_PlateCarrier1_rgr"; { if (_unit canAddItemToVest _x) then { _unit addItemToVest _x} } forEach _oldContent; }; } forEach (allUnits select {side _x == WEST}); This script doesn't take into account the remaining rounds on each magazine. If you need that, you must use another command like getUnitLoadout. 4 Share this post Link to post Share on other sites
Harzach 2516 Posted May 19, 2020 6 minutes ago, pierremgi said: This script doesn't take into account the remaining rounds on each magazine. If you need that, you must use another command like getUnitLoadout. That's where I was getting mired down, should have switched to a get/set approach. 1 Share this post Link to post Share on other sites
ooakoetwo 0 Posted November 11, 2020 how do i add a vest with item to a crate? Share this post Link to post Share on other sites
pierremgi 4836 Posted November 11, 2020 Say your crate is crate1.You want to add a: v_plateCarrierGL_mtp with 3 batteries, 2 FAK and 1 binoculars. if (isServer) then { crate1 spawn { params ["_myCrate"]; private _myVestItems = [["firstAidKit",2],["binocular",1],["laserBatteries",3]]; private _conts = +(everyContainer _myCrate); _myCrate addItemCargoGlobal ["V_PlateCarrierGL_mtp",1]; private _theVest = (+(everyContainer _myCrate) - _conts) #0#1; {_theVest addItemCargoGlobal _x} count _myVestItems; }; }; 2 1 Share this post Link to post Share on other sites
quickdagger 170 Posted February 9, 2022 Hi all, This discussion is really very interesting. I am trying to do the same but, adding random vests, uniforms and weapons. So far this part works but the containers are empty, the items don't add back to the inventory. @pierremgi, I wonder if you could could give a hand here. I am trying to do the same but, in the configs, with event handlers. It is not working and I can't figure out why. Here is the config if you want to know: class dgr_arulco_Soldier1 : dgr_soldier_rambo { scope = 2; displayName = "Arulco Police Officer"; _generalMacro = "dgr_arulco_Soldier1"; side = 0; faction = "dgr_arulco"; author = "Dagger"; disabled = 0; vehicleClass = "Men"; role = "Rifleman"; nameSound = "veh_infantry_s"; cost = 100000; threat[] = {1,1,1}; canHideBodies = 1; canDeactivateMines = 0; attendant = 0; engineer = 0; canUseScanners = 0; nightVision = 0; uavHacker = 1; woman = 0; uniformClass = "dgr_uniform_police"; hiddenSelectionsTextures[] = {"\a3_dgr_equipment\data\dgr_uniform_police_co.paa"}; headgearList[] = { "dgr_beret2", "dgr_beret2", "dgr_ech28", "" }; identityTypes[] = {"LanguageFRE_F","Head_Tanoan"}; class EventHandlers: EventHandlers { //Headgear class Dgr_Headgear { init = "if (local (_this select 0)) then {[(_this select 0), [], []] call BIS_fnc_unitHeadgear;}"; }; //Switchable unit class Dgr_SwitchableUnit { init = "if (local (_this select 0)) then {addSwitchableUnit (_this select 0)};"; }; //Copy loadout class Dgr_CopyItems { init = "_DgrCopyItems[] = items (_this select 0);"; }; class Dgr_CopyAssignedItems { init = "_DgrCopyAssignedItems[] = assignedItems (_this select 0);"; }; class Dgr_CopyMagazines { init = "_DgrCopyMagazines[] = itemsWithMagazines (_this select 0);"; }; class Dgr_CopyUniformItems { init = "_DgrCopyUniformItems[] = uniformItems (_this select 0);"; }; class Dgr_CopyVestItems { init = "_DgrCopyVestItems[] = vestItems (_this select 0);"; }; class Dgr_CopyBackpackItems { init = "_DgrCopyBackpackItems[] = backpackItems (_this select 0);"; }; //Delete old gear class Dgr_RemoveUniform { init = "removeUniform (_this select 0);"; }; class Dgr_RemoveVest { init = "removeVest (_this select 0);"; }; class Dgr_RemoveBackpack { init = "removeBackpack (_this select 0);"; }; class Dgr_RemoveWeapon { init = "removeAllWeapons (_this select 0);"; }; //Spawn new gear class Dgr_SpawnUniform { init = "_DgrSpawnUniform = selectRandom [""dgr_uniform_police"",""dgr_rambo_police"",""dgr_uniform_mix_police""];"; }; class Dgr_SpawnVest { init = "_DgrSpawnVest = selectRandom [""dgr_vest_light_police5""];"; }; class Dgr_SpawnBackpack { init = "_DgrSpawnBackpack = selectRandom [""dgr_vest_belt"", ""dgr_holster""];"; }; class Dgr_SpawnWeapon { init = "_DgrSpawnWeapon = selectRandom [""dgr_45"", ""dgr_45_S2"", ""dgr_uzi_pdw""];"; }; //Add gear class Dgr_AddUniform { init = "(_this select 0) addUniform _DgrSpawnUniform;"; }; class Dgr_AddVest { init = "(_this select 0) addVest _DgrSpawnVest;"; }; class Dgr_AddBackpack { init = "(_this select 0) addBackpack _DgrSpawnBackpack;"; }; //Paste items back class Dgr_PasteItemsToUniform { init = "(_this select 0) addItemToUniform _DgrCopyUniformItems[];"; }; class Dgr_PasteItemsToVest { init = "(_this select 0) addItemToVest _DgrCopyVestItems[];"; }; class Dgr_PasteItemsToBackpack { init = "(_this select 0) addItemToBackpack _DgrCopyBackpackItems[];"; }; class Dgr_PasteItems { init = "(_this select 0) addItem _DgrCopyItems[];"; }; class Dgr_PasteAssignedItems { init = "(_this select 0) addItem _DgrCopyAssignedItems[];"; }; class Dgr_PasteMagazines { init = "(_this select 0) addItem _DgrCopyMagazines[];"; }; class Dgr_AddWeapon { init = "(_this select 0) addWeapon _DgrSpawnWeapon;"; }; //Insignia class Dgr_Insignia { init = "if (local (_this select 0)) then {[(_this select 0), ""dgr_logo_arulco""] call BIS_fnc_setUnitInsignia;}"; }; }; genericNames = "TanoanMen"; backpack = "dgr_holster"; Items[] = {"ACE_personalAidKit","ACE_tourniquet","ACE_tourniquet","ACE_morphine","ACE_morphine","ACE_epinephrine","ACE_CableTie","ACE_Banana","ACE_fieldDressing","ACE_fieldDressing","ACE_fieldDressing","ACE_fieldDressing","ACE_elasticBandage","ACE_elasticBandage","ACE_elasticBandage","ACE_elasticBandage","ACE_packingBandage","ACE_packingBandage","ACE_packingBandage","ACE_packingBandage"}; RespawnItems[] = {"ACE_personalAidKit","ACE_tourniquet","ACE_tourniquet","ACE_morphine","ACE_morphine","ACE_epinephrine","ACE_CableTie","ACE_Banana","ACE_fieldDressing","ACE_fieldDressing","ACE_fieldDressing","ACE_fieldDressing","ACE_elasticBandage","ACE_elasticBandage","ACE_elasticBandage","ACE_elasticBandage","ACE_packingBandage","ACE_packingBandage","ACE_packingBandage","ACE_packingBandage"}; linkedItems[] = {"dgr_vest_light_police5"}; respawnLinkedItems[] = {"dgr_vest_light_police5"}; weapons[] = {"Throw","Put","dgr_45"}; respawnWeapons[] = {"Throw","Put","dgr_45"}; magazines[] = {"DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","ACE_CTS9"}; respawnMagazines[] = {"DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","ACE_CTS9"}; }; Thank you in advance! Share this post Link to post Share on other sites
pierremgi 4836 Posted February 9, 2022 Sorry! No clue about this way. Share this post Link to post Share on other sites
Harzach 2516 Posted February 9, 2022 class Dgr_CopyItems { init = "_DgrCopyItems[] = items (_this select 0);"; }; class Dgr_PasteItems { init = "(_this select 0) addItem _DgrCopyItems[];"; }; I'm with Pierre, no idea about doing this via configs, but I can tell you that trying to pass local variables in global space like this will never work. 1 Share this post Link to post Share on other sites
quickdagger 170 Posted February 9, 2022 Well, I don't know what a local/global variable is and, what "pass a variable" is either. Nevertheless, it looks like I have found the solution 🙂 The reason I want to do it in the configs is that, every time one of my units is added to a mission, by the editor, Zeus or dynamically spawned by the mission generator, it will bring the full package. It will always have random gear no matter what. Here is the code in case you are curious: class dgr_arulco_Soldier1 : dgr_soldier_rambo { scope = 2; displayName = "Arulco Police Officer"; _generalMacro = "dgr_arulco_Soldier1"; side = 0; faction = "dgr_arulco"; author = "Dagger"; disabled = 0; vehicleClass = "Men"; role = "Rifleman"; nameSound = "veh_infantry_s"; cost = 100000; threat[] = {1,1,1}; canHideBodies = 1; canDeactivateMines = 0; attendant = 0; engineer = 0; canUseScanners = 0; nightVision = 0; uavHacker = 1; woman = 0; uniformClass = "dgr_uniform_police"; hiddenSelectionsTextures[] = {"\a3_dgr_equipment\data\dgr_uniform_police_co.paa"}; headgearList[] = { "dgr_beret2", "dgr_beret2", //"dgr_ech28", "lxWS_H_PASGT_goggles_white_F", "" }; identityTypes[] = {"LanguageFRE_F","Head_Tanoan"}; genericNames = "TanoanMen"; backpack = "dgr_holster"; Items[] = {"ACE_personalAidKit","ACE_tourniquet","ACE_tourniquet","ACE_morphine","ACE_morphine","ACE_epinephrine","ACE_CableTie","ACE_Banana","ACE_fieldDressing","ACE_fieldDressing","ACE_fieldDressing","ACE_fieldDressing","ACE_elasticBandage","ACE_elasticBandage","ACE_elasticBandage","ACE_elasticBandage","ACE_packingBandage","ACE_packingBandage","ACE_packingBandage","ACE_packingBandage"}; RespawnItems[] = {"ACE_personalAidKit","ACE_tourniquet","ACE_tourniquet","ACE_morphine","ACE_morphine","ACE_epinephrine","ACE_CableTie","ACE_Banana","ACE_fieldDressing","ACE_fieldDressing","ACE_fieldDressing","ACE_fieldDressing","ACE_elasticBandage","ACE_elasticBandage","ACE_elasticBandage","ACE_elasticBandage","ACE_packingBandage","ACE_packingBandage","ACE_packingBandage","ACE_packingBandage"}; linkedItems[] = {"ItemMap","ItemCompass","ItemRadio","dgr_vest_light_police5"}; respawnLinkedItems[] = {"ItemMap","ItemCompass","ItemRadio","dgr_vest_light_police5"}; weapons[] = {"Throw","Put","dgr_45"}; respawnWeapons[] = {"Throw","Put","dgr_45"}; magazines[] = {"DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","ACE_CTS9"}; respawnMagazines[] = {"DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","DGR_45_FMJ_25Rnd","ACE_CTS9"}; //https://forums.bohemia.net/forums/topic/229336-copying-vest-content-to-another-vest/?_fromLogin=1#replyForm class EventHandlers: EventHandlers { //Headgear class Dgr_Headgear { init = "if (local (_this select 0)) then {[(_this select 0), [], []] call BIS_fnc_unitHeadgear;}"; }; //Switchable unit class Dgr_SwitchableUnit { init = "if (local (_this select 0)) then {addSwitchableUnit (_this select 0)};"; }; //Private class Dgr_PrivateItems { init = "(_this select 0) == _x;"; }; //Copy loadout class Dgr_CopyItems { init = "_DgrCopyItems = items (_this select 0);"; }; class Dgr_CopyAssignedItems { init = "_DgrCopyAssignedItems = assignedItems (_this select 0);"; }; class Dgr_CopyMagazines { init = "_DgrCopyMagazines = itemsWithMagazines (_this select 0);"; }; class Dgr_CopyUniformItems { init = "_DgrCopyUniformItems = uniformItems (_this select 0);"; }; class Dgr_CopyVestItems { init = "_DgrCopyVestItems = vestItems (_this select 0);"; }; class Dgr_CopyBackpackItems { init = "_DgrCopyBackpackItems = backpackItems (_this select 0);"; }; //Delete old gear class Dgr_RemoveUniform { init = "removeUniform (_this select 0);"; }; class Dgr_RemoveVest { init = "removeVest (_this select 0);"; }; class Dgr_RemoveBackpack { init = "removeBackpack (_this select 0);"; }; class Dgr_RemoveWeapon { init = "removeAllWeapons (_this select 0);"; }; //Spawn new gear class Dgr_SpawnUniform { init = "_DgrSpawnUniform = selectRandom [""dgr_uniform_police"",""dgr_rambo_police"",""dgr_uniform_mix_police""];"; }; class Dgr_SpawnVest { init = "_DgrSpawnVest = selectRandom [""dgr_vest_light_police5""];"; }; class Dgr_SpawnBackpack { init = "_DgrSpawnBackpack = selectRandom [""dgr_vest_belt"", ""dgr_holster""];"; }; class Dgr_SpawnWeapon { init = "_DgrSpawnWeapon = selectRandom [""dgr_45"", ""dgr_45_S2"", ""dgr_uzi_pdw""];"; }; //Add gear class Dgr_AddUniform { init = "(_this select 0) addUniform _DgrSpawnUniform;"; }; class Dgr_AddVest { init = "(_this select 0) addVest _DgrSpawnVest;"; }; class Dgr_AddBackpack { init = "(_this select 0) addBackpack _DgrSpawnBackpack;"; }; //Paste items back /* class Dgr_PasteItemsToUniform { init = "{(_this select 0) addItemToUniform _x} forEach _DgrCopyUniformItems;"; }; class Dgr_PasteItemsToVest { init = "{(_this select 0) addItemToVest _x} forEach _DgrCopyVestItems;"; }; class Dgr_PasteItemsToBackpack { init = "{(_this select 0) addItemToBackpack _x} forEach _DgrCopyBackpackItems;"; }; class Dgr_PasteItems { init = "{(_this select 0) addItem _x} forEach _DgrCopyItems;"; }; class Dgr_PasteAssignedItems { init = "{(_this select 0) addItem _x} forEach _DgrCopyAssignedItems;"; }; */ class Dgr_PasteMagazines { init = "{(_this select 0) addItem _x} forEach _DgrCopyMagazines;"; }; class Dgr_AddWeapon { init = "(_this select 0) addWeapon _DgrSpawnWeapon;"; }; //Insignia class Dgr_Insignia { init = "if (local (_this select 0)) then {[(_this select 0), ""dgr_logo_arulco""] call BIS_fnc_setUnitInsignia;}"; }; }; }; It still comes with one less magazine, probably because it goes away when the event handler deletes the weapon, which contained it. In this case would you know how to fix it? Best! 1 Share this post Link to post Share on other sites
Harzach 2516 Posted February 9, 2022 4 hours ago, quickdagger said: Well, I don't know what a local/global variable is and, what "pass a variable" is either. Fundamental concepts.https://community.bistudio.com/wiki/Variables 1 Share this post Link to post Share on other sites
quickdagger 170 Posted February 9, 2022 Very nice reading, thank you for the directions. So, if this unit is spawned automatically by a KP Liberation server for example, what should be the issue? Because I have tested it in the editor, in multiplayer, on my local machine and it is working. Please correct me if I am wrong but I believe that, as the soldier spawns, it will create a local variable in whatever machine the server is, and this local variable will be deleted after call because it is local. Then, every player will see the created object soldier and he will be wearing a random loadout. If the variable was created public, not deleted because it is global, then, wouldn't it nullify the random effect? Share this post Link to post Share on other sites