Jump to content
Sign in to follow this  
Sneakers O'Toole

random items in ammobox

Recommended Posts

Hi,

I am trying to make an ammobox that adds my favourite items randomly. So i have just made a basic outline.

I made an initial array to return the type of weapon, ar, sniper, pistol, etc. Then a random choice for the weapons of that type, that are of my preference.

Is this the right way to set this up? I dont want spend hours to finish it, for someone to tell me it's a stupid way to do it.

//create an ammo box at player pos // will need to change the postion later
_cache_base1 = "GuerillaCacheBox_EP1" createVehicle (position player);

// remove all weapons and mags from ammobox
clearweaponcargo _cache_base1;
clearmagazinecargo _cache_base1;

//example from wiki = _bestShooter = [_rento, _ben, _trit] call BIS_fnc_selectRandom;
_weapon_SEL = [_ar_wep, _lmg_wep, _snip_wep, _pst_wep, _tws_wep] call BIS_fnc_selectRandom;

//debug info
hint format["returned array = %1",_weapon_sel];

//create a random number
_ar_sel = ceil (random 100);

//debug info
hint format["returned array = %1",_ar_sel];

if _weapon_SEL = _ar_wep then 

//example from "dutchy" script:
//if ((_rNumber < 100)&&(_rNumber > 92)) then { _ammobox addWeaponCargo ["Colt1911" ,1] };
if ((_ar_sel < 10) then { _cache_base1 addWeaponCargo ["RH_Scarh_sd_gl_eotech" ,1];
if ((_ar_sel < 10) then { _cache_base1 addMagazineCargo ["12Rnd_45cal_usp" ,25];

if ((_ar_sel < 20)&&(_ar_sel > 10)) then { _cache_base1 addWeaponCargo ["another ar weapon" ,1];
if ((_ar_sel < 20)&&(_ar_sel > 10)) then { _cache_base1 addMagazineCargo ["its mags" ,25];
//etc... for up to 10 ar weapons

if _weapon_SEL = _lmg_wep then 

//create a random number
_lmg_sel = ceil (random 100);

//debug info
hint format["returned array = %1",_lmg_sel];

if ((_lmg_sel < 10) then _cache_base1 addWeaponCargo ["RH_mk43eotech" ,1];
if ((_lmg_sel < 10) then _cache_base1 addMagazineCargo ["12Rnd_45cal_usp" ,5];

if ((_lmg_sel < 20)&&(_ar_sel > 10)) then _cache_base1 addWeaponCargo ["another lmg weapon" ,1];
if ((_lmg_sel < 20)&&(_ar_sel > 10)) then _cache_base1 addMagazineCargo ["its mags" ,5];
//etc... for up to 10 lmg weapons

Cheers.

Edited by SneakersO_Toole

Share this post


Link to post
Share on other sites

You need to check your syntax here and there. Things like:

if _weapon_SEL = _ar_wep then 

should be

if (_weapon_SEL == _ar_wep) then
{
    // your code here
};

Download Squint by sbsmac for error checking. The general idea looks okay though. Don't get disheartened, just fix it up, run it and you'll learn how to make it better as you go along.

EDIT: Oh, and you need the functions module on the map if you're using any of the BIS functions.

DOUBLE EDIT: For efficiency, you might want to check out switch (condition) do instead of lots of if (condition) then :)

Edited by Das Attorney

Share this post


Link to post
Share on other sites

switch-statement would be preffered (as said by panther & Das Attorney)

Don't use BIS_Fnc_selectRandom here if you want reliable results (it has a tendency to ignore the first and last selection of an array)

Check your syntax (as said previously).

Where is _rNumber defined? That isn't a hard-coded variable as far as I know so you have to define it yourself.

It's also kind of pointless to select a weapon and then make the whole thing dependent on numbers. I don't quite get you here.

A much simpler script would be something like this:

_ammobox = _this select 0;
_randomprimary = ["M16A2GL","M16A4_GL","M4A1","M4A1_AIM_SD_CAMO"];
_randommags = (floor(random 11)); //It's important to note that floor random ALWAYS rounds down. 11 will NEVER be the case.
_randselect = (floor(random 4));
clearWeaponCargo _ammobox;
clearMagazineCargo _ammobox;

switch (_randselect) do { // Switch-statement which uses the variable _randselect to select a case. Each case adds a different weapon to the ammobox.
case 0: 
{
_weapon = _randomprimary select 0; // select 0 simply selects the first entry ("M16A2GL") from _randomprimary's array.
_ammobox addMagazineCargo ["30Rnd_556x45_Stanag",_randommags]; // this adds a random amount of magazine (up to 10) of the appropriate type to the cargo space.
};
case 1:
{
_weapon = _randomprimary select 1;
_ammobox addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};
case 2:
{
_weapon = _randomprimary select 2;
_ammobox addMagazineCargo [30Rnd_556x45_Stanag"",_randommags];
};
case 3:
{
_weapon = _randomprimary select 3;
_ammobox addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

Note you'll have to pass the script the name of the ammobox you placed on the map.

Untested the above but should work.

Share this post


Link to post
Share on other sites

ok, thanks guys, lots of good info here.

thanks for the code, i didnt't know about switch, I will need to develop a concept of the term 'switch'.

Oh, 'rnumber' was just the var name from the example code i used for how to fulfil the syntax.

As for the point? Well it's like me saying to the game 'give me a gun that i have already told you i like, but I want it to be a surprise which gun it is.'

Thanks again.

Share this post


Link to post
Share on other sites
switch-statement would be preffered (as said by panther & Das Attorney)

A much simpler script would be something like this:

_ammobox = _this select 0;
_randomprimary = ["M16A2GL","M16A4_GL","M4A1","M4A1_AIM_SD_CAMO"];
_randommags = (floor(random 11)); //It's important to note that floor random ALWAYS rounds down. 11 will NEVER be the case.
_randselect = (floor(random 4));
clearWeaponCargo _ammobox;
clearMagazineCargo _ammobox;

switch (_randselect) do { // Switch-statement which uses the variable _randselect to select a case. Each case adds a different weapon to the ammobox.
case 0: 
{
_weapon = _randomprimary select 0; // select 0 simply selects the first entry ("M16A2GL") from _randomprimary's array.
_ammobox addMagazineCargo ["30Rnd_556x45_Stanag",_randommags]; // this adds a random amount of magazine (up to 10) of the appropriate type to the cargo space.
};
case 1:
{
_weapon = _randomprimary select 1;
_ammobox addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};
case 2:
{
_weapon = _randomprimary select 2;
_ammobox addMagazineCargo [30Rnd_556x45_Stanag"",_randommags];
};
case 3:
{
_weapon = _randomprimary select 3;
_ammobox addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

Note you'll have to pass the script the name of the ammobox you placed on the map.

Untested the above but should work.

I got really confused trying to change the functioning of my script to reflect your more streamlined and efficient script. So I made a botched Frankenstein's Monster with a switch for the weapon type selection, but 'if then' for the actual weapon selection. I just can't concieve of how to make it choose the class of weapon before it chooses the weapon itself, ie:

this is the flow i want to achieve:

STEP 1: choose a random weapon type: (pistol, assault rifle, sniper rifle, light machine gun, or any tws weapon) (this is just private variables for me to conceptualise flow. I could lump all weapons into 1 big array but as I am learning i want it set out easy to follow in bitesize chunks, and doing it this way will make it easier for adaptation later on.)

STEP 2: choose a random weapon from the selected type (there will be different numbers of choices in each group, so 1 global random variable won't work)

//create an ammo box at player pos, I will need to change the postion later
_cache_base1 = "GuerillaCacheBox_EP1" createVehicle (position player);

// remove all weapons and mags from ammobox
clearweaponcargo _cache_base1;
clearmagazinecargo _cache_base1;

_weap_typ = (floor(random 5)); 	//this will select the class of weapon I am to be given
//I want to distinguish the different types of weapons into ar's, snipers, pistols, etc.

_randommags = (floor(random 21));   //It's important to note that floor random ALWAYS rounds down. 11 will NEVER be the case.

switch (_weap_typ) do { 			// I want to distinguish the different types of weapons into ar's, snipers, pistols, etc.

case 0:								// AR weapons type
{
_pick_ar = (floor(random 101)); // i give each type its own random gen for different numbers of prefered weapons in each class, ie i might like 10 ar's but there is only 7 psitols i like 

if ((_ar_sel < 10) then { _cache_base1 addWeaponCargo ["RH_Scarh_sd_gl_eotech" ,1];
if ((_ar_sel < 10) then { _cache_base1 addMagazineCargo ["20rnd_762x51_B_SCAR",_randommags];

if ((_ar_sel < 20)&&(_ar_sel > 10)) then { _cache_base1 addWeaponCargo ["RH_acrglaim" ,1];
if ((_ar_sel < 20)&&(_ar_sel > 10)) then { _cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
//up to 10 types...
};

case 1:					  			// Pistol weapons type
{
_pick_pst = (floor(random 71));

if ((_ar_sel < 10) then { _cache_base1 addWeaponCargo ["some pistol" ,1];
if ((_ar_sel < 10) then { _cache_base1 addMagazineCargo ["its ammo",_randommags];

if ((_ar_sel < 20)&&(_ar_sel > 10)) then { _cache_base1 addWeaponCargo ["some pistol" ,1];
if ((_ar_sel < 20)&&(_ar_sel > 10)) then { _cache_base1 addMagazineCargo ["its ammo",_randommags];
//up to 7 types...
};

case 2:					  			// Sniper weapons type
{
};

case 3:					  			// LMG weapons type
{
};

case 4:					  			// TWS weapons type
{
};

I can see how your code works for 1 group of weapons in

_randomprimary = ["M16A2GL","M16A4_GL","M4A1","M4A1_AIM_SD_CAMO"];

But I just can't concieve of how to make it choose the class of weapon before it chooses the weapon itself.

I noticed the 'forEach ARRAY;' in that link but it would run for every var in the array, not just one.

Edited by SneakersO_Toole

Share this post


Link to post
Share on other sites

So I used an 'if then' to randomly choose the type of weapon, and a switch statement within the 'if then'.

Amazingly I get no error messages, but it doesn't work correctly either.

It just continuously spawns ammo boxes with nothing in them.

Why does it keep making ammo boxes? There is no loop, and why are they empty?

//create an ammo box at player pos, I will need to change the postion later
_cache_base1 = "GuerillaCacheBox_EP1" createVehicle (position player);

// remove all weapons and mags from ammobox
clearweaponcargo _cache_base1;
clearmagazinecargo _cache_base1;

_weap_typ = (floor(random 5)); 		//this will select the class of weapon I am to be given
_randommags = (floor(random 21)); 	//generate random number of mags

//debug
hint format["weapon type = %1",_weap_typ];
hint format["# of mags = %1",_randommags];

//START IF statement (pistols)
if (_weap_type == 0) then			//_weap_type 0 = pistol class
{

_pistol_sel = (floor(random 7));	//Selects the pistol - 7 possible choices
switch (_pistol_sel) do { 			// Switch-statement which uses the variable _pistol_sel to select a case.

case 0: 
{
_cache_base1 addWeaponCargo ["RH_uspm" ,1];
_cache_base1 addMagazineCargo ["12Rnd_45cal_usp",_randommags];
};

case 1: 
{
_cache_base1 addWeaponCargo ["RH_muzi" ,1];
_cache_base1 addMagazineCargo ["32Rnd_9x19_Muzi",_randommags];
};

case 2: 
{
_cache_base1 addWeaponCargo ["RH_m9csd" ,1];
_cache_base1 addMagazineCargo ["15Rnd_9x19_M9SD",_randommags];
};

case 3: 
{
_cache_base1 addWeaponCargo ["RH_Deagleg" ,1];
_cache_base1 addMagazineCargo ["7Rnd_50_AE",_randommags];
};

case 4: 
{
_cache_base1 addWeaponCargo ["RH_Deagles" ,1];
_cache_base1 addMagazineCargo ["7Rnd_50_AE",_randommags];
};

case 5: 
{
_cache_base1 addWeaponCargo ["RH_g18" ,1];
_cache_base1 addMagazineCargo ["33Rnd_9x19_g18",_randommags];
};

case 6: 
{
_cache_base1 addWeaponCargo ["RH_tec9" ,1];
_cache_base1 addMagazineCargo ["30Rnd_9x19_tec",_randommags];
};

exit;	
};
//END IF statement (pistols)


//START IF statement (Assault Rifles)
if (_weap_type == 1) then				//_weap_type 1 = Assault class
{

_ar_sel = (floor(random 30));			//Selects the AR weapon

switch (_ar_sel) do {

case 0: 
{
_cache_base1 addWeaponCargo ["RH_Scarh_sd_gl_eotech" ,1];
_cache_base1 addMagazineCargo ["20rnd_762x51_B_SCAR",_randommags];
};

case 1: 
{
_cache_base1 addWeaponCargo ["RH_acrglaim" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 2: 
{
_cache_base1 addWeaponCargo ["mcno_SCAR_H_CQC_CCO_WHITE" ,1];
_cache_base1 addMagazineCargo ["20Rnd_762x51_SB_SCAR",_randommags];
};

case 3: 
{
_cache_base1 addWeaponCargo ["mcno_SCAR_H_STD_EGLM_Spect_WHITE" ,1];
_cache_base1 addMagazineCargo ["20Rnd_762x51_B_SCAR",_randommags];
};

case 4: 
{
_cache_base1 addWeaponCargo ["mcno_SCAR_L_CQC_Holo_WHITE" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 5: 
{
_cache_base1 addWeaponCargo ["mcno_SCAR_L_STD_Mk4CQT_WHITE"	,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 6: 
{
_cache_base1 addWeaponCargo ["RH_ak102gl" ,1];
_cache_base1 addMagazineCargo ["RH_30Rnd_556x45_AK",_randommags];
};

case 7: 
{
_cache_base1 addWeaponCargo ["RH_m4ceotech" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 8: 
{
_cache_base1 addWeaponCargo ["RH_m4ctsdglacog" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 9: 
{
_cache_base1 addWeaponCargo ["RH_m4cmkeotech" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 10: 
{
_cache_base1 addWeaponCargo ["RH_m4cmkaim" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 11: 
{
_cache_base1 addWeaponCargo ["RH_m4ctsdeotech" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 12: 
{
_cache_base1 addWeaponCargo ["RH_mk14eotech" ,1];
_cache_base1 addMagazineCargo ["20Rnd_762x51_DMR",_randommags];
};

case 13: 
{
_cache_base1 addWeaponCargo ["RH_mk14sdaim" ,1];
_cache_base1 addMagazineCargo ["RH_20Rnd_762x51_SD",_randommags];
};

case 14: 
{
_cache_base1 addWeaponCargo ["RH_ScarAkbaim" ,1];
_cache_base1 addMagazineCargo ["30Rnd_762x39_AK47",_randommags];
};

case 15: 
{
_cache_base1 addWeaponCargo ["RH_ScarAkeotech" ,1];
_cache_base1 addMagazineCargo ["30Rnd_762x39_AK47",_randommags];
};

case 16: 
{
_cache_base1 addWeaponCargo ["RH_scarHb_sd_gl_eotech" ,1];
_cache_base1 addMagazineCargo ["20Rnd_762x51_SB_SCAR",_randommags];
};

case 17: 
{
_cache_base1 addWeaponCargo ["RH_Scarh_sd_gl_eotech" ,1];
_cache_base1 addMagazineCargo ["20Rnd_762x51_B_SCAR",_randommags];
};

case 18: 
{
_cache_base1 addWeaponCargo ["RH_scarLb_sd_gl_aim" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 19: 
{
_cache_base1 addWeaponCargo ["RH_m16a4gleotech" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 21: 
{
_cache_base1 addWeaponCargo ["RH_m16a4glaim" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 22: 
{
_cache_base1 addWeaponCargo ["RH_m4glaim" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 23: 
{
_cache_base1 addWeaponCargo ["RH_m4glaeotech" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 24: 
{
_cache_base1 addWeaponCargo ["RH_m4sbraim" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 25: 
{
_cache_base1 addWeaponCargo ["RH_m4sbreotech" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 26: 
{
_cache_base1 addWeaponCargo ["RH_hk417sdeotech" ,1];
_cache_base1 addMagazineCargo ["RH_20Rnd_762x51_SD_hk417",_randommags];
};

case 27: 
{
_cache_base1 addWeaponCargo ["RH_hk417sglaim" ,1];
_cache_base1 addMagazineCargo ["RH_20Rnd_762x51_hk417",_randommags];
};

case 28: 
{
_cache_base1 addWeaponCargo ["LEN_L119A1_EOT_PF" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

case 29: 
{
_cache_base1 addWeaponCargo ["LEN_L119A1_EOT_UGL_PF" ,1];
_cache_base1 addMagazineCargo ["30Rnd_556x45_Stanag",_randommags];
};

exit;	
};
//END IF statement (Assault Rifles)

//START IF statement (LMG)
if (_weap_type == 2) then			//_weap_type 2 = LMG class
{

_lmg_sel = (floor(random 5));		//Selects the LMG - 5 possible choices
switch (_lmg_sel) do { 				// Switch-statement which uses the variable _lmg_sel to select a case.

case 0: 
{
_cache_base1 addWeaponCargo ["Mcno_M249_m145_EP1_white" ,1];
_cache_base1 addMagazineCargo ["200Rnd_556x45_M249",_randommags];
};

case 1: 
{
_cache_base1 addWeaponCargo ["RH_m60e4eotech" ,1];
_cache_base1 addMagazineCargo ["100Rnd_762x51_M240" ,_randommags];
};

case 2: 
{
_cache_base1 addWeaponCargo [L110A1 ,1];
_cache_base1 addMagazineCargo ["200Rnd_556x45_M249",_randommags];
};

case 3: 
{
_cache_base1 addWeaponCargo [MG36 ,1];
_cache_base1 addMagazineCargo ["100Rnd_556x45_BetaCMag",_randommags];
};

case 4: 
{
_cache_base1 addWeaponCargo ["RH_M249" ,1];
_cache_base1 addMagazineCargo ["200Rnd_556x45_M249",_randommags];
};

exit;	
};
//END IF statement (LMG)


//START IF statement (sniper)
if (_weap_type == 3) then			//_weap_type 3 = sniper class
{

_sniper_sel = (floor(random 3));	//Selects the sniper - 3 possible choices
switch (_sniper_sel) do { 			// Switch-statement which uses the variable _sniper_sel to select a case.

case 0: 
{
_cache_base1 addWeaponCargo ["M110_NVG_EP1" ,1];
_cache_base1 addMagazineCargo ["20Rnd_762x51_B_SCAR",_randommags];
};

case 1: 
{
_cache_base1 addWeaponCargo ["mcno_SCAR_H_LNG_Sniper_WHITE" ,1];
_cache_base1 addMagazineCargo ["20Rnd_762x51_B_SCAR",_randommags];
};

case 2: 
{
_cache_base1 addWeaponCargo ["mcno_SCAR_H_LNG_Sniper_SD_WHITE" ,1];
_cache_base1 addMagazineCargo ["20Rnd_762x51_SB_SCAR",_randommags];
};

exit;	
};
//END IF statement (sniper)


//START IF statement (tws)
if (_weap_type == 4) then			//_weap_type 4 = tws class
{

_tws_sel = (floor(random 4));		//Selects the tws - x possible choices
switch (_tws_sel) do { 				// Switch-statement which uses the variable _tws_sel to select a case.

case 0: 
{
_cache_base1 addWeaponCargo ["MCNO_M110_TWS_EP1_WHITE" ,1];
_cache_base1 addMagazineCargo ["20Rnd_762x51_B_SCAR",_randommags];
};

case 1: 
{
_cache_base1 addWeaponCargo ["Mcno_m249_TWS_EP1_White" ,1];
_cache_base1 addMagazineCargo ["200Rnd_556x45_M249",_randommags];
};

case 2: 
{
_cache_base1 addWeaponCargo ["BAF_AS50_TWS" ,1];
_cache_base1 addMagazineCargo ["5Rnd_127x99_as50",_randommags];
};

case 3: 
{
_cache_base1 addWeaponCargo ["m107_TWS_EP1" ,1];
_cache_base1 addMagazineCargo ["10Rnd_127x99_M107",_randommags];
};

exit;	
};
//END IF statement (tws)

lol, this is probably the most ridiculous piece of code ever.:icon_redface::nuts:

Share this post


Link to post
Share on other sites

I tried it again just to see exactly how i executed it so i just ran it from a new mission with nothing else in it.

I run it from a trigger:

act: anybody

condition: this

on act: script = [] execVM "ran_weap.sqf";

Now it is not spamming ammoboxes. It does indeed make a random choice for

_weap_typ = (floor(random 5)); 		//this will select the class of weapon I am to be given
_randommags = (floor(random 21)); 	//generate random number of mags

But there is nothing in the box, tried 20+ times in a row. It is empty every single time.

so I added:

//debug
hintc format["pistol sel =%1", _pistol_sel];

below the if then statement for each weapon type. And i never get a hint. So I guess it is not executing the code within any of the if then statements.

---------- Post added at 15:05 ---------- Previous post was at 14:46 ----------

I had the wrong variable name inside the if then statement

weap_typ was incorrectly weap_type.

But it changed nothing. There is still nothing in the box, and it still does not execute the code within the if statements.:confused:

Share this post


Link to post
Share on other sites

Only thing I can think of is that the weapon names are wrong. Do you have the RH weapon modpack?

Share this post


Link to post
Share on other sites

take a look at my last post in this thread

http://forums.bistudio.com/showthread.php?134508-How-to-get-cargo-capacity-and-cost-weight-of-stuff-into-sqf

i use an array of weapons and ammo and spawn them into vehicles (just like your ammo box) BUT i use global commands addweaponcargoglobal and addmagazinecargoglobal so all units can access it and so it works when joining a dedicated server.

Share this post


Link to post
Share on other sites

I have script errors on the arma start cmdline

@eggbeast. Thanks I will look at that.

But I really need to understand why it is not processing anything after the 'if' statement. Surely there is an error with the if syntax!

I removed almost all of the code and check out how bizarre this is: (this is the ENTIRE FILE)

hint format["yadda yadda"];

//EVERYTHING ABOVE THIS LINE WORKS AS NORMAL
// if i type here:   uggedybuggedyboo I get an error. If i remove a { or a " I get an error.

if (_weap_typ == 0) then
{

hint format["this text is invisible"];	// THIS TEXT DOES NOT SHOW UP INGAME

uggedybuggedyboo			//obvious error here but no error message? NOTHING I DO HERE IS PROCESSED?

Surely the if syntax is wrong?

Share this post


Link to post
Share on other sites

Try changing from _weap_typ to _weaptyp (the MAIN variable)

Share this post


Link to post
Share on other sites

I tried a stripped down (but still meaningful) basic test version with the IF_THEN but without the SWITCH and it worked fine:

_weap_typ = (floor(random 1)); 		//FORCE _weap_typ to 0
_randommags = (floor(random 21)); 	

//debug
hint format["weapon type = %1, # of mags = %2,", _weap_typ,_randommags];

if (_weap_typ == 0) then
{

hint format["this text is invisible"];    // THIS DOES SHOW UP INGAME
_cache_base1 = "GuerillaCacheBox_EP1" createVehicle (position player);


};

I then tried the switch without the IF_THEN and that also worked fine.

_cache_base1 = "GuerillaCacheBox_EP1" createVehicle (position player);

clearweaponcargo _cache_base1;
clearmagazinecargo _cache_base1;

_weap_typ = (floor(random 1)); 		//FORCE _weap_typ to 0
_randommags = (floor(random 21)); 	

//debug
hint format["weapon type = %1, # of mags = %2,", _weap_typ,_randommags];

_pistol_sel = (floor(random 2));	//FORCE _pistol_sel to 0 or 1

//debug
//hintc format["pistol sel =%1", _pistol_sel];

switch (_pistol_sel) do { 			// Switch-statement which uses the variable _pistol_sel to select a case.
hintc format["pistol sel =%1", _pistol_sel];

case 0: 
{
_cache_base1 addWeaponCargo ["RH_uspm" ,1];
_cache_base1 addMagazineCargo ["12Rnd_45cal_usp",_randommags];
};

case 1: 
{
_cache_base1 addWeaponCargo ["RH_muzi" ,1];
_cache_base1 addMagazineCargo ["32Rnd_9x19_Muzi",_randommags];
};
//BOTH ABOVE CASES WORK FINE

};

I then simply replaced the code that was working fine within the _IF_THEN statement with the SWITCH code that was working fine without the IF_THEN.

And it didnt work. SO I guess you can't have a switch inside an if_then. I'll look for another way. Thanks for your responses.

Share this post


Link to post
Share on other sites
Why do you need to use switch inside of an if statement?

Technically it was to prevent unnecessary if-statements because originally he had like 20 weapon choices for each weapon category (pistols etc) which he processed with an if-statement each. I don't see why a switchstatement wouldn't work within an if-statement.

Share this post


Link to post
Share on other sites
@eggbeast. Thanks I will look at that.

do look, I use an "if then" to set the type and then a "switch" to set it with ammo and spawn it - it works perfectly so check your syntax against mine if it helps

Share this post


Link to post
Share on other sites

That seems very well done, and a large part is beyond my understanding. But from what I can see:

* you have if_then statements that define variables

* you have switch operations that contain if_then statements

But there appear to be no if_then statements that contain switch operations. It will take me some time to understand it better which helps me understand things more, so if I've got this right:

Your if_then defines a variable...

if (_vec isKindOf "Helicopter") then {_type=0};

...which is used by the switch to select a case.

Whereas my if_then contains a switch array...

if (_weap_typ == 0) then
{

switch (_pistol_sel) do
{

case 0: 
{
_cache_base1 addWeaponCargo ["RH_uspm" ,1];
_cache_base1 addMagazineCargo ["12Rnd_45cal_usp",_randommags];
};

case 1: 
{
_cache_base1 addWeaponCargo ["RH_muzi" ,1];
_cache_base1 addMagazineCargo ["32Rnd_9x19_Muzi",_randommags];
};
};

...which seems like it is just not viable. Especially when you consider that my switch array works fine when it is not contained within the if_then statement. And correspondingly, the if_then statement works fine when it does not contain the switch array. Any of what I say can be nonsense of course because I'm new to all this, but that is how it seems to me.

I made the switches for the weapon types into seperate files and am looking to call them somehow. So simply put: I am looking for a way to call 1, from a possible 5, switches. Is call something I could use? Do you call files or can you call sections of a script like in basic you have goto.

Share this post


Link to post
Share on other sites

Maybe a double-switchstatement? One for _weap_type which defines what content the ammoboxes have and one which defines _weap_type.

I guess that'll work out.

Share this post


Link to post
Share on other sites

I tried doing another switch statement, I think you meant someething else but I tried 5 switches within 1 switch 'inception' style :).

And I started the habit of indenting code and "{", "};" those things. Turns out, er... I missed the "};" from the if_then statements. :whistle:

I kinda feel like this:

oohhh.jpg

But also like this:

3dsmile9.gif

But mostly like this:

oohhh.jpg

Anyway, thanks for the help and suggestions.

Share this post


Link to post
Share on other sites

i don't think the siting is the problem

if (_weap_typ == 0) then
{

switch (_pistol_sel) do
{

case 0: 
   {
_cache_base1 addWeaponCargo ["RH_uspm" ,1];
_cache_base1 addMagazineCargo ["12Rnd_45cal_usp",_randommags];
   };

case 1: 
   {
_cache_base1 addWeaponCargo ["RH_muzi" ,1];
_cache_base1 addMagazineCargo ["32Rnd_9x19_Muzi",_randommags];
   };
};  

//you are missing a }; here, e.g.
};  

here is a script i developed in one of my missions which creates random ammo boxes around a target city and places into each of them some items with the correct ammo - it may help to plunder the logic

//Eggbeast loot spawning - called from BIS_EVO_Erec in Evo_erec.sqf serverside

/*
//////////////////
what do we need to do?
//////////////////

---Egg_evo_loot
Identify town location (send radio pos from erec) and find suitable buildings 

---init
Set weapon and ammo arrays
in the init - called in EGG_Evo_Loot

EGG_EVO_LootboxA 
EGG_EVO_LootboxB 
EGG_EVO_LootboxC 
EGG_EVO_LootboxD 
EGG_EVO_LootboxE 
EGG_EVO_LootboxF 
EGG_EVO_LootboxG
EGG_EVO_LootboxH

//backpacks
EGG_EVO_Kitarray0
//personal kit W
EGG_EVO_Kitarray1
//pistols W M
EGG_EVO_Kitarray2
//grenades etc M
EGG_EVO_Kitarray3
//rockets W M
EGG_EVO_Kitarray4
//machineguns
EGG_EVO_Kitarray5
//sniper
EGG_EVO_Kitarray6
//SMG
EGG_EVO_Kitarray7
//rifles
EGG_EVO_Kitarray8
//GL
EGG_EVO_Kitarray9

---spawnlootbox
randomly generate 1 box from each Lootbox array (A-G) for:
A-	pistols and ammo and personal items, map compass etc
B-	smgs and ammo
C-	launchers and ammo
D-	sniper rifles and ammo
E-	mixed bag inc GL
F-	rifles and carbines and ammo
G-	MGs and ammo
H-	satchels, grenades, and mines
fill box with items using kit arrays in init

---EGG_EVO_guardloot
Establish a guard unit for each crate.  When the last guard unit is killed, delete the box after 600s (10 mins)

might need to edit the bis_evo_fillinf to take a variable count of units

---EGG_EVO_deletelootbox 
when the city is clear, delete the ammo boxes

this is in the init

//in the init - called in EGG_Evo_Loot

EGG_current_boxes = []; 

EGG_EVO_LootboxA = ["USBasicAmmunitionBox","RUBasicAmmunitionBox","GuerillaCacheBox","LocalBasicAmmunitionBox","GuerillaCacheBox_EP1","TKBasicAmmunitionBox_EP1","UNBasicAmmunitionBox_EP1"];
EGG_EVO_LootboxB = ["USBasicWeaponsBox","RUBasicWeaponsBox","LocalBasicWeaponsBox","CZBasicWeapons_EP1","GERBasicWeapons_EP1","TKBasicWeapons_EP1","UNBasicWeapons_EP1"];
EGG_EVO_LootboxC = ["USLaunchersBox","RULaunchersBox","USLaunchers_EP1","TKLaunchers_EP1"];
EGG_EVO_LootboxD = ["USSpecialWeaponsBox","RUSpecialWeaponsBox","SpecialWeaponsBox","USSpecialWeapons_EP1","TKSpecialWeapons_EP1"];
EGG_EVO_LootboxE = ["USVehicleBox","RUVehicleBox","USVehicleBox_EP1","TKVehicleBox_EP1"];
EGG_EVO_LootboxF = ["Gunrack1","Gunrack2","GunrackUS_EP1","GunrackTK_EP1"];
EGG_EVO_LootboxG =["USOrdnanceBox","RUOrdnanceBox","TKOrdnanceBox_EP1"];
EGG_EVO_LootboxH = ["BAF_IEDBox"];

//backpacks
EGG_EVO_Kitarray0 = ["CZ_VestPouch_EP1","US_Assault_Pack_EP1","US_Backpack_EP1","BAF_AssaultPack_special","DE_Backpack_Specops_EP1","Tripod_Bag","M252_US_Bag_EP1","TOW_TriPod_US_Bag_EP1","M2HD_mini_TriPod_US_Bag_EP1","MK19_TriPod_US_Bag_EP1"];

//personal kit W
EGG_EVO_Kitarray1 =["ItemCompass","ItemGPS","ItemMap","ItemRadio","ItemWatch","NVGoggles","Binocular","Binocular_Vector","Laserdesignator"];

//pistols W M
EGG_EVO_Kitarray2 =["RH_m93r","RH_20Rnd_9x19_M93","RH_p226","RH_15Rnd_9x19_usp","RH_g18","RH_33Rnd_9x19_g18","RH_g19t","RH_17Rnd_9x19_g17","RH_mk2","RH_10Rnd_22LR_mk2","RH_mk22vsd","RH_8Rnd_9x19_Mksd","RH_uspsd","RH_15Rnd_9x19_uspsd","RH_m9sd","15Rnd_9x19_M9SD","RH_m1911sd","RH_8Rnd_45cal_m1911","RH_anac","RH_6Rnd_44_Mag","RH_bull","RH_6Rnd_44_Mag","RH_python","RH_6Rnd_357_Mag","RH_deagle","RH_7Rnd_50_AE","RH_pp2000p","30Rnd_9x19_MP5p","RH_mac10p","RH_9mm_32RND_pMag","RH_tec9","RH_30Rnd_9x19_tec","RH_muzi","RH_32Rnd_9x19_Muzi","RH_mp5kp","30Rnd_9x19_MP5p","RH_mp7p","RH_46x30mm_40RND_pMag","RH_vz61","RH_20Rnd_32cal_vz61","RH_tt33","RH_8Rnd_762_tt33","RH_pm","8Rnd_9x18_Makarov","RH_pmsd","8Rnd_9x18_MakarovSD","RH_aps","RH_20Rnd_9x18_aps","RH_apssd","RH_20Rnd_9x18_apssd","Sa61_EP1","20Rnd_B_765x17_Ball","glock17_EP1","17Rnd_9x19_glock17","UZI_EP1","30Rnd_9x19_UZI","UZI_SD_EP1","30Rnd_9x19_UZI_SD"];

//grenades etc M
EGG_EVO_Kitarray3 =["HandGrenade_East","MineE","pipebomb","HandGrenade_West","mine","BAF_L109A1_HE","Laserbatteries","SmokeShell","SmokeShellRed","SmokeShellOrange","BAF_ied_v1","BAF_ied_v2","BAF_ied_v3","BAF_ied_v4"];

//rockets W M
EGG_EVO_Kitarray4 =["Strela","Strela","Igla","Igla","RPG7V","OG7","RPG7V","PG7V","RPG7V","PG7VR","RPG18","RPG18","MetisLauncher","AT13","RPG7V","PG7VL","M136","M136","SMAW","SMAW_HEAA","SMAW","SMAW_HEDP","Stinger","Stinger","JAVELIN","JAVELIN","M47Launcher_EP1","Dragon_EP1","MAAWS","MAAWS_HEAT","MAAWS","MAAWS_HEDP","BAF_NLAW_Launcher","NLAW"];

//machineguns
EGG_EVO_Kitarray5 =["PK","100Rnd_762x54_PK","RPK_74","75Rnd_545x39_RPK","Pecheneg","100Rnd_762x54_PK","RH_rpk74m1p29","RH_45Rnd_545x39_mag","RH_rpk74m","RH_45Rnd_545x39_mag","RH_rpk47","RH_75Rnd_762x39_mag","BAF_L86A2_ACOG","30rnd_556x45_Stanag","MG36_camo","100Rnd_556x45_BetaCMag","M249_EP1","200Rnd_556x45_M249","M249_m145_EP1","200Rnd_556x45_M249","M249_TWS_EP1","200Rnd_556x45_M249","m8_SAW","100Rnd_556x45_BetaCMag","M240","100Rnd_762x51_M240","m240_scoped_EP1","100Rnd_762x51_M240","M60A4_EP1","100Rnd_762x51_M240","BAF_L110A1_Aim","200Rnd_556x45_M249","Mk_48_DES_EP1","100Rnd_762x51_M240","RH_M249pelcan","200Rnd_556x45_M249","RH_Mk48mod1","100Rnd_762x51_M240","RH_Mk48mod1acog","100Rnd_762x51_M240","RH_Mk48mod1elcan","100Rnd_762x51_M240","RH_M60E4_EOTECH","100Rnd_762x51_M240","RH_MK43_ACOG","100Rnd_762x51_M240","RH_MK43_ELCAN","100Rnd_762x51_M240","RH_XM8DSAW","100Rnd_556x45_BetaCMag","RH_m27aim","100Rnd_556x45_BetaCMag","RH_m27ceotech","100Rnd_556x45_BetaCMag"];

//sniper
EGG_EVO_Kitarray6 =["m8_tws_sd","30Rnd_556x45_G36SD","M24","5Rnd_762x51_M24","M4SPR","30Rnd_556x45_Stanag","M40A3","5Rnd_762x51_M24","DMR","20Rnd_762x51_DMR","M107","10Rnd_127x99_m107","M107_TWS_EP1","10Rnd_127x99_m107","M110_NVG_EP1","20Rnd_762x51_B_SCAR","M110_TWS_EP1","20Rnd_762x51_B_SCAR","SCAR_H_LNG_Sniper","20Rnd_762x51_B_SCAR","SCAR_H_LNG_Sniper_SD","20Rnd_762x51_SB_SCAR","BAF_AS50_scoped","10Rnd_127x99_m107","BAF_AS50_TWS","10Rnd_127x99_m107","BAF_LRR_scoped_W","5Rnd_86x70_L115A1","BAF_L85A2_RIS_CWS","30Rnd_556x45_Stanag","RH_m1ssp","20Rnd_762x51_DMR","RH_m1steot","20Rnd_762x51_DMR","RH_mk14ebrsp_sd","RH_20Rnd_762x51_SD","RH_m39emr","20Rnd_762x51_DMR","RH_mk12sd","30Rnd_556x45_StanagSD","RH_m21","20Rnd_762x51_DMR","RH_MK21A5SD","20Rnd_762x51_DMR","FN_FAL_ANPVS4","20Rnd_762x51_FNFAL","ksvk","5Rnd_127x108_KSVK","SVD_CAMO","10Rnd_762x54_SVD","VSS_vintorez","10Rnd_9x39_SP5_VSS","SVD_NSPU_EP1","10Rnd_762x54_SVD","RH_asvalsp","20Rnd_9x39_SP5_VSS","RH_svu","10Rnd_762x54_SVD","AKS_74_GOSHAWK","30Rnd_545x39_AK","AK_107_pso","30Rnd_545x39_AK","AKS_74_pso","30Rnd_545x39_AK","huntingrifle","5x_22_LR_17_HMR"];

//SMG
EGG_EVO_Kitarray7 =["RH_bizonsdk","64Rnd_9x19_SD_Bizon","bizon_silenced","64Rnd_9x19_SD_Bizon","AKS_74_U","30Rnd_545x39_AK","Saiga12K","8Rnd_B_Saiga12_74Slug","RH_asval","RH_20Rnd_9x39_val_mag","bizon_silenced","64Rnd_9x19_SD_Bizon","RH_asvalk","RH_20Rnd_9x39_val_mag","MP5SD","30Rnd_9x19_MP5SD","RH_HK53aim","30Rnd_556x45_Stanag","RH_mp5a5ris","30Rnd_9x19_MP5","RH_P90isd","RH_57x28mm_50RND_SD_Mag","RH_umpsdaim","RH_45ACP_25RND_SD_Mag","RH_krisssdeot","RH_45ACP_30RND_SD_Mag","RH_uzisd","RH_9mm_32RND_SD_Mag","RH_tmpsdaim","30Rnd_9x19_MP5SD","RH_mp7eot","RH_46x30mm_40RND_Mag","RH_mp7sdaim","RH_46x30mm_40RND_SD_Mag","M1014","8Rnd_B_Beneli_Pellets","AA12_PMC","20Rnd_B_AA12_HE","RH_m4sbraim","100Rnd_556x45_BetaCMag"];

//rifles
EGG_EVO_Kitarray8 =["Sa58V_CCO_EP1","30Rnd_762x39_SA58","LeeEnfield","10x_303","FN_FAL","20Rnd_762x51_FNFAL","AK_107_kobra","30Rnd_545x39_AK","RH_akmssd","RH_30Rnd_762x39_SDmag","RH_ak105sp","30Rnd_545x39_AK","RH_rk95sdaim","RH_30Rnd_762x39_SDmag","RH_SCARAKACOG","30Rnd_762x39_AK47","M16A2","100Rnd_556x45_BetaCMag","RH_m16a3cs","100Rnd_556x45_BetaCMag","M14_EP1","20Rnd_762x51_DMR","Scar_L_CQC_CCO_SD","30rnd_556x45_Stanag","SCAR_H_STD_TWS_SD","20Rnd_762x51_SB_SCAR","RH_ar10","RH_20Rnd_762x51_AR10","RH_MK14SDEOTECH","RH_20Rnd_762x51_SD_mk14","RH_sc2shd","20Rnd_762x51_DMR","RH_Mk18sdaim","30Rnd_556x45_StanagSD","RH_mk18t","30Rnd_556x45_Stanag","RH_m4sd","30Rnd_556x45_StanagSD"];

//GL
EGG_EVO_Kitarray9 =["RH_M4CMKEOTECH","30Rnd_556x45_Stanag ","RH_an94gl","30Rnd_545x39_AK","RH_aks74uptk","30Rnd_545x39_AKSD","RH_ak104gl","30Rnd_762x39_AK47","RH_ak105kgl","30Rnd_545x39_AK","AK_74_GL","30Rnd_545x39_AK","M79_EP1","1Rnd_HE_M203","Mk13_EP1","1Rnd_HE_M203","M32_EP1","6Rnd_HE_M203","RH_m16a3sgl","30Rnd_556x45_Stanag","RH_m16a4gleotech","30Rnd_556x45_Stanag","RH_M4sdgleotech_wdl","30Rnd_556x45_StanagSD","RH_mk18dcglacog","30Rnd_556x45_Stanag","RH_M4CTSDGLACOG_F","30Rnd_556x45_StanagSD","RH_SCARH_GL_SPECTERDR","20rnd_762x51_B_SCAR","SCAR_L_CQC_EGLM_Holo","30Rnd_556x45_Stanag","BAF_L85A2_UGL_Holo","30Rnd_556x45_Stanag","M4A3_CCO_EP1","30Rnd_556x45_Stanag","SCAR_H_STD_EGLM_Spect","20rnd_762x51_B_SCAR","SCAR_L_STD_EGLM_TWS","30Rnd_556x45_Stanag","RH_mp5a5eod","30Rnd_9x19_MP5","RH_mp5a5eodeot","30Rnd_9x19_MP5"];

*/


EGG_EVO_spawnlootbox =
{
_loottype = _this select 0;
_pos1 = _this select 1;

switch (_loottype) do
{
	case 0: //eqpt
	{
		_maxb = (count EGG_EVO_LootboxA);
		_rbox = floor random _maxb;
		_boxtype = EGG_EVO_LootboxA select _rbox;
		_maxk = (count EGG_EVO_Kitarray1);
		_rkitA = floor random _maxk;
		_weptype1 = EGG_EVO_Kitarray1 select _rkitA;
		_acrate = createVehicle [_boxtype, _pos1, [], 10, "NONE"];
		clearWeaponCargoGlobal _acrate;
		clearMagazineCargoGlobal _acrate;
		_acrate addWeaponCargoGlobal [_weptype1,1];	
	};
	case 1: //pistols
	{
		_maxb = (count EGG_EVO_LootboxA);
		_rbox = floor random _maxb;
		_boxtype = EGG_EVO_LootboxA select _rbox;
		_maxk = ((count EGG_EVO_Kitarray2)/2); 
//58 items in array 0,2,4...,54,56
//maxk returns 29
		_rkitA = ((floor random _maxk)*2);
		_rkitB = ((floor random _maxk)*2);
		_rkitC = ((floor random _maxk)*2);
		_weptype1 = EGG_EVO_Kitarray2 select (_rkitA);
		_ammotype1 = EGG_EVO_Kitarray2 select (_rkitA + 1);
		_weptype2 = EGG_EVO_Kitarray2 select (_rkitB);
		_ammotype2 = EGG_EVO_Kitarray2 select (_rkitB + 1);
		_ammotype3 = EGG_EVO_Kitarray2 select (_rkitC + 1);
		_acrate = createVehicle [_boxtype, _pos1, [], 10, "NONE"];
		clearWeaponCargoGlobal _acrate;
		clearMagazineCargoGlobal _acrate;
		_acrate addWeaponCargoGlobal [_weptype1,1];	
		_acrate addWeaponCargoGlobal [_weptype2,1];	
		_acrate addMagazineCargoGlobal [_ammotype1,6];	
		_acrate addMagazineCargoGlobal [_ammotype2,4];	
		_acrate addMagazineCargoGlobal [_ammotype3,5];	
	};
	case 2: //satchels and nades
	{
		_maxb = count EGG_EVO_LootboxH;
		_rbox = (floor random _maxb);
		_boxtype = EGG_EVO_LootboxH select _rbox;
		_maxk = count EGG_EVO_Kitarray3;
		_rkit1 = (floor random _maxk);
		_rkit2 = (floor random _maxk);
		_rkit3 = (floor random _maxk);
		_ammotype1 = EGG_EVO_Kitarray3 select _rkit1;
		_ammotype2 = EGG_EVO_Kitarray3 select _rkit2;
		_ammotype3 = EGG_EVO_Kitarray3 select _rkit3;
		_acrate = createVehicle [_boxtype, _pos1, [], 10, "NONE"];
		clearWeaponCargoGlobal _acrate;
		clearMagazineCargoGlobal _acrate;
		_acrate addMagazineCargoGlobal [_ammotype1,6];
		_acrate addMagazineCargoGlobal [_ammotype2,4];
		_acrate addMagazineCargoGlobal [_ammotype3,6];
	};
	case 3: //rockets
	{
		_maxb = count EGG_EVO_LootboxC;
		_rbox = (floor random _maxb);
		_boxtype = EGG_EVO_LootboxC select _rbox;
		_maxk = ((count EGG_EVO_Kitarray4)/2);
		_rkitA = ((floor random _maxk)*2);
		_rkitB = ((floor random _maxk)*2);
		_rkitC = ((floor random _maxk)*2);
		_weptype1 = EGG_EVO_Kitarray4 select _rkitA;
		_ammotype1 = EGG_EVO_Kitarray4 select (_rkitA + 1);
		_weptype2 = EGG_EVO_Kitarray4 select _rkitB;
		_ammotype2 = EGG_EVO_Kitarray4 select (_rkitB + 1);
		_ammotype3 = EGG_EVO_Kitarray4 select (_rkitC + 1);
		_acrate = createVehicle [_boxtype, _pos1, [], 10, "NONE"];
		clearWeaponCargoGlobal _acrate;
		clearMagazineCargoGlobal _acrate;
		_acrate addWeaponCargoGlobal [_weptype1,1];	
		_acrate addWeaponCargoGlobal [_weptype2,1];	
		_acrate addMagazineCargoGlobal [_ammotype1,6];
		_acrate addMagazineCargoGlobal [_ammotype2,2];
		_acrate addMagazineCargoGlobal [_ammotype3,3];	
	};
	case 4: //MG
	{
		_maxb = count EGG_EVO_LootboxG;
		_rbox = (floor random _maxb);
		_boxtype = EGG_EVO_LootboxG select _rbox;
		_maxk = (count EGG_EVO_Kitarray5)/2;
		_rkit1 = ((floor random _maxk)*2);
		_rkit2 = ((floor random _maxk)*2);
		_rkit3 = ((floor random _maxk)*2);
		_weptype1 = EGG_EVO_Kitarray5 select _rkit1;
		_ammotype1 = EGG_EVO_Kitarray5 select (_rkit1+1);
		_ammotype2 = EGG_EVO_Kitarray5 select (_rkit2+1);
		_ammotype3 = EGG_EVO_Kitarray5 select (_rkit3+1);
		_acrate = createVehicle [_boxtype, _pos1, [], 10, "NONE"];
		clearWeaponCargoGlobal _acrate;
		clearMagazineCargoGlobal _acrate;
		_acrate addWeaponCargoGlobal [_weptype1,1];	
		_acrate addMagazineCargoGlobal [_ammotype1,6];	
		_acrate addMagazineCargoGlobal [_ammotype2,3];	
		_acrate addMagazineCargoGlobal [_ammotype3,1];	
	};
	case 5: //sniper
	{
		_maxb = count EGG_EVO_LootboxD;
		_rbox = (floor random _maxb);
		_boxtype = EGG_EVO_LootboxD select _rbox;
		_maxk = (count EGG_EVO_Kitarray6)/2;
		_rkit1 = ((floor random _maxk)*2);
		_rkit2 = ((floor random _maxk)*2);
		_rkit3 = ((floor random _maxk)*2);
		_weptype1 = EGG_EVO_Kitarray6 select _rkit1;
		_ammotype1 = EGG_EVO_Kitarray6 select (_rkit1+1);
		_ammotype2 = EGG_EVO_Kitarray6 select (_rkit2+1);
		_ammotype3 = EGG_EVO_Kitarray6 select (_rkit3+1);
		_acrate = createVehicle [_boxtype, _pos1, [], 10, "NONE"];
		clearWeaponCargoGlobal _acrate;
		clearMagazineCargoGlobal _acrate;
		_acrate addWeaponCargoGlobal [_weptype1,1];	
		_acrate addMagazineCargoGlobal [_ammotype1,6];	
		_acrate addMagazineCargoGlobal [_ammotype2,6];	
		_acrate addMagazineCargoGlobal [_ammotype3,4];	
	};
	case 6: //smg
	{
		_maxb = count EGG_EVO_LootboxB;
		_rbox = floor random _maxb;
		_boxtype = EGG_EVO_LootboxB select _rbox;
		_maxk = (count EGG_EVO_Kitarray7)/2;
		_rkit1 = ((floor random _maxk)*2);
		_rkit2 = ((floor random _maxk)*2);
		_rkit3 = ((floor random _maxk)*2);
		_weptype1 = EGG_EVO_Kitarray7 select _rkit1;
		_ammotype1 = EGG_EVO_Kitarray7 select (_rkit1+1);
		_weptype2 = EGG_EVO_Kitarray7 select _rkit2;
		_ammotype2 = EGG_EVO_Kitarray7 select (_rkit2+1);
		_weptype3 = EGG_EVO_Kitarray7 select _rkit3;
		_ammotype3 = EGG_EVO_Kitarray7 select (_rkit3+1);
		_acrate = createVehicle [_boxtype, _pos1, [], 10, "NONE"];
		clearWeaponCargoGlobal _acrate;
		clearMagazineCargoGlobal _acrate;
		_acrate addWeaponCargoGlobal [_weptype1,1];	
		_acrate addWeaponCargoGlobal [_weptype2,1];	
		_acrate addWeaponCargoGlobal [_weptype3,1];	
		_acrate addMagazineCargoGlobal [_ammotype1,6];	
		_acrate addMagazineCargoGlobal [_ammotype2,4];	
		_acrate addMagazineCargoGlobal [_ammotype3,5];	
	};
	case 7: //rifle
	{
		_maxb = count EGG_EVO_LootboxF;
		_rbox = (floor random _maxb);
		_boxtype = EGG_EVO_LootboxF select _rbox;
		_maxk = (count EGG_EVO_Kitarray7)/2;
		_rkit1 = ((floor random _maxk)*2);
		_rkit2 = ((floor random _maxk)*2);
		_rkit3 = ((floor random _maxk)*2);
		_weptype1 = EGG_EVO_Kitarray7 select _rkit1;
		_ammotype1 = EGG_EVO_Kitarray7 select (_rkit1+1);
		_weptype2 = EGG_EVO_Kitarray7 select _rkit2;
		_ammotype2 = EGG_EVO_Kitarray7 select (_rkit2+1);
		_ammotype3 = EGG_EVO_Kitarray7 select (_rkit3+1);
		_acrate = createVehicle [_boxtype, _pos1, [], 10, "NONE"];
		clearWeaponCargoGlobal _acrate;
		clearMagazineCargoGlobal _acrate;
		_acrate addWeaponCargoGlobal [_weptype1,1];	
		_acrate addWeaponCargoGlobal [_weptype2,1];	
		_acrate addMagazineCargoGlobal [_ammotype1,6];	
		_acrate addMagazineCargoGlobal [_ammotype2,3];	
		_acrate addMagazineCargoGlobal [_ammotype3,5];	
	};
	case 8: //GL
	{
		_maxb = count EGG_EVO_LootboxE;
		_rbox = (floor random _maxb);
		_boxtype = EGG_EVO_LootboxE select _rbox;
		_maxk = (count EGG_EVO_Kitarray9)/2;
		_rkit1 = ((floor random _maxk)*2);
		_rkit2 = ((floor random _maxk)*2);
		_rkit3 = ((floor random _maxk)*2);
		_weptype1 = EGG_EVO_Kitarray9 select _rkit1;
		_ammotype1 = EGG_EVO_Kitarray9 select (_rkit1+1);
		_weptype2 = EGG_EVO_Kitarray9 select _rkit2;
		_ammotype2 = EGG_EVO_Kitarray9 select (_rkit2+1);
		_ammotype3 = EGG_EVO_Kitarray9 select (_rkit3+1);
		_acrate = createVehicle [_boxtype, _pos1, [], 10, "NONE"];
		clearWeaponCargoGlobal _acrate;
		clearMagazineCargoGlobal _acrate;
		_acrate addWeaponCargoGlobal [_weptype1,1];	
		_acrate addWeaponCargoGlobal [_weptype2,1];	
		_acrate addMagazineCargoGlobal [_ammotype1,6];	
		_acrate addMagazineCargoGlobal [_ammotype2,4];	
		_acrate addMagazineCargoGlobal [_ammotype3,5];
		_acrate addMagazineCargoGlobal ["RH_5Rnd_B_Beneli_Pellets",3];
		_acrate addMagazineCargoGlobal ["RH_5Rnd_B_Beneli_74Slug",3];
		_acrate addMagazineCargoGlobal ["RH_1Rnd_30mm",6];
		_acrate addMagazineCargoGlobal ["1rnd_HE_GP25",8];
		_acrate addMagazineCargoGlobal ["1rnd_HE_M203",8];
		_acrate addMagazineCargoGlobal ["6Rnd_HE_M203",8];

		if (gitsnades == 1) then
		{
//new GL AMMO
			_acrate addMagazineCargoGlobal ["5Rnd_HE_GP25",8];
			_acrate addMagazineCargoGlobal ["5Rnd_FlareWhite_GP25",8];
			_acrate addMagazineCargoGlobal ["5Rnd_Smoke_GP25",8];
			_acrate addMagazineCargoGlobal ["5Rnd_HE_M203",8];
			_acrate addMagazineCargoGlobal ["5Rnd_HEDP_M203",8];
			_acrate addMagazineCargo ["5Rnd_FlareYellow_M203",8];
			_acrate addMagazineCargo ["5Rnd_SmokeRed_M203",8];
		};
	};

	case 9: //backpack
	{
		_acrate = createVehicle ["Misc_Backpackheap_EP1", _pos1, [], 10, "NONE"];
		_maxk = count EGG_EVO_Kitarray0;
		_rkit1 = (floor random _maxk);
		packID2 = _acrate addAction [("<t color='#FF4040'>" + "Examine Backpack Pile" + "</t>"),"data\scripts\BPmenu_vet.sqf",_rkit1,1, true, true,""];

	};

};
//box filled
EGG_current_boxes = EGG_current_boxes + _acrate;
_crcount = count EGG_current_boxes;

//	hint format["no. boxes %1",_crcount];

};

EGG_EVO_deletelootbox =
{
{deletevehicle _x} forEach EGG_current_boxes;
sleep 1.0;
EGG_current_boxes = []; 
};


//ammo dump defence
//now lootbox is spawned, set a guard on it
EGG_EVO_Guardloot =
{
_pos = _this select 0;
_grp = createGroup (east);
_type = EGG_EVO_east5 select 0;
_unit = _grp createUnit [_type, _pos, [], 20, "FORM"];Sleep BIS_EVO_GlobalSleep;
_unit addEventHandler ["killed", {handle = [_this select 0,"INF"] execVM "data\scripts\mobjbury.sqf"}];		
[_grp,5] call BIS_EVO_FillInf;
_recy = [objnull,_grp] execVM "data\scripts\grecycle.sqf";
Sleep 2;
_allvecs = EGG_EVO_eastveh6;
_max = (count _allvecs)-1;
_array = [_allvecs select (floor random _max),_pos,(east),10,180,0] call BIS_EVO_CreateVehicle;
_grp = _array select 0;
_vec = _array select 1;
_rds = (_vec nearRoads 20);

if(not Isnull (_rds select 0)) then
{
	_vec setpos position (_rds select 0);
	_vec setdir (getdir (_rds select 0));
}
else
{
	_vec setdir 180;
};

[_grp] call BIS_EVO_OrderSquad;
Sleep 1;
_recy = [objnull,_grp] execVM "data\scripts\grecycle.sqf";
{_x setSkill skillfactor+(random 0.2);_x addEventHandler ["killed", {handle = [_this select 0,"MEC"] execVM "data\scripts\mobjbury.sqf"}]} forEach (units _grp);

};

//main script starts here

_loottype = 0;
_countlocs = 0;
_lootcenter = _this select 0;

//TEMP
//_lootcenter = getmarkerpos "hospital";

_cityno = _this select 1;

//deletes old boxes
//temp disable
/*
if (isdefined _oldcity and _oldcity >0) then {_oldcity = _cityno} else {_oldcity =0};
if (_oldcity < _cityno) then {[EGG_current_boxes] call EGG_EVO_deletelootbox};
*/

_lootbuildingarray = nearestObjects [_lootcenter, ["Land_Mil_Barracks_i","Land_Mil_ControlTower","Land_Misc_deerstand","Land_A_GeneralStore_01","Land_Farm_Cowshed_a","Land_A_GeneralStore_01a","Land_A_Hospital","Land_A_Office01","Land_A_Office02","Land_A_Pub_01","Land_A_TVTower_Base","Land_a_stationhouse","Land_rail_station_big","Land_Barn_Metal","Land_Barn_W_01","Land_Barrack2","Land_Church_01","Land_Church_02","Land_Church_05R","Land_Hlidac_budka","Land_HouseB_Tenement","Land_HouseV2_02_Interier","Land_Ind_Garage01","Land_Ind_Expedice_3","Land_Ind_Pec_03a","Land_Barn_W_02","Land_Church_02a","Land_Church_03","Land_Ind_Pec_03b","Land_Ind_SawMillPen","Land_Ind_Vysypka","Land_Ind_Workshop01_01","Land_Ind_Workshop01_02","Land_Ind_Workshop01_04","Land_Panelak","Land_Panelak2","Land_Rail_House_01","Land_Farm_Cowshed_b","Land_Farm_Cowshed_c","Land_Hangar_2","Land_SS_hangar","Land_Shed_Ind02Land_Tovarna2","Land_sara_domek_zluty","Land_sara_hasic_zbroj","Land_stodola_old_open","Land_stodola_open","Land_HouseV2_04_interier","Land_HouseV_1I4","Land_A_FuelStation_Shed","Land_repair_center","FuelStation","FuelStation_army","Land_Mil_Repair_center_EP1","Land_A_FuelStation_Build","Land_A_FuelStation_Feed","Land_Ind_FuelStation_Feed_EP1","Land_Ind_FuelStation_Build_EP1","Land_Ind_FuelStation_Shed_EP1","Land_Ind_Garage01_EP1","Land_benzina_schnell","Land_fuelstation","Land_fuelstation_army","Land_ibr_FuelStation_Feed","Land_ibr_FuelStation_Build","Land_ibr_FuelStation_Shed","Land_A_BuildingWIP","Land_A_Castle_BergfritLand_A_Castle_Bergfrit","Land_A_Castle_Gate","Land_A_Crane_02a"], 500];

_countlocs = count _lootbuildingarray;

//hint format["loot locs %1",_countlocs];

if (_countlocs >8) then {_countlocs = 8};

_c=0;
while {_c < _countlocs} do 
{
	_currenthouse = _lootbuildingarray select _c;
//		_ctype = typeof (_currenthouse);
	_loottype = (floor random 10);//pistol or mg etc
//		hint format["loot type %1",_loottype];
//		_currenthouse = nearestObjects [_lootcenter, [_ctype],500];
//		_spawnlootpos = position (_currenthouse select 0);
	_spawnlootpos = position (_currenthouse);

//temp
//		_spawnlootpos = getmarkerpos "LAVHQf";

	[_loottype, _spawnlootpos] call EGG_EVO_spawnlootbox;
//temp rem out
	[_spawnlootpos] call EGG_EVO_Guardloot;
	_c=_c+1;
	sleep 1.1;
};

exit;

Edited by eggbeast

Share this post


Link to post
Share on other sites

Yeah, just to clarify switches are fine within if thens, i missed the closing }; of the if then so it was 'open'.

Thanks for the example code eggbeast. It all helps soften the learning curve.

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  

×