The Orders Master 0 Posted June 4, 2020 So I've been trying to write a script to automatically set loadouts for any units on the blufor side, so i wouldn't have to set the loadout every time i switch some stuff around in the Mission. The Script also checks what type of unit it is (e.g. "B_Soldier_SL_F") and selects a loadout accordingly. This is my script so far: params [["_this", objNull, [objNull]]]; removeAllWeapons _this; removeAllItems _this; removeAllAssignedItems _this; removeUniform _this; removeVest _this; removeBackpack _this; removeHeadgear _this; removeGoggles _this; _this setSpeaker "Male05ENGB"; _this setFace selectRandom ["WhiteHead_03", "WhiteHead_14", "WhiteHead_04"]; switch (typeOf _this) do{ case "B_Soldier_SL_F"; case "B_Soldier_TL_F": {call FNC_Leader;}; case "B_Soldier_F": {call selectRandom [FNC_Soldier_FAL, FNC_Soldier_LEE, FNC_Soldier_LEE];}; case "B_Sharpshooter_F": {call FNC_Sharpshooter;}; case "B_medic_F": {call FNC_Medic;}; }; exit; FNC_Leader = { //Add Weapons _this addWeapon "CUP_arifle_SR3M_Vikhr"; _this addPrimaryWeaponItem "CUP_30Rnd_9x39_SP5_VIKHR_M"; _this addWeapon "CUP_hgun_Colt1911"; _this addHandgunItem "CUP_7Rnd_45ACP_1911"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add binoculars _this addWeapon "Binocular"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; _this addItemToUniform "CUP_7Rnd_45ACP_1911"; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 4 do {_this addItemToVest "CUP_30Rnd_9x39_SP5_VIKHR_M";}; for "_i" from 1 to 2 do {_this addItemToVest "CUP_7Rnd_45ACP_1911";}; _this addHeadgear "rhsgref_un_beret"; _this addGoggles "CUP_G_PMC_RadioHeadset"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Soldier_LEE = { //Add weapons _this addWeapon "CUP_srifle_LeeEnfield"; _this addPrimaryWeaponItem "CUP_10x_303_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 10 do {_this addItemToVest "CUP_10x_303_M";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Soldier_FAL = { //Add weapons _this addWeapon "CUP_arifle_FNFAL5060"; _this addPrimaryWeaponItem "CUP_20Rnd_762x51_FNFAL_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 5 do {_this addItemToVest "CUP_20Rnd_762x51_FNFAL_M";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Sharpshooter = { //Add weapons _this addWeapon "CUP_srifle_LeeEnfield"; _this addPrimaryWeaponItem "CUP_optic_no23mk2"; _this addPrimaryWeaponItem "CUP_10x_303_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 10 do {_this addItemToVest "CUP_10x_303_M";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Medic = { //Add weapons _this addWeapon "CUP_srifle_LeeEnfield"; _this addPrimaryWeaponItem "CUP_10x_303_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; _this addBackpack "B_TacticalPack_oli"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 8 do {_this addItemToVest "CUP_10x_303_M";}; _this addItemToBackpack "Medikit"; for "_i" from 1 to 10 do {_this addItemToBackpack "FirstAidKit";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; Now, the problem i run into is that for some odd reason one unit ends up with just it's underwear. So i suppose it must have an error at the switch-do structure, but i don't get why. I'm calling this from a Trigger and the code there is: {if ((side _x) == west) then {[_x] call Orders_fnc_loadUnit;}} forEach allUnits; and the Orders_fnc_loadUnit function looks like this: params [["_this", objNull, [objNull]]]; switch (side _this) do{ case west: {[_this] execVM "units\west.sqf";}; case independent: {[_this] execVM "units\independent.sqf";}; }; I also plan on turning this into a multiplayer mission at some point, so any tipps regarding that would be very much appreciated as well. Cheers Share this post Link to post Share on other sites
Crazy_Man 36 Posted June 4, 2020 For multiplayer, better use this command setUnitLoadout. And for the problem with the group leader it is because, when the switch is first declared, all the functions below the switch are not yet declared. So try do declare all the functions before the switch. params [["_this", objNull, [objNull]]]; FNC_Leader = { //Add Weapons _this addWeapon "CUP_arifle_SR3M_Vikhr"; _this addPrimaryWeaponItem "CUP_30Rnd_9x39_SP5_VIKHR_M"; _this addWeapon "CUP_hgun_Colt1911"; _this addHandgunItem "CUP_7Rnd_45ACP_1911"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add binoculars _this addWeapon "Binocular"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; _this addItemToUniform "CUP_7Rnd_45ACP_1911"; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 4 do {_this addItemToVest "CUP_30Rnd_9x39_SP5_VIKHR_M";}; for "_i" from 1 to 2 do {_this addItemToVest "CUP_7Rnd_45ACP_1911";}; _this addHeadgear "rhsgref_un_beret"; _this addGoggles "CUP_G_PMC_RadioHeadset"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Soldier_LEE = { //Add weapons _this addWeapon "CUP_srifle_LeeEnfield"; _this addPrimaryWeaponItem "CUP_10x_303_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 10 do {_this addItemToVest "CUP_10x_303_M";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Soldier_FAL = { //Add weapons _this addWeapon "CUP_arifle_FNFAL5060"; _this addPrimaryWeaponItem "CUP_20Rnd_762x51_FNFAL_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 5 do {_this addItemToVest "CUP_20Rnd_762x51_FNFAL_M";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Sharpshooter = { //Add weapons _this addWeapon "CUP_srifle_LeeEnfield"; _this addPrimaryWeaponItem "CUP_optic_no23mk2"; _this addPrimaryWeaponItem "CUP_10x_303_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 10 do {_this addItemToVest "CUP_10x_303_M";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Medic = { //Add weapons _this addWeapon "CUP_srifle_LeeEnfield"; _this addPrimaryWeaponItem "CUP_10x_303_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; _this addBackpack "B_TacticalPack_oli"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 8 do {_this addItemToVest "CUP_10x_303_M";}; _this addItemToBackpack "Medikit"; for "_i" from 1 to 10 do {_this addItemToBackpack "FirstAidKit";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; removeAllWeapons _this; removeAllItems _this; removeAllAssignedItems _this; removeUniform _this; removeVest _this; removeBackpack _this; removeHeadgear _this; removeGoggles _this; _this setSpeaker "Male05ENGB"; _this setFace selectRandom ["WhiteHead_03", "WhiteHead_14", "WhiteHead_04"]; switch (typeOf _this) do{ case "B_Soldier_SL_F"; case "B_Soldier_TL_F": {call FNC_Leader;}; case "B_Soldier_F": {call selectRandom [FNC_Soldier_FAL, FNC_Soldier_LEE, FNC_Soldier_LEE];}; case "B_Sharpshooter_F": {call FNC_Sharpshooter;}; case "B_medic_F": {call FNC_Medic;}; }; exit; 1 Share this post Link to post Share on other sites
The Orders Master 0 Posted June 4, 2020 Oooooh, yeah makes sense. Thank you so much for the quick reply. Share this post Link to post Share on other sites
Crazy_Man 36 Posted June 4, 2020 Tips for performance: Create your functions (like FNC_Leader) only once because each time you execute the west.sqf or independent.sqf script you recreate these functions. An example: init.sqf: if (isServer) then { Orders_fnc_loadUnit = { params [["_this", objNull, [objNull]]]; switch (side _this) do{ case west: {[_this] execVM "units\west.sqf";}; case independent: {[_this] execVM "units\independent.sqf";}; }; }; FNC_Leader_West = { params ["_this"]; //Add Weapons _this addWeapon "CUP_arifle_SR3M_Vikhr"; _this addPrimaryWeaponItem "CUP_30Rnd_9x39_SP5_VIKHR_M"; _this addWeapon "CUP_hgun_Colt1911"; _this addHandgunItem "CUP_7Rnd_45ACP_1911"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add binoculars _this addWeapon "Binocular"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; _this addItemToUniform "CUP_7Rnd_45ACP_1911"; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 4 do {_this addItemToVest "CUP_30Rnd_9x39_SP5_VIKHR_M";}; for "_i" from 1 to 2 do {_this addItemToVest "CUP_7Rnd_45ACP_1911";}; _this addHeadgear "rhsgref_un_beret"; _this addGoggles "CUP_G_PMC_RadioHeadset"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Soldier_LEE_West = { params ["_this"]; //Add weapons _this addWeapon "CUP_srifle_LeeEnfield"; _this addPrimaryWeaponItem "CUP_10x_303_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 10 do {_this addItemToVest "CUP_10x_303_M";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Soldier_FAL_West = { params ["_this"]; //Add weapons _this addWeapon "CUP_arifle_FNFAL5060"; _this addPrimaryWeaponItem "CUP_20Rnd_762x51_FNFAL_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 5 do {_this addItemToVest "CUP_20Rnd_762x51_FNFAL_M";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Sharpshooter_West = { params ["_this"]; //Add weapons _this addWeapon "CUP_srifle_LeeEnfield"; _this addPrimaryWeaponItem "CUP_optic_no23mk2"; _this addPrimaryWeaponItem "CUP_10x_303_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 10 do {_this addItemToVest "CUP_10x_303_M";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; FNC_Medic_West = { params ["_this"]; //Add weapons _this addWeapon "CUP_srifle_LeeEnfield"; _this addPrimaryWeaponItem "CUP_10x_303_M"; //Add containers _this forceAddUniform "U_BG_Guerrilla_6_1"; _this addVest "V_HarnessO_brn"; _this addBackpack "B_TacticalPack_oli"; //Add items to containers for "_i" from 1 to 2 do {_this addItemToUniform "FirstAidKit";}; for "_i" from 1 to 2 do {_this addItemToVest "rhs_grenade_mkii_mag";}; for "_i" from 1 to 8 do {_this addItemToVest "CUP_10x_303_M";}; _this addItemToBackpack "Medikit"; for "_i" from 1 to 10 do {_this addItemToBackpack "FirstAidKit";}; _this addHeadgear "rhsgref_un_beret"; //Add items _this linkItem "ItemMap"; _this linkItem "ItemCompass"; _this linkItem "ItemWatch"; }; // Add the others functions for the independent side here, don't forget the "params ["_this"];" at the begining of all these functions }; west.sqf : params [["_this", objNull, [objNull]]]; removeAllweapons _this; removeAllItems _this; removeAllAssignedItems _this; removeUniform _this; removeVest _this; removeBackPack _this; removeHeadGear _this; removeGoggles _this; _this setSpeaker "Male05ENGB"; _this setFace selectRandom ["WhiteHead_03", "WhiteHead_14", "WhileHead_04"]; switch (typeOf _this) do { case "B_Soldier_SL_F"; case "B_Soldier_TL_F": {[_this] call FNC_Leader_west}; case "B_Soldier_F": {[_this] call selectRandom [FNC_Soldier_FAL_West, FNC_Soldier_LEE_West, FNC_Soldier_LEE_West]}; case "B_SharShooter_F": {[_this] call FNC_Sharpshooter_west}; case "B_medic_F": {[_this] call FNC_medic_West}; }; Share this post Link to post Share on other sites