Jump to content
Sign in to follow this  
egbert

Custom Loadout Script

Recommended Posts

Hi there !

 

I'm trying to make a MP mission where all my IAs spawn from a SQF file. But I also want these IAs equiped with a random custom loadout, from another SQF file if possible (I already managed to call and equip IA in one SQF file, but I really would like to separate those files so I can adapt any mission easily).

 

This was my original SQF, which was working :

params ["_type", "_x"];

if (isServer || isDedicated) then {

//Garde robe et armurerie dispo
_weaponList = [
	["arifle_Mk20_ACO_pointer_F","30Rnd_556x45_Stanag"],
	["hgun_PDW2000_Holo_F","30Rnd_9x21_Mag"],
	["SMG_02_ACO_F","30Rnd_9x21_Mag_SMG_02"],
	["SMG_05_F","30Rnd_9x21_Mag_SMG_02"],
	["hlc_rifle_aks74u_MTK","hlc_30Rnd_545x39_B_AK"],
	["arifle_AKM_F","30Rnd_762x39_Mag_F"],
	["hlc_rifle_aks74","hlc_30Rnd_545x39_B_AK"],
	["arifle_CTAR_blk_F","30Rnd_580x42_Mag_F"],
	["hlc_rifle_aku12","hlc_30Rnd_545x39_B_AK"]
];

_weaponListMg = [
    ["LMG_Mk200_pointer_F","200Rnd_65x39_cased_Box"],
	["Weapon_LMG_Zafir_F","150Rnd_762x54_Box"],
	["hlc_rifle_rpk","hlc_75Rnd_762x39_m_rpk"],
	["LMG_03_F","200Rnd_556x45_Box_F"]
];

_weaponListGl = [
	["arifle_AK12_GL_F","30Rnd_762x39_Mag_F"],
	["hlc_rifle_ak74m_gl","hlc_30Rnd_545x39_B_AK"],
	["arifle_Mk20_GL_plain_F","30Rnd_556x45_Stanag"]
];

_weaponListTp = [
    ["srifle_EBR_F","20Rnd_762x51_Mag"],
	["srifle_DMR_01_F","10Rnd_762x54_Mag"],
	["srifle_DMR_04_F","10Rnd_127x54_Mag"],
    ["arifle_AK12_F","30Rnd_762x39_Mag_F"],
    ["srifle_DMR_07_blk_F","20Rnd_650x39_Cased_Mag_F"],	
    ["srifle_DMR_06_olive_F","20Rnd_762x51_Mag"]
];

// select from the array
_weapon = _weaponList call BIS_fnc_selectRandom;
_weaponMg = _weaponListMg call BIS_fnc_selectRandom;
_weaponGl = _weaponListGl call BIS_fnc_selectRandom;

//Création des markers
//Sentinelles camp
spawn_S01 = ["spawn_S01",[24654.3,23183.1],"colorOPFOR","ELLIPSE",0] call LM_fnc_markerCreation;
spawn_S02 = ["spawn_S02",[24642,23158.3],"colorOPFOR","ELLIPSE",0] call LM_fnc_spawnCreation;


//Création des groupes
//Sentinelles camp
S01 = [getMarkerPos "spawn_S01", EAST, ["KICC_FUSILIER"],[],[],[0.1,0.4],[],[],183 ] call BIS_fnc_spawnGroup; 
S02 = [getMarkerPos "spawn_S02", EAST, ["KICC_FUSILIER","KICC_FUSILIER"],[[0,0,0],[1,1,0]],[],[0.1,0.4],[],[1,0.6],0 ] call BIS_fnc_spawnGroup;
{_x disableAI "MOVE"} forEach units S02; 

//Habillage des groupes
_allunits = units S01 + units S02;
{
switch ( typeOf _x) do {
	case ("KICC_FUSILIER") : {
		removeAllWeapons _x;
		removeAllItems _x;
		removeAllAssignedItems _x;
		removeUniform _x;
		removeVest _x;
		removeBackpack _x;
		removeHeadgear _x;
		removeGoggles _x;
		_x forceAddUniform (["U_I_C_Soldier_Bandit_2_F","U_I_C_Soldier_Bandit_3_F","U_C_WorkerCoveralls","U_C_Man_casual_3_F","U_BG_Guerrilla_6_1","U_C_Poor_1","U_BG_Guerilla2_2","U_BG_Guerilla2_1","U_BG_Guerilla2_3","U_BG_Guerilla3_1","U_C_HunterBody_grn","U_I_C_Soldier_Para_1_F","U_I_C_Soldier_Para_2_F","U_I_C_Soldier_Para_3_F","U_I_C_Soldier_Para_4_F","U_I_C_Soldier_Camo_F","U_BG_leader","U_BG_Guerilla1_1"] call BIS_fnc_selectRandom);
		_x addVest (["V_PlateCarrier1_blk","V_PlateCarrier1_rgr_noflag_F","V_PlateCarrier1_tna_F","V_Chestrig_blk","V_Chestrig_rgr","V_Chestrig_khk","V_Chestrig_oli","V_PlateCarrierIA1_dgtl","V_HarnessOGL_brn","V_HarnessOGL_ghex_F","V_HarnessO_brn","V_HarnessO_ghex_F","V_HarnessO_gry","V_Rangemaster_belt","V_TacVestIR_blk","V_BandollierB_blk","V_BandollierB_cbr","V_BandollierB_ghex_F","V_BandollierB_rgr","V_BandollierB_khk","V_BandollierB_oli","V_TacChestrig_cbr_F","V_TacChestrig_grn_F","V_TacChestrig_oli_F","V_Tacblk","V_Tacbrn","V_Taccamo","V_Tackhk","V_Tacoli","V_I_G_resistanceLeader_F"] call BIS_fnc_selectRandom);
		_x addHeadgear (["H_Cap_red","H_Cap_blu","H_Cap_oli","H_Cap_headphones","H_Cap_tan","H_Cap_blk","H_Cap_brn_SPECOPS","H_Cap_blk_Raven","H_Cap_oli_hs","H_MilCap_ocamo","H_MilCap_mcamo","H_MilCap_oucamo","H_MilCap_rucamo","H_MilCap_gry","H_MilCap_dgtl","H_MilCap_blue","H_Bandanna_khk","H_Bandanna_khk_hs","H_Bandanna_cbr","H_Bandanna_gry","H_Shemag_khk","H_Shemag_tan","H_Shemag_olive","H_Shemag_olive_hs","H_ShemagOpen_khk","H_ShemagOpen_tan","H_Beret_blk","H_Beret_grn","H_Beret_ocamo","H_Watchcap_blk","H_Watchcap_cbr","H_Watchcap_khk","H_Watchcap_camo","H_Watchcap_sgg","H_TurbanO_blk"] call BIS_fnc_selectRandom);
		_x addGoggles (["G_Balaclava_blk","G_Balaclava_oli","G_Bandanna_blk","G_Bandanna_oli","G_Aviator","G_Spectacles","G_Squares_Tinted","G_Squares","G_Squares","G_Shades_Blue","G_Shades_Red","G_Shades_Green","G_Shades_Red","G_Sport_BlackWhite","G_Sport_Blackyellow","G_Sport_Checkered","G_Sport_Greenblack","G_Sport_Red"] call BIS_fnc_selectRandom);
		_x addItemToVest "MiniGrenade";
		_x addItemToVest "MiniGrenade";
		_x addItemToVest "Chemlight_blue";		
		for "_i" from 0 to 6 do {_x addMagazine (_weapon select 1); };
		_x addWeapon (_weapon select 0);
		for "_i" from 1 to 2 do {_x addItemToVest "16Rnd_9x21_Mag";};
		_x addWeapon "hgun_Rook40_F";
		_x addPrimaryWeaponItem "acc_flashlight";
		};
};
}forEach _allunits;
};

 

And so I would like to keep AI spawn in one file, and AI loadout in another file.

I hope this bit of code isn't too messy. In order to mix Ai spawn and custom loadout I picked some ideas from Larrow --> here .

 

If anyone have any clue how to make this happen, it would be very nice, I've made several missions with guerilla oriented faction, editing every unit manually, and I feel I could save so much time with a working code/function like this !

Thanks in advance !

 

Share this post


Link to post
Share on other sites

After spawning the units you can do this 

[(units S01 + units S02)] call XXX_fnc_randomLoadout; // replace XXX by the tag you used in functions.h

And creating a file : fn_randomLoadout.sqf  which will look like this 

params [["_units",[]]];

if(count _units isEqualTo 0) exitWith {};

/*
	todo : weapon/headgear/goggles/uniform/vest/backpack list
*/

{
	// todo : select random stuff from lists above
} foreach _units;

 

Share this post


Link to post
Share on other sites

Thank you for your reply Xjoker_ !

 

Yeah, creating a function out of this is probably the best thing to do ! I will definitely do that !

But I forgot to explain that some of my units, according to their class, should pick specific weapons among an array. In the bit of code you wrote, I miss this idea of if "KICC_RIFLEMAN", then select randomly in Rifleman stuff, if "KICC_MACHINEGUNNER", then select randomly in MG stuff... to get me on the right track, and my poor knowledge won't help me.

In my first code, there was this (I don't understand how it works, I just copied it from another codes from far more talented people than me) :

 

switch ( typeOf _x) do {
	case ("KICC_RIFLEMAN") : {
    
    give this 
    give that
    etc...
    
    };
    
    case ("KICC_MACHINEGUNNER") : {
    
    give this 
    give that
    etc...
    
    };
    };

Thanks again for your time !

 

Share this post


Link to post
Share on other sites

Wouldn't it be easier to simply build their loadouts in the arsenal, export them as sqf files and then load those randomly by picking the filenames from an array?

Share this post


Link to post
Share on other sites

Thanks Tajin for your reply !

Well, I guess it would be a bit easier, but not as much random as the kind of function I had in mind. And maybe a lot more work, especially because I also use external mods, and if some classnames of some, let's say, uniform changes, it's a pain in the a** to search and replace all the classnames in all the sqf files. With my function, I only have to write it once. But yes, I swear, if I fail to write and use my function, I will do that. (I say "my function" but obviously I take no credit for that, I'm unable to properly write a function by myself !)

Share this post


Link to post
Share on other sites
params [["_units",[]]];

if(count _units isEqualTo 0) exitWith {};

// Here, you define the loadout for each class
_rifleman = [
	["classHead1"], // headgears
	["classG1"], // goggles
	["classU1"], // uniform
	["classV1"], // vest
	["classBP1"], // backpack
	[["classWeapon1","classMagWeapon1"],["classWeapon2","classMagWeapon2"]], // primary weapons
	[["classWeapon1","classMagWeapon1"],["classWeapon2","classMagWeapon2"]] 	// handguns
];

_machineGunner = [
	["classHead1"], // headgears
	["classG1"], // goggles
	["classU1"], // uniform
	["classV1"], // vest
	["classBP1"], // backpack
	[["classWeapon1","classMagWeapon1"],["classWeapon2","classMagWeapon2"]], // primary weapons
	[["classWeapon1","classMagWeapon1"],["classWeapon2","classMagWeapon2"]] 	// handguns
];

{
	// Now you get the right array with the class
	_loadout = switch (typeof _x) do {
		case "KICC_RIFLEMAN": {
			_rifleman
		};	
		case "KICC_MACHINEGUNNER": {
			_machineGunner
		};
		default {[]};
	};

	// And then you pick random items from the array (they all have the same structure)
	_x addHeadgear (selectRandom (_loadout select 0)); // select 0 = headgear
	_x addGoggles (selectRandom (_loadout select 1)); // select 1 = goggles
	_x forceAddUniform (selectRandom (_loadout select 2)); // select 2 = uniform
	_x addVest (selectRandom (_loadout select 3)); // select 3 = vest
	_x addBackpack (selectRandom (_loadout select 4)); // select 4 = backpack
	_weapon = (selectRandom (_loadout select 5)); // select 5 = primary weapon
	_x addWeapon (_weapon select 0); // weapon select 0 = weapon's classname
	for "_i" from 1 to 4 do {_x addMagazine (_weapon select 1)}; // weapon select 1 = weapon's mag classname
	_handgun = (selectRandom (_loadout select 6)); // select 6 = handgun
	_x addWeapon (_handgun select 0); // handgun select 0 = handgun's classname
	for "_i" from 1 to 4 do {_x addMagazine (_handgun select 1)}; // handgun select 1 = handgun's mag classname

} foreach _units;


 

Share this post


Link to post
Share on other sites

Many many thanks to you Xjoker_ ! It works like a charm !

 

And I went a bit deeper in the comprehension of SQF syntax, thanks to your code !

I just added something like removeBackpack _x; right after your comment in the last paragraph, otherwise my unit spawned with his original backpack at his feet.

 

Thanks again !

 

  • Like 1

Share this post


Link to post
Share on other sites

This is much simpler

That way works but this is simpler and it works with so little text editing.

This is in your description.ext file

respawnTemplates[] = {"MenuInventory","MenuPosition"};

 

This is in your initplayerlocal.sqf file

[player, [missionnamespace, "virtualinventory"]] call Bis_fnc_saveinventory;

 

This is in your onplayerrespawn.sqf

[player, [missionnamespace, "virtualinventory"]] call Bis_fnc_loadinventory;

 

You make sure you click save loadout in the multiplayer section of you missions attributes drop down while editing. Place soldiers on the battlefield, edit their loadout in arsenal, save it or not in arsenal, I save so they can be reused. Save the scenario after leaving arsenal and you are done creating loadouts. If you go back and change the loadout or make even more loadouts to choose from make sure you save. Those loadouts are now saved in the scenario as long as those files above are in your mission folder.

 

You don't even have to care what the soldier started out as when you placed them. After editing his loadout double click him and in the role portion of his attributes you can put a name or even a fairly long description of his loadout so people know what they are getting when they choose it in the lobby.

 

It will throw an error that is meaningless, I think it is because the menu inventory has no other inventories to choose from and the inventory shown is wrong. It doesn't matter you've named or described the the loadout in the role slot of his attributes.

 

I got most of this from one of SayUnkl's videos on youtube.

 

And now I link to my new problem. Vehicle respawn module problem.

Share this post


Link to post
Share on other sites

That way I posted will work but you have to go to the lobby to change roles and loadouts, not a good fix, this works but its a little more work. Posted from another thread.

 

FOR MORONS LIKE ME

Now I've done this which like always has much borrowed stuff in it from those who really know how to do this.

The first file below is your init.sqf file. You can add more than just west1, west2, resistance1 and resistance2 as you need. This is my test scenario so it only has 4. Always post 2 or more  loadouts or other stuff in examples so morons like me can see the structure better. Don't assume we are all gonna learn to write the stuff you do, or can learn to or have time to. I looked over several of the vehicle respawn scripts and I think, did that take a week to write or a month.

 

I always set all the other player respawn stuff in the editor, like delay. Someone told me that respawn on start was a good idea so I did it.

 

respawnOnStart = 1;

[west, "WEST1"] call BIS_fnc_addRespawnInventory;
[west, "WEST2"] call BIS_fnc_addRespawnInventory;
[resistance, "resistance1"] call BIS_fnc_addRespawnInventory;
[resistance, "resistance2"] call BIS_fnc_addRespawnInventory;

This is the one that really needs 2 or more examples, loadouts and stuff in the description.ext file. Those calls in the above init.sqf file will load these inventories. This is with WWII mods installed so you will have to change the weapons and mags. Use whatever you want for the display names. I figure you know how to export the loadout you make out of the arsenal but you cannot paste it in here, it won't work. You have to paste into a text file and then copy and paste individual pieces into this. It does not take as long as you think it might. What I've done is just a template for someone to use. I put this one in a spoiler, which I hope works, this forum has no preview.

 

Spoiler

respawnTemplateswest[] = {"MenuInventory","MenuPosition"};
respawnTemplatesresistance[] = {"MenuInventory","MenuPosition"};
class CfgRoles
{
class west1
{
displayName = "tanker";
};
class west2
{
displayName = "rifleman";
};
class resistance1
{
displayName = "rifleman";
};
class resistance2
{
displayName = "tanker";
};
};


class CfgRespawnInventory
{
class west1
{
displayName = "tanker"; // Name visible in the menu
role = "west1";
// Loadout definition, uses same entries as CfgVehicles classes
weapons[] = {
"LIB_M1908"
};
magazines[] = {
"LIB_8Rnd_9x19_P08",
"LIB_8Rnd_9x19_P08",
"LIB_8Rnd_9x19_P08",
"LIB_8Rnd_9x19_P08",
"LIB_8Rnd_9x19_P08",
"LIB_8Rnd_9x19_P08",
"LIB_8Rnd_9x19_P08",
"LIB_m39",
"fow_e_m24",
"fow_e_m24"
};
items[] = {
"FirstAidKit",
"FirstAidKit",
"toolkit"

};
linkedItems[] = {
"V_LIB_GER_TankPrivateBelt",
"H_LIB_GER_TankPrivateCap",
"ItemMap",
"ItemCompass",
"ItemWatch"
};
backpack = "B_LIB_GER_CowBackpack_04";
uniformClass = "U_LIB_GER_Tank_crew_private";
};

class west2
{
displayName = "rifleman"; // Name visible in the menu
role = "west2";
// Loadout definition, uses same entries as CfgVehicles classes
weapons[] = {
"LIB_G43"
};
magazines[] = {
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_10Rnd_792x57",
"LIB_shg24",
"LIB_shg24",
"LIB_shg24"
};
items[] = {
"FirstAidKit",
"FirstAidKit"
};
linkedItems[] = {
"V_LIB_GER_VestG43",
"H_LIB_GER_Cap",
"ItemMap",
"ItemCompass",
"ItemWatch"
};
uniformClass = "U_LIB_GER_Oberschutze";
backpack = "B_LIB_GER_A_frame";
};


class resistance1
{
displayName = "rifleman"; // Name visible in the menu
role = "resistance1";
// Loadout definition, uses same entries as CfgVehicles classes
weapons[] = {
"fow_w_m1_garand",
"LIB_Binocular_SU"
};
magazines[] = {
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_8Rnd_762x63",
"LIB_US_Mk_2",
"LIB_US_Mk_2",
"LIB_US_Mk_2",
"LIB_US_Mk_2",
"LIB_US_Mk_2"
};
items[] = {
"FirstAidKit",
"FirstAidKit"
};
linkedItems[] = {
"fow_v_us_garand",
"fow_h_us_m1",
"ItemMap",
"ItemCompass",
"ItemWatch"
};
uniformClass = "U_LIB_CIV_Functionary_2";
backpack = "B_LIB_US_RocketBag_Vide";
};


class resistance2
{
displayName = "tanker"; // Name visible in the menu
role = "resistance2";
// Loadout definition, uses same entries as CfgVehicles classes
weapons[] = {
"LIB_Colt_M1911",
"LIB_Binocular_SU"
};
magazines[] = {
"LIB_7Rnd_45ACP",
"LIB_7Rnd_45ACP",
"LIB_7Rnd_45ACP",
"LIB_7Rnd_45ACP",
"LIB_7Rnd_45ACP",
"LIB_7Rnd_45ACP",
"LIB_7Rnd_45ACP",
"LIB_US_Mk_2",
"LIB_US_Mk_2",
"LIB_US_Mk_2"
};
items[] = {
"FirstAidKit",
"FirstAidKit"
};
linkedItems[] = {
"V_LIB_US_Vest_45",
"H_LIB_US_Helmet_Tank_AO",
"ItemMap",
"ItemCompass",
"ItemWatch"
};
uniformClass = "U_LIB_USA_NCO_Crew2ndADVbPbCptM1911";
backpack = "B_LIB_USA_Backpack_Vide";
};
};

Notice I used functionary clothes on one of them and loaded Japanese weapons, that for some reason he can't use, on another to make sure the game was loading the loadout out of the description.ext file and not using what I left in the editor.

 

Resistance is the side the US is on in the WWII mods, I don't know about the other mods. Anyway I kept getting errors because I tried independent and guerrilla, neither work in these 2 files for me. In other places independent works, independent is how it is listed in the editor but not in these files.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×