Jump to content
Sign in to follow this  
spitfire007

How do I add only one of two random magazines to a vehicle ?

Recommended Posts

Hi all,

I am very new at this so please forgive me if it's an obvious question.

I have the following code in my wasteland folder.

_num = floor (random 100);
if (_num < 100) then { _car addWeaponCargoGlobal ["Binocular", 1];
if (_num < 75) then { _car addWeaponCargoGlobal ["NVgoggles", 1]};
if (_num < 30) then { _car addMagazineCargoGlobal ["BAF_ied_v1", 1]};
if (_num < 30) then { _car addMagazineCargoGlobal ["BAF_ied_v2", 1]};

I would like to be able to add either the BAF_ied_v1 to the car OR the BAF_ied_v2

Thanks for looking.

Share this post


Link to post
Share on other sites

_num = floor (random 100);
if (_num < 100) then { _car addWeaponCargoGlobal ["Binocular", 1];
if (_num < 75) then { _car addWeaponCargoGlobal ["NVgoggles", 1]};
if (_num < 30) then {
_random = random 1;
If (_random > 0.5) then {
_car addMagazineCargoGlobal ["BAF_ied_v1", 1];
} else {
_car addMagazineCargoGlobal ["BAF_ied_v2", 1];
};
};

That one should work.

Share this post


Link to post
Share on other sites

I hope you both have noticed that your if-clauses won't work as intended :S

As I understood the query you want to either add a Binocular or NVgoggles AND either BAF_ied_v1 or BAF_ied_v2 to the same vehicle.

But in case your random number happens to be 29, you'll add a Binocular AND NVgoggles AND one of the IED-types.

How about this?

waituntil {!isNil "bis_fnc_init"};
_car addWeaponCargoGlobal [(["Binocular", "NVgoggles"] call BIS_fnc_selectRandom), 1];
_car addWeaponCargoGlobal [(["BAF_ied_v1", "BAF_ied_v2"] call BIS_fnc_selectRandom), 1];

Don't forget to place the Functions-Module into your map for the above code to work.

Share this post


Link to post
Share on other sites

Thanks for the code above.

I am not sure it's going to work for me though as I don't want all vehicles to have either binoculars OR NVgoggles.

waituntil is gong to break it ?

From the Wiki.

"The execution of the rest of the script therefore will be suspended until waitUntil condition is satisfied and the loop is aborted. Because of this script suspension use spawn or execVM to safely execute code containing waitUntil"

---------- Post added at 06:15 ---------- Previous post was at 06:11 ----------

This is what I have changed.

_num = floor (random 100);
if (_num < 75) then { _car addWeaponCargoGlobal ["Binocular", 1];
if (_num < 40) then { _car addWeaponCargoGlobal ["NVgoggles", 1]};


if (_num < 30) then {

_random = random 1;

If (_random > 0.5) then {

_car addMagazineCargoGlobal ["BAF_ied_v1", 1]}; 

else 	{
_car addMagazineCargoGlobal ["BAF_ied_v2", 1]};

				};

if (_num < 5) then { _car addWeaponCargoGlobal ["Binocular_Vector", 1]}; 

Unfortunately I think there must be a syntax error I can't spot somewhere.

If I insert the above into the file it breaks all vehicle weapon spawning. I only get a makerov and 2 mags in all vehicles.

I am guessing a curly bracket or something is not where it should be and being a novice I can't spot it.

Edit: got it working to my requirements.

_num = floor (random 100);

if (_num < 75) then  { _car addWeaponCargoGlobal ["Binocular", 1]};
if (_num < 40) then  { _car addWeaponCargoGlobal ["NVgoggles", 1]};
if (_num < 30) then {_random = random 1};

if (_num < 10) then {
_random = random 1;
If (_random > 0.5) then {
_car addMagazineCargoGlobal ["BAF_ied_v1", 1];
} else {
_car addMagazineCargoGlobal ["BAF_ied_v2", 1];
};
};

if (_num < 5) then { _car addWeaponCargoGlobal ["Binocular_Vector", 1]}; 

This code works !

Thanks guys for the help.

Edited by spitfire007

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  

×