Justin Bowes 1 Posted September 16 I'm new to Arma scripting. I've been using ChatGPT 4o to generate code (after having it research the language of Arma), then using my limited knowledge on the language of Arma to try to repair various problems. Since ChatGPT seams to have hit a wall with its ability to help me, and it keeps repeating like a skipping record that I need to double check my code is actually correct, I decided perhaps experienced (human) scripters would immediately see the issue, diagnose the solution, and then kindly and comprehensively explain what was going wrong and how to fix it. I'm eager to learn more about coding, but you may need to break things down into laymen's terms. If you respond to this, Thank you so much for trying to help me in advance. A bit of background on what I'm trying to accomplish: I have a bunch of terrorist riflemen. I want to make it to where, on mission start, there is a 80% chance that they spawn with a "basic Rifleman" loadout and a 20% chance that they spawn with a "elite rifleman" loadout. I tried getting it to work with specified variable names, but eventually figured out that I can design the code so any unit with the initiation script in its Init field can have the script applied to them. It still doesn't work, despite my code editor (Visual Studio Code) not finding any errors with the script itself. Arma 3 seams to be very stingy about "defining" variables, and I can't seam to fix it no matter what I do. PLEASE HELP ME!!! I have been frustratedly working on this for almost 2 weeks now, working on it almost 2 hours a day, and I'm not getting anywhere. The script itself: Initiated by the init field of each affected unit: [this] execVM "EliteOrNot.sqf"; private _basicLoadout = [ //Defines what should be in _basicLoadout variable ["arifle_AKM_F", "", "", ["30Rnd_762x39_Mag_F", 30], [], ""], [], [], ["Binocular", [], "", "", [], ""], ["U_I_C_Soldier_Bandit_4_F", [ "FirstAidKit", "30Rnd_762x39_Mag_F", "30Rnd_762x39_Mag_F" ]], ["V_BandollierB_blk", [ "HandGrenade", "30Rnd_762x39_Mag_F", "30Rnd_762x39_Mag_F", "30Rnd_762x39_Mag_F", "ACE_CTS9" ]], ["B_Messenger_Black_F", [ "ACE_fieldDressing", "ACE_quikclot", "ACE_quikclot", "ACE_elasticBandage", "ACE_elasticBandage", "ACE_elasticBandage", "ACE_EarPlugs", "ACE_morphine", "ACE_splint", "ACE_splint", "ACE_tourniquet", "kat_EACA", "30Rnd_762x39_Mag_F" ]], ["H_Bandanna_gry", "G_Balaclava_blk"], ["ItemMap", "ItemCompass", "ItemWatch", "ItemRadio", "ItemGPS"], [], "", ["male01per"], [], [] ]; private _eliteLoadout = [ //Defines what should be in the _eliteLoadout Variable ["arifle_AK12_F", "", "", ["30Rnd_762x39_AK12_Mag_F", 30], [], ""], ["hgun_Rook40_F", "", "", ["16Rnd_9x21_Mag", 16], [], ""], [], ["Binocular", [], "", "", [], ""], ["U_C_E_LooterJacket_01_F", [ "ACE_fieldDressing", "ACE_packingBandage", "ACE_morphine", "ACE_tourniquet", "30Rnd_762x39_AK12_Mag_F", "16Rnd_9x21_Mag" ]], ["V_PlateCarrier2_blk", [ "HandGrenade", "HandGrenade", "30Rnd_762x39_AK12_Mag_F", "30Rnd_762x39_AK12_Mag_F", "30Rnd_762x39_AK12_Mag_F", "30Rnd_762x39_AK12_Mag_F", "16Rnd_9x21_Mag", "16Rnd_9x21_Mag" ]], ["B_LegStrapBag_coyote_F", [ "ACE_fieldDressing", "ACE_fieldDressing", "ACE_quikclot", "ACE_quikclot", "ACE_elasticBandage", "ACE_elasticBandage", "kat_chestSeal", "ACE_EarPlugs", "ACE_epinephrine", "ACE_morphine", "ACE_splint", "ACE_tourniquet", "ACE_tourniquet" ]], ["H_PASGT_basic_black_F", "G_Bandanna_beast"], ["ItemMap", "ItemCompass", "ItemWatch", "ItemRadio", "ItemGPS"], [], "", ["male02per"], [], [] ]; if (random 1 < 0.8) then { //80% chance _unit setUnitLoadout _basicLoadout; //affected unit sets loadout as "basic" } else { //If this does not happen, then _unit setUnitLoadout _eliteLoadout; //affected unit sets loadout as "elite" }; //End Function I don't know how much context you need to understand any of this, but I did my best to give EVERY DETAIL I could possible give you because I'm used to working with AI, which requires as much specification as possible to function correctly. If I over-informed you, I'm sorry, and thank you for being patient with this. Again, thank you so much for your advice in advance. I know that if your responding to this forum, you either have a similar problem, or you know your way around a code and are searching forums, perhaps bored, looking for challenges to conquer. Either way, any information you want to contribute to this forum, please do, regardless of why you are viewing this thread. Thank you and thank you again! Share this post Link to post Share on other sites
JCataclisma 78 Posted September 16 Hello! Does the game tell you which specific variable is wrong, like showing you the "#" symbol before the variable name? And, just for the sake of an extra testing, you could have two soldiers anywhere distant on your map, named "elite" and "notElite", already using the desired loadout. Then you try to use the syntax shown on the Example 2 (link at the end of this message) So instead of your current last lines on the provided code, you could try something like this: if (random 1 < 0.8) then { _unit setUnitLoadout (getUnitLoadout notElite); } else { _unit setUnitLoadout (getUnitLoadout elite); }; https://community.bistudio.com/wiki/setUnitLoadout?useskin=darkvector Share this post Link to post Share on other sites
mrcurry 496 Posted September 16 (edited) 4 hours ago, JCataclisma said: https://community.bistudio.com/wiki/setUnitLoadout?useskin=darkvector I've been doing SQF since Arma 2... Hundreds if not thousands of hours spent looking on the BIKI... and today I learned the BIKI has dark themes... F M L Edit: Right maybe I should contribute something useful... Only thing I see is that _unit isn't defined in what you posted.Something like: params["_unit"]; at the start of EliteOrNot.sqf should do the trick. Edited September 16 by mrcurry Being useful 2 Share this post Link to post Share on other sites
Maff 250 Posted September 17 (edited) On 9/16/2024 at 5:27 PM, Justin Bowes said: I've been using ChatGPT 4o to generate code... You maniac! Your loadout array is completely messed up. See Unit Loadout Array for the correct syntax. Here is a template for reference and to help get you sorted. Spoiler _testLoadout = [ [ // Primary weapon. "arifle_AK12_F", "", "", "", ["30Rnd_762x39_AK12_Mag_F", 30], [], "" ], [ // Launcher - Secondary weapon. "", "", "", "", [], [], "" ], [ // Handgun. "hgun_Rook40_F", "", "", "", ["16Rnd_9x21_Mag", 16], [], "" ], [ // Uniform. "U_C_E_LooterJacket_01_F", [ // 2x basic bandages. ["ACE_fieldDressing", 2], // 2x Quickclots. ["ACE_quikclot", 2] ] ], [ // Vest. "V_PlateCarrier2_blk", [ // 5x 30Rnd mags. ["30Rnd_762x39_AK12_Mag_F", 5, 30], // 2x hand grenades. ["HandGrenade", 2, 1] ] ], [ // Backpack "B_AssaultPack_mcamo_Ammo", [ // 2x 30Rnd mags. ["30Rnd_762x39_AK12_Mag_F", 2, 30], // 8x splints. ["ACE_splint", 8] ] ], // Headgear. "H_PASGT_basic_black_F", // Googles / Facewear. "G_Bandanna_beast", // Binocular. ["Binocular", "", "", "", [], [], ""], // Assigned items below. ["ItemMap", "", "ItemRadio", "ItemCompass", "ItemWatch", ""] ]; _unit = _this #0; _unit setUnitLoadout _testLoadout; EDIT: Or you can scroll to the bottom of that link for a better example - D'oh! Edited September 17 by Maff 1 Share this post Link to post Share on other sites
Justin Bowes 1 Posted September 18 So, I've done that in previous versions. Should I still add it, in addition to the "private _unit = _this select 0;" ABOVE it, or replace it? Or what? Share this post Link to post Share on other sites
Justin Bowes 1 Posted September 18 Good idea, JCataclisma I'm going to do that because apparently: 4 hours ago, Maff said: You maniac! Your loadout array is completely messed up. See Unit Loadout Array for the correct syntax. Here is a template for reference and to help get you sorted. Reveal hidden contents _testLoadout = [ [ // Primary weapon. "arifle_AK12_F", "", "", "", ["30Rnd_762x39_AK12_Mag_F", 30], [], "" ], [ // Launcher - Secondary weapon. "", "", "", "", [], [], "" ], [ // Handgun. "hgun_Rook40_F", "", "", "", ["16Rnd_9x21_Mag", 16], [], "" ], [ // Uniform. "U_C_E_LooterJacket_01_F", [ // 2x basic bandages. ["ACE_fieldDressing", 2], // 2x Quickclots. ["ACE_quikclot", 2] ] ], [ // Vest. "V_PlateCarrier2_blk", [ // 5x 30Rnd mags. ["30Rnd_762x39_AK12_Mag_F", 5, 30], // 2x hand grenades. ["HandGrenade", 2, 1] ] ], [ // Backpack "B_AssaultPack_mcamo_Ammo", [ // 2x 30Rnd mags. ["30Rnd_762x39_AK12_Mag_F", 2, 30], // 8x splints. ["ACE_splint", 8] ] ], // Headgear. "H_PASGT_basic_black_F", // Googles / Facewear. "G_Bandanna_beast", // Binocular. ["Binocular", "", "", "", [], [], ""], // Assigned items below. ["ItemMap", "", "ItemRadio", "ItemCompass", "ItemWatch", ""] ]; _unit = _this #0; _unit setUnitLoadout _testLoadout; EDIT: Or you can scroll to the bottom of that link for a better example - D'oh! And I do not currently want to learn the code names of every single object and how to do it right. This is a bit easier. 1 Share this post Link to post Share on other sites
Maff 250 Posted September 18 21 minutes ago, Justin Bowes said: And I do not currently want to learn the code names of every single object and how to do it right. This is a bit easier. Another option is to use ACE Arsenal to create each loadout, export it to clipboard and paste into your script. Share this post Link to post Share on other sites
Justin Bowes 1 Posted September 18 My new code currently reflects this: Params ["_unit"]; ["_unit"] = _this select 0; if (random 1 < 0.8) then { _unit setUnitLoadout getUnitLoadout basic; } else { _unit setUnitLoadout getUnitLoadout elite; }; I'm currently getting errors with having not defined "basic" or "elite" variables, and also I'm apparently missing a ; on line 2 which seams like a load of arma 3 bull crap to me. Nevertheless, If it won't function, it won't function, and I need to fix the code regardless. Again, I'm sure there's something like six rookie mistakes I made with formatting in this script, so point that out if you see it. Share this post Link to post Share on other sites
JCataclisma 78 Posted September 18 You don't need all those symbols on the second line - just use "_unit = _this select 0;" . And, accordingly to that example on wiki page, you are missing the parenthesis on the "getUnitLoadout". So try this: Params ["_unit"]; _unit = _this # 0; if (random 1 < 0.8) then { _unit setUnitLoadout (getUnitLoadout basic); } else { _unit setUnitLoadout (getUnitLoadout elite); }; Share this post Link to post Share on other sites
Maff 250 Posted September 18 18 hours ago, Justin Bowes said: I'm sure there's something like six rookie mistakes I made with formatting in this script, so point that out if you see it. Post all your script, please. It'll help solve your scripting issues quicker. Did you correct your _basicLoadout and _eliteLoadout arrays? Or, Have you changed your method? Are "basic" and "elite" your loadout arrays? Do you have "basic" and "elite" units named and with the loadouts you want?BTW. Using ChatGPT, or SkyNet Junior, isn't helping you or the folk trying to help you. Share this post Link to post Share on other sites
Justin Bowes 1 Posted September 18 I tried your code, and it gave me several undefined errors. My code editor doesn't like it, and neither does Arma. "Value of private variable '_unit' is never used." also, my code editor recommends I remove the parenthesis around the "getunitloadout" commands saying that "parenthesis can be safely removed (altho i'm not sure if this is just a fluke so ill take your word for it)" Also, "global variable 'basic' is never assigned in this file." Also, "global variable 'elite' is never assigned in this file." Those are just the errors from my text editor, but arma seams to completely disregard that and give me 8109 error messages of its own. I'm sure you know what I mean. (responding to JCataclisma) 1 Share this post Link to post Share on other sites
Justin Bowes 1 Posted September 18 Yeah I changed my array to copy and paste loadout from another unit I placed 22 kilometers across the map. And yes, I do have "basic" and "elite" units in-game. Also, I only used ChatGPT for the original code because it was a much more rapid way to get an original feal for what I was working with. (responding to Maff) Share this post Link to post Share on other sites
Justin Bowes 1 Posted September 18 My code is now: (full script) Params ["_unit"]; _unit = _this # 0; if (random 1 < 0.8) then { _unit setUnitLoadout (getUnitLoadout basic); } else { _unit setUnitLoadout (getUnitLoadout elite); }; Share this post Link to post Share on other sites
II OMEGA101 II 17 Posted September 19 Hi Justin, Your on the right lines in some bits. Your just missing some elements of the script though. I have a little experience with loadout scripts. Happy to share an example. Loadout.sqf _unit = _this select 0; _LoadoutBasic = { _unit = _this select 0; removeAllWeapons _unit; removeAllItems _unit; removeAllAssignedItems _unit; removeUniform _unit; removeVest _unit; removeBackpack _unit; removeHeadgear _unit; removeGoggles _unit; // ________________ Random Stuff ________________ // _MainWeapon = selectRandom [ "arifle_AKM_F", "hgun_PDW2000_F", "SMG_01_F", "SMG_05_F", "hgun_Pistol_01_F", "hgun_Pistol_heavy_02_F", "arifle_AKS_F", "srifle_DMR_06_hunter_F", "sgun_HunterShotgun_01_F", "sgun_HunterShotgun_01_sawedoff_F" ]; _Sidearm = selectRandom [ ]; _Uniforms = selectRandom [ "U_B_CombatUniform_mcam_vest","U_B_GEN_Soldier_F","U_C_WorkerCoveralls","U_C_Poor_1","U_B_CombatUniform_tshirt_mcam_wdL_f","U_C_HunterBody_grn", "U_C_Poor_shorts_1","U_C_Commoner_shorts" ]; _Vests = selectRandom [ "V_Rangemaster_belt","V_BandollierB_khk","V_BandollierB_cbr","V_BandollierB_rgr","V_BandollierB_blk","V_BandollierB_oli","V_Chestrig_khk", "V_Chestrig_rgr","V_Chestrig_blk","V_Chestrig_oli","V_Pocketed_black_F","V_LegStrapBag_black_F" ]; _Headgear = selectRandom [ "H_Cap_grn_BI","H_Cap_police","H_Cap_usblack","H_HelmetB_light","H_Cap_blk_Raven","H_Cap_blk_ION","H_Watchcap_cbr","H_Watchcap_khk", "H_Watchcap_camo","H_Watchcap_sgg","H_Hat_Safari_sand_F","H_Hat_Safari_olive_F","H_HeadBandage_bloody_F" ]; _Backpacks = selectRandom [ "B_LegStrapBag_black_F","B_LegStrapBag_coyote_F","B_LegStrapBag_olive_F","B_Messenger_Black_F","B_Messenger_Coyote_F", "B_Messenger_Gray_F","B_Messenger_Olive_F","B_Messenger_IDAP_F","" ]; _Facewear = selectRandom [ "G_Balaclava_blk","G_Balaclava_combat","G_Balaclava_lowprofile","G_Balaclava_TI_blk_F","G_Balaclava_TI_G_blk_F", "G_Balaclava_TI_tna_F","G_Balaclava_TI_G_tna_F","G_Bandanna_aviator","G_Bandanna_beast","G_Bandanna_blk","G_Bandanna_khk", "G_Bandanna_shades","G_Bandanna_sport","G_Bandanna_oli","G_Bandanna_tan","" ]; _LinkItems = selectRandom [ "ItemMap","ItemCompass","ItemWatch","ItemRadio","ItemGPS" ]; _Items = selectRandom [ "rvg_plasticBottleEmpty","rvg_beansEmpty","rvg_plasticBottle","Chemlight_red","rvg_spirit","rvg_franta","rvg_beans", "rvg_bacon","rvg_flare","rvg_docFolder","rvg_notepad","rvg_plasticBottlePurified","FirstAidKit","rvg_guttingKnife" ]; // ________________ Loadout ________________ // _unit forceAddUniform _Uniforms; _unit addVest _Vests; _unit addBackpack _Backpacks; for "_i" from 1 to (1 + floor random 2) do {_unit addItemToVest _Items;}; _RandomNo = [1,2,3,4] call BIS_fnc_selectRandom; [_unit,_MainWeapon,_RandomNo] call bis_fnc_addWeapon; _unit addHeadgear _Headgear; _unit setIdentity _Facewear; _unit linkItem _LinkItems; }; _LoadoutElite { _unit = _this select 0; removeAllWeapons _unit; removeAllItems _unit; removeAllAssignedItems _unit; removeUniform _unit; removeVest _unit; removeBackpack _unit; removeHeadgear _unit; removeGoggles _unit; // ________________ Random Stuff ________________ // _MainWeapon = selectRandom [ "arifle_AKM_F", "hgun_PDW2000_F", "SMG_01_F", "SMG_05_F", "hgun_Pistol_01_F", "hgun_Pistol_heavy_02_F", "arifle_AKS_F", "srifle_DMR_06_hunter_F", "sgun_HunterShotgun_01_F", "sgun_HunterShotgun_01_sawedoff_F" ]; _Sidearm = selectRandom [ ]; _Uniforms = selectRandom [ "U_B_CombatUniform_mcam_vest","U_B_GEN_Soldier_F","U_C_WorkerCoveralls","U_C_Poor_1","U_B_CombatUniform_tshirt_mcam_wdL_f","U_C_HunterBody_grn", "U_C_Poor_shorts_1","U_C_Commoner_shorts" ]; _Vests = selectRandom [ "V_Rangemaster_belt","V_BandollierB_khk","V_BandollierB_cbr","V_BandollierB_rgr","V_BandollierB_blk","V_BandollierB_oli","V_Chestrig_khk", "V_Chestrig_rgr","V_Chestrig_blk","V_Chestrig_oli","V_Pocketed_black_F","V_LegStrapBag_black_F" ]; _Headgear = selectRandom [ "H_Cap_grn_BI","H_Cap_police","H_Cap_usblack","H_HelmetB_light","H_Cap_blk_Raven","H_Cap_blk_ION","H_Watchcap_cbr","H_Watchcap_khk", "H_Watchcap_camo","H_Watchcap_sgg","H_Hat_Safari_sand_F","H_Hat_Safari_olive_F","H_HeadBandage_bloody_F" ]; _Backpacks = selectRandom [ "B_LegStrapBag_black_F","B_LegStrapBag_coyote_F","B_LegStrapBag_olive_F","B_Messenger_Black_F","B_Messenger_Coyote_F", "B_Messenger_Gray_F","B_Messenger_Olive_F","B_Messenger_IDAP_F","" ]; _Facewear = selectRandom [ "G_Balaclava_blk","G_Balaclava_combat","G_Balaclava_lowprofile","G_Balaclava_TI_blk_F","G_Balaclava_TI_G_blk_F", "G_Balaclava_TI_tna_F","G_Balaclava_TI_G_tna_F","G_Bandanna_aviator","G_Bandanna_beast","G_Bandanna_blk","G_Bandanna_khk", "G_Bandanna_shades","G_Bandanna_sport","G_Bandanna_oli","G_Bandanna_tan","" ]; _LinkItems = selectRandom [ "ItemMap","ItemCompass","ItemWatch","ItemRadio","ItemGPS" ]; _Items = selectRandom [ "rvg_plasticBottleEmpty","rvg_beansEmpty","rvg_plasticBottle","Chemlight_red","rvg_spirit","rvg_franta","rvg_beans", "rvg_bacon","rvg_flare","rvg_docFolder","rvg_notepad","rvg_plasticBottlePurified","FirstAidKit","rvg_guttingKnife" ]; // ________________ Loadout ________________ // _unit forceAddUniform _Uniforms; _unit addVest _Vests; _unit addBackpack _Backpacks; for "_i" from 1 to (1 + floor random 2) do {_unit addItemToVest _Items;}; _RandomNo = [1,2,3,4] call BIS_fnc_selectRandom; [_unit,_MainWeapon,_RandomNo] call bis_fnc_addWeapon; _unit addHeadgear _Headgear; _unit setIdentity _Facewear; _unit linkItem _LinkItems; }; if (random 1 < 0.8) then { [_unit] spawn _LoadoutBasic; } else { [_unit] spawn _LoadoutElite; }; To call the loadout script put this into the soldier's init field. This can also be used on units spawned via script. Simply swap "this" out with the variable of the unit. [this] execVM "Loadout.sqf"; Your passing the variable of the unit into the script when you execute it which is good. Also you don't need a hashtag just "_unit = _this select 0;" will be okay. I usually put this at the top of the script as it's always worked best for me that way. What this line does it will assign _unit as the variable for the variable that you passed into the script. What your missing is the code that adds the items to the unit. I take it that you may want to remove just the weapon rather than everything the unit has like I've done? Feel free to use and adjust my code. At the bottom of my script you can see I've got commands that add weapons, uniforms and items to the unit which is what I think your missing. Give this is a go and see if it helps. I would recommend reading about global and local variables in arma too. Edit: sorry i missed completely that you want to select a loadout at random. When I'm back later I'll show you how you can do that. Edit 2: I've re-edited the code. I've changed the loadouts into two functions within the same script. There's numerous ways you can go about doing this and you'll likely change your method a dozen times over however this..... should ...... work. Just ammend the code to how you need to. If you only want items and weapons then you can simply delete the other lines and keep the lines that add items and weapons. If your not using ravage I would recommend removing all class names beginning with rvg. I hope this helps. 1 Share this post Link to post Share on other sites
Justin Bowes 1 Posted September 20 Thanks... But I must ask for the sake of asking, wouldn't it just be easier to copy and paste a loadout from an existing unit? I find that the names of each loadout item can be kinda elusive sometimes and very confusing... and I'm by no means experienced in this category... Share this post Link to post Share on other sites
II OMEGA101 II 17 Posted September 21 This is just an example. I needed to fully customise the loadouts of the units I spawned for the scenario I built. You can take the concept and customise how you like. Chop and change it to make it as easy or as specific as you want. Share this post Link to post Share on other sites