Jump to content
Sign in to follow this  
NotASemiPro

Custom Ammo Crates with Random Loadout

Recommended Posts

Hi,

I have searched all over the web and can't find out what is wrong with a script I wrote. I am trying to spawn random guns and items in an Ammo Crate for a mission I am making. When I preview the mission, the crate is emptied, but no weapons are added.

Thanks!

//clears ammo crate

_crate = _this select 0;
clearMagazineCargo _crate;
clearWeaponCargo _crate;

//generates random number

_number = round(random 100);

//if the number is zero, then it adds one

if (_number == 0) then {_number = _number + 1};

//Based on the random number, it adds weapons to the crate

if ((_number > 0) && (_number < 21)) then {addWeaponCargo ["M16A2",1]; addMagazineCargo ["30Rnd_556x45_Stanag",3];};
if ((_number > 20) && (_number < 31)) then {addWeaponCargo ["M16A4",1]; addMAgazineCargo ["30Rnd_556x45_Stanag",3];};
if ((_number > 30) && (_number < 41)) then {addWeaponCargo ["M4A1_HWS_GL_CAMO",1]; addMagazineCargo ["30Rnd_556x45_Stanag",3];};
if ((_number > 40) && (_number < 51)) then {addWeaponCargo ["M8_SHARPSHOOTER",1] addMagazineCargo ["30Rnd_556x45_G36",3]};
if ((_number > 50) && (_number < 59)) then {addWeaponCargo ["M24",1] addMagazineCargo ["5Rnd_762x51_M24",2]};
if ((_number > 58) && (_number < 81)) then {addWeaponCargo ["AK_47_S",1] addMagazineCargo ["30Rnd_762x39_AK4",4]};
if ((_number > 80) && (_number < 101)) then {addMagazineCargo ["15Rnd_9x19_M9",2]};

//Same method for adding items

_number2 = round(random 7);


//if the number is zero, then it adds one

if (_number2 == 0) then {_number2 = _number2 + 1;};


if (_number == 1) then {addWeaponCargo ["Binocular",1];};
if (_number == 2) then {addWeaponCargo ["ItemMap",1];};
if (_number == 3) then {addWeaponCargo ["ItemGPS",1];};
if (_number == 4) then {addWeaponCargo ["ItemRadio",1]; addWeaponeCargo ["NVGoggles",1];};
if (_number == 5) then {addMagazineCargo ["20Rnd_762x51_DMR",3]};
if (_number == 6) then {addMagazineCargo ["5Rnd_127x108_KSVK",3];};
if (_number == 7) then {addWeaponCargo ["Binocular",1]; addWeaponCargo ["ItemMap",1]; addWeaponCargo ["ItemGPS",1]; addWeaponCargo ["ItemRadio",1]; addWeaponeCargo ["NVGoggles",1]; addMAgazineCargo ["5Rnd_127x108_KSVK",3];};

Share this post


Link to post
Share on other sites

Doesn't it appear strange to you that addWeaponCargo and addMagazineCargo magically finds the crate you want to use them on?

_crate, my young Padawan, use you must!

Checking Wiki, usefull it is! Hmmmmmmm.

25.jpg

Share this post


Link to post
Share on other sites
Doesn't it appear strange to you that addWeaponCargo and addMagazineCargo magically finds the crate you want to use them on?

_crate, my young Padawan, use you must!

Checking Wiki, usefull it is! Hmmmmmmm.

http://www.empireonline.com/images/features/100greatestcharacters/photos/25.jpg

Haha, thanks! I thought I checked the wiki already. I guess I skipped over that part.

Share this post


Link to post
Share on other sites

I found out that when I and another player trigger this script, we see different items in the box, and they can't pickup what is in the gear. Is there any way to bypass this?

Edit: Here is the edited code:

//clears ammo crate

_crate = _this select 0;
clearMagazineCargo _crate;
clearWeaponCargo _crate;

//generates random number

_number = round(random 100);

//if the number is zero, then it adds one

if (_number == 0) then {_number = _number + 1};

//Based on the random number, it adds weapons to the crate

if ((_number > 0) && (_number < 21)) then {_crate addWeaponCargo ["M16A2",1]; _crate addMagazineCargo ["30Rnd_556x45_Stanag",3];};
if ((_number > 20) && (_number < 31)) then {_crate addWeaponCargo ["M16A4",1]; _crate addMAgazineCargo ["30Rnd_556x45_Stanag",3];};
if ((_number > 30) && (_number < 41)) then {_crate addWeaponCargo ["M4A1_HWS_GL_CAMO",1]; _crate addMagazineCargo ["30Rnd_556x45_Stanag",3];};
if ((_number > 40) && (_number < 51)) then {_crate addWeaponCargo ["M8_SHARPSHOOTER",1]; _crate addMagazineCargo ["30Rnd_556x45_G36",3]};
if ((_number > 50) && (_number < 59)) then {_crate addWeaponCargo ["M24",1]; _crate addMagazineCargo ["5Rnd_762x51_M24",2]};
if ((_number > 58) && (_number < 81)) then {_crate addWeaponCargo ["AK_47_S",1]; _crate addMagazineCargo ["30Rnd_545x39_AK",4]};
if ((_number > 80) && (_number < 101)) then {_crate addMagazineCargo ["15Rnd_9x19_M9",2]};

//We will use the same method to add items/mags to the crate.

_number2 = round(random 7);


//if the number is zero, then it adds one

if (_number2 == 0) then {_number2 = _number2 + 1;};


if (_number2 == 1) then {_crate addWeaponCargo ["Binocular",1];};
if (_number2 == 2) then {_crate addWeaponCargo ["ItemMap",1];};
if (_number2 == 3) then {_crate addWeaponCargo ["ItemGPS",1];};
if (_number2 == 4) then {_crate addWeaponCargo ["ItemRadio",1]; addWeaponeCargo ["NVGoggles",1];};
if (_number2 == 5) then {_crate addMagazineCargo ["20Rnd_762x51_DMR",3]};
if (_number2 == 6) then {_crate addMagazineCargo ["5Rnd_127x108_KSVK",3];};
if (_number2 == 7) then {_crate addWeaponCargo ["Binocular",1]; _crate addWeaponCargo ["ItemMap",1]; _crate addWeaponCargo ["ItemGPS",1]; _crate addWeaponCargo ["ItemRadio",1]; _crate addWeaponeCargo ["NVGoggles",1]; _crate addMagazineCargo ["5Rnd_127x108_KSVK",3]; _crate addMagazineCargo ["20Rnd_762x51_DMR",3]};

Edited by NotASemiPro
Added Code

Share this post


Link to post
Share on other sites

you should only have the server spawn the items and use the add mag and weapon global commands.

1st line of code in your script should be

if (!isServer) exitwith {};

your add weapons and mag commands should be the global versions (since it MP)

addMagazineCargoGlobal 
addWeaponCargoGlobal

there are also clear weapon and mag global commands.

clearWeaponCargoGlobal
clearMagazineCargoGlobal 

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  

×