Jump to content
  • 0

Static Crates Random loot


Cyrus

Question

Im looking for an easy, effective way to randomize loot (weapons, ammo, toolbelt items, food, meds and building supplies) in static crate. I have a placed crate already and populated with stuff but i would like to have this random on spawn. Also i would like to know how to have this crate stay for 2 hours then destroy and respawn 15 min later. This is what my customLootCrate.sqf looks like :

  Reveal hidden contents

 

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Setup arrays and pick a random item from it. You can use the BIS_fnc_selectRandom function to do that: https://community.bistudio.com/wiki/BIS_fnc_selectRandom

_someWeaponArray = [
	"DMR_DZ",
	"M24_des_EP1",
	"FNFAL_DZ",
	"Mk48_CCO_DZ",
	"M240_DZ",
	"G17_FL_DZ",
	"M9_SD_DZ"
];

//Pick 1 random item from it
_randomWeapon = _someWeaponArray call BIS_fnc_selectRandom;

//Optionally remove it from the array afterwards
_someWeaponArray = _someWeaponArray - [_randomWeapon];

 

Link to comment
Share on other sites

  • 0
  On 1/22/2018 at 3:27 PM, DAmNRelentless said:

Setup arrays and pick a random item from it. You can use the BIS_fnc_selectRandom function to do that: https://community.bistudio.com/wiki/BIS_fnc_selectRandom

_someWeaponArray = [
	"DMR_DZ",
	"M24_des_EP1",
	"FNFAL_DZ",
	"Mk48_CCO_DZ",
	"M240_DZ",
	"G17_FL_DZ",
	"M9_SD_DZ"
];

//Pick 1 random item from it
_randomWeapon = _someWeaponArray call BIS_fnc_selectRandom;

//Optionally remove it from the array afterwards
_someWeaponArray = _someWeaponArray - [_randomWeapon];

 

Expand  

@DAmNRelentless Thanks for the reply. That makes sense. for arguments sake if i want to populate the crate with multiple random items from the same array to i just specify the amount like this? :

_randomWeapon = [_someWeaponArray,10] call BIS_fnc_selectRandom;

Essentially requesting 10 random weapons from the array?

Link to comment
Share on other sites

  • 0

@Cyrus I don't think that would work since it's not matching the function's syntax anymore. But due to the fact that different amounts of items are stored in a array as well, you could pick a random array.

_someWeaponArray = [
	["DMR_DZ",2],
	["M24_des_EP1,4]",
	["FNFAL_DZ",2],
	["Mk48_CCO_DZ",1],
	["M240_DZ,1"],
	["G17_FL_DZ",5],
	["M9_SD_DZ",5]
];

//Pick 1 random item array from it format: ["weapon",amount]
//Keep in mind that it's saved as array this time
_randomWeapon = _someWeaponArray call BIS_fnc_selectRandom;

//Optionally remove it from the array afterwards
//You don't need to set it as array now. Since it is already an array, you can just do
_someWeaponArray = _someWeaponArray - _randomWeapon;

//Adding the item to the crate if it's already set up
//the variable is enough because it's already an array
_this addWeaponCargoGlobal _randomWeapon;

Now to not do this everytime, you could specify how many items from which arrays are picked. There can't be duplicate ones since the code is already removing the _randomWeapon from the origin array.

  Reveal hidden contents

 

Link to comment
Share on other sites

  • 0
  On 1/22/2018 at 7:20 PM, DAmNRelentless said:

@Cyrus I don't think that would work since it's not matching the function's syntax anymore. But due to the fact that different amounts of items are stored in a array as well, you could pick a random array.

_someWeaponArray = [
	["DMR_DZ",2],
	["M24_des_EP1,4]",
	["FNFAL_DZ",2],
	["Mk48_CCO_DZ",1],
	["M240_DZ,1"],
	["G17_FL_DZ",5],
	["M9_SD_DZ",5]
];

//Pick 1 random item array from it format: ["weapon",amount]
//Keep in mind that it's saved as array this time
_randomWeapon = _someWeaponArray call BIS_fnc_selectRandom;

//Optionally remove it from the array afterwards
//You don't need to set it as array now. Since it is already an array, you can just do
_someWeaponArray = _someWeaponArray - _randomWeapon;

//Adding the item to the crate if it's already set up
//the variable is enough because it's already an array
_this addWeaponCargoGlobal _randomWeapon;

Now to not do this everytime, you could specify how many items from which arrays are picked. There can't be duplicate ones since the code is already removing the _randomWeapon from the origin array.

  Reveal hidden contents

 

Expand  

@DAmNRelentless Thank you, logically that makes a lot more sense. I will play around with this method and see what i come up with.

 

EDIT : for the sake of argument, pairing weapons with their respective ammo would not work seeing as the _this addWeaponCargoGlobal would require a weapon and _this addMagazineCargoGlobal would require a magazine? Something like this? 

_weaponAmmoArray =
		  [
		  [["BAF_LRR_scoped",2],["5Rnd_86x70_L115A1", 20]],
		  [["DMR_DZ",1],["20Rnd_762x51_DMR",20]],
		  [["FN_FAL_ANPVS4_DZE",2],["20Rnd_762x51_FNFAL",20]],
		  [["Mk48_CCO_DZ",2],["100Rnd_762x54_PK",20]],
		  [["M240_DZ",2],["100Rnd_762x51_M240",20]],
		  [["G17_FL_DZ",2],["17Rnd_9x19_glock17",20]],
		  [["M9_SD_DZ",2],["15Rnd_9x19_M9SD",20]]
		  ];
		  
		  _rngAmmoWeaponPairSelect    = _weaponAmmoArray call BIS_fnc_selectRandom;
		  _this addWeaponCargoGlobal _rngAmmoWeaponPairSelect;

The aim is to return a random weapon, with a random amount of its respective ammo?

Link to comment
Share on other sites

  • 0

That's fairly easy to do aswell. Returning a weapon works just like I mentioned before. To get its respective ammo, you can random select with a multidimensional array and store it into different variables. I guess by "random amount of its respective ammo" you mean an amount between 0 and the amount you set in your array.

  Reveal hidden contents

 

Link to comment
Share on other sites

  • 0
  On 1/22/2018 at 9:31 PM, DAmNRelentless said:

That's fairly easy to do aswell. Returning a weapon works just like I mentioned before. To get its respective ammo, you can random select with a multidimensional array and store it into different variables. I guess by "random amount of its respective ammo" you mean an amount between 0 and the amount you set in your array.

  Reveal hidden contents

 

Expand  

Very nice, I learn more everyday. this scripting is really versatile. BTW this is what i was looking at in the past couple of min. Would this work ? Instead of multiple iterations i use a loop with a counter?

_weaponsArray = [["BAF_LRR_scoped",2],["DMR_DZ",1],["FN_FAL_ANPVS4_DZE",2],["Mk48_CCO_DZ",2],["M240_DZ",2],["G17_FL_DZ",2],["M9_SD_DZ",2]]
		  _ammoArray	= [["20Rnd_762x51_DMR",20],["5Rnd_86x70_L115A1", 20],["20Rnd_762x51_FNFAL",20],["100Rnd_762x54_PK",20],["100Rnd_762x51_M240",20],["17Rnd_9x19_glock17",20],["15Rnd_9x19_M9SD",20]]
		  
		  
		  
		  _rngWeaponSelect = _weaponsArray call BIS_fnc_selectRandom;
		  
		  _rngAmmoSelec    = _ammoArray call BIS_fnc_selectRandom;
		  
		  _wepCount = 0;
		  
		  _ammoCount = 0;
		  
		  //Adding weapons to the crate with a loop statement
		  while {_wepCount != 7} do
			{
				_this addWeaponCargoGlobal _rngWeaponSelect;
				_wepCount = _Wepcount + 1
			}
		  
		  while {_ammoCount != 7} do
		  {
				_this addMagazineCargoGlobal _rngAmmoSelect;
				_ammoCount = _ammoCount + 1;
		  }

 

Link to comment
Share on other sites

  • 0

@DAmNRelentless I will definitely be using your code, i was just curious at the possibilities of generating randoms from arrays. I more familiar with python and C#. Probably why i find SQF interesting. With practice im learning to change my mindset in terms of more effecting coding essentially improving across the board. I really appreciate the help that you are offering though

Link to comment
Share on other sites

  • 0

Quick question.. When creating the crate this is the default script for it :

_this = createVehicle ["USSpecialWeaponsBox", [4434.3223, 10632.069, 0], [], 0, "CAN_COLLIDE"];

Can i change it to this, to tie in with your method?

_ammoCrate = createVehicle ["USSpecialWeaponsBox", [4434.3223, 10632.069, 0], [], 0, "CAN_COLLIDE"];

and then fill _ammoCrate by calling globals like this?

 


_buildArray   = [["ItemLockbox",2],["ItemPole",20],["ItemComboLock",2],["ItemGenerator",3],["ItemVault",2],["ItemCorrugated",20],["plot_pole_kit",2],["ItemWire",10,["ItemTankTrap",10],["ItemSandbag",10],["CinderBlocks",40],["MortarBucket",20]];

_rngBuildSelect  = _buildArray call BIS_fnc_selectRandom;

_ammoCrate addMagazineCargoGlobal _rngBuildSelect;	

 

Link to comment
Share on other sites

  • 0

Will you please have a look and see if this will do what I am trying to achieve? And if the syntax is correct? I'm only applying what I have learned from the info you have given me.

  Reveal hidden contents

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Discord

×
×
  • Create New...