Jump to content
  • 0

Randomizing loadouts


BetterDeadThanZed

Question

I'm trying to randomize the player loadouts when they spawn new or die and respawn. In the init.sqf I have added this:

primary_fnc_selectRandom = {
    _this select (floor random (count _this))
};
_primary = ["M16A2","M16A4","M4A1","Sa58P_EP1","Sa58V_EP1","AKS_74_U","AK_47_M","AK_74","FN_FAL","Winchester1866","MR43","M1014","Remington870_lamp","LeeEnfield","Saiga12K","huntingrifle"] call primary_fnc_selectRandom;

Below that I have this:

DefaultWeapons = ["ItemMap",_primary];

This works to give the player a random primary weapon from that list, but the problem is that they have no ammo. Is there a way to tell the server to give the player the ammo needed for that weapon? I could just make it so all the weapons that are in the list use the same ammo but that would be boring and would be a bit restrictive. I also don't want specific random loadouts, where if you get primary weapon "A", then you also get secondary weapon "B". I want it to be truely random. I've also created arrays like that for secondary weapons and food and drinks.

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

From WAI

find_suitable_ammunition = {

	private["_weapon","_result","_ammoArray"];

	_result 	= false;
	_weapon 	= _this;
	_ammoArray 	= getArray (configFile >> "cfgWeapons" >> _weapon >> "magazines");

	if (count _ammoArray > 0) then {
		_result = _ammoArray select 0;
	};

	_result

};
_primary = ["M16A2","M16A4","M4A1","Sa58P_EP1","Sa58V_EP1","AKS_74_U","AK_47_M","AK_74","FN_FAL","Winchester1866","MR43","M1014","Remington870_lamp","LeeEnfield","Saiga12K","huntingrifle"] call BIS_fnc_selectRandom;

_ammo = _primary call find_suitable_ammunition;
DefaultMagazines = ["ItemBandage","ItemPainkiller",_ammo,_ammo,_ammo]; 

might work, untesed

Link to comment
Share on other sites

  • 0
RandomPrimary = {
	private ["_wArray","_select","_amArray"];

	_wArray = [
	["M16A2","30Rnd_556x45_Stanag"],
	["M16A4","30Rnd_556x45_Stanag"],
	["M4A1","30Rnd_556x45_Stanag"],
	["Sa58P_EP1","30Rnd_762x39_SA58"], // listed twice?
	["Sa58V_EP1","30Rnd_762x39_SA58"],
	["AKS_74_U","30Rnd_545x39_AK"],
	["AK_47_M","30Rnd_762x39_AK47"],
	["AK_74","30Rnd_545x39_AK"],
	["FN_FAL","20Rnd_762x51_FNFAL"],
	["Winchester1866","15Rnd_W1866_Slug"],
	["MR43","2Rnd_shotgun_74Slug"],
	["M1014","8Rnd_B_Beneli_74Slug"],
	["Remington870_lamp","8Rnd_B_Beneli_74Slug"],
	["LeeEnfield","10x_303"],
	["Saiga12K","8Rnd_B_Saiga12_74Slug"],
	["huntingrifle","5x_22_LR_17_HMR"]
	]:
	
	_select = _wArray select floor(random(count _wArray));
	
	from "_i" from 0 to 4 do {
		
		player addMagazine (_select select 1);
		
	};
	
	player addWeapon (_select select 0);
};

You could also do this but then you'd not use the defaultweapon and magazine command

Link to comment
Share on other sites

  • 0

Defent, how would I add the weapon to the inventory?

DefaultWeapons = ["ItemMap",_wpArray];

Doesn't seem to work. What should go in place of "_wpArray".

RandomPrimary = {
	private ["_wpArray","_slct"];
	
	_wpArray = [
	"M16A2",
	"M16A4",
	"M4A1",
	"Sa58P_EP1",
	"Sa58V_EP1",
	"AKS_74_U",
	"AK_47_M",
	"AK_74",
	"FN_FAL",
	"Winchester1866",
	"MR43",
	"M1014",
	"Remington870_lamp",
	"LeeEnfield",
	"Saiga12K",
	"huntingrifle"
	];
	
	_slct = _wpArray select floor(random(count _wpArray));
	
	[_slct] call AddAmmo;
};

addAmmo = {
private ["_addthings","_amArray"];
	_addThings = _this select 0;
	_amArray = getArray (configFile >> "cfgWeapons" >> _addThings >> "magazines");
	for "_i" from 0 to 4 do 
	{
		player addMagazine (_amArray select 0);
	};
}; 

This randoms a weapon for you. After that you could do

_stuff = call RandomPrimary;
DefaultWeapons = ["ItemMap",_stuff];


This should circumvent the need for default magazines, ive not tested it though.

 

Sorry for the edits, keep trying to fix it :)

Link to comment
Share on other sites

  • 0

I am getting this error after putting the above code in my init.sqf:

22:27:25 Error in expression < = getArray (configFile >> "cfgWeapons" >> _wpArray >> "magazines");
for "_i" fr>
22:27:25   Error position: <>> _wpArray >> "magazines");
for "_i" fr>
22:27:25   Error >>: Type Array, expected String
Link to comment
Share on other sites

  • 0
RandomPrimary = {
	private ["_wpArray","_slct","_amArray"];
	
	_wpArray = [
	"AKM_Epoch",
	"MultiGun"
	];
	
	// select from the array
	_slct = _wpArray select floor(random(count _wpArray));
	
	_amArray = getArray (configFile >> "cfgWeapons" >> _slct >> "magazines");
	
	
	// add Weapon and ammo
	player addWeapon _slct;
	
	for "_i" from 0 to 4 do 
	{
		player addMagazine (_amArray select 0);
	};
};

This works, I tested it in arma 3, just change the array of weapons to the arma 2 weapons.

 

Then do 

_things = call RandomPrimary;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...