Welcome to the Iron Front Fan Forums!
Sign up Latest Topics
 
 
 


Reply
  Author   Comment  
Tayuk

Avatar / Picture

Retired Admin/IFR
Registered:
Posts: 456
Reply with quote  #1 
I am creating a script to have a random weapons/items in an ammobox, which works fine for selecting a random weapon and random magazines. But what I would like is to have random weapons selected, but have the correct magazines to suit the randomly selected weapon in the box also. Would anyone have an idea how to do this?

// called using nul = [this] execVM "randomweapons.sqf"
_box = _this select 0;
_weapon = ["LIB_MP40","LIB_K98"];
_magazine = ["LIB_32Rnd_9x19", "lib_5Rnd_792x57"];

_box allowDamage false;

clearWeaponCargo _box;
clearMagazineCargo _box;

_box AddMagazineCargo [_magazine select floor (random count _magazine),3];
_box AddMagazineCargo [_magazine select floor (random count _magazine),3];
_box AddweaponCargo [_weapon select floor (random count _weapon), 1];
0
Rydygier

Avatar / Picture

IFR Team
Registered:
Posts: 179
Reply with quote  #2 
One way would be to select randomly one of nested "set" array, that holds both, a weapon, and appriopriate for it ammo class:

_sets = [["LIB_MP40","LIB_32Rnd_9x19"],["LIB_K98","lib_5Rnd_792x57"]];
_set = _sets select (floor (random (count _sets)));

_weapon = _set select 0;
_ammo = _set select 1;

_box AddMagazineCargo [_ammo,3];
_box AddweaponCargo [_weapon,1];


Another possibility may be to select randomly a weapon, then obtain from it's config proper magazine class probably via getText command, but I haven't much experience with such methods.

EDIT

Something like this, I believe:

_set = ["LIB_MP40","LIB_K98"];
_weapon = _set select (floor (random (count _set)));

_mags = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");

{_box AddMagazineCargo [_x,3]} foreach _mags;
_box AddweaponCargo [_weapon,1];


0
Tayuk

Avatar / Picture

Retired Admin/IFR
Registered:
Posts: 456
Reply with quote  #3 
Brilliant stuff, that works perfectly, thank you Rydygier 

[EDIT] Both methods work perfectly well.


0
Tayuk

Avatar / Picture

Retired Admin/IFR
Registered:
Posts: 456
Reply with quote  #4 

I have got this finalish script that works perfectly well in single player and in the editor, but in multiplayer it doesn't. If there are 2 players each player see's different things in the box and only me being the host was really able to take items from the box, any one know how to fix that?

Might it be something simple like adding this line to it?

if(isServer) then { the script in here };




//nul = [this] execVM "weapons2.sqf";
_box = _this select 0;

_box allowDamage false;

clearWeaponCargo _box;
clearMagazineCargo _box;

_weap = ["LIB_SVT_40","LIB_M9130PU", "LIB_DP28","LIB_M9130", "LIB_PPSh41_m", "LIB_PPSh41_d", "LIB_TT33", "LIB_G43", "LIB_MP44", "LIB_MG42","LIB_MP40","LIB_M1908", "LIB_K98", "LIB_K98ZF39"];
_weapon = _weap select (floor (random (count _weap)));
_weapon1 = _weap select (floor (random (count _weap)));
_item = ["itemmap", "itemCompass", "LIB_Binocular_SU", "itemwatch", "LIB_w"];
_item1 = ["Pipebomb", "LIB_pomzec_MINE_mag", "lib_f1", "lib_nb39"];
_mags = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines");
_mags1 = getArray (configFile >> "CfgWeapons" >> _weapon1 >> "magazines");

{_box AddMagazineCargo [_x,6]} foreach _mags;
{_box AddMagazineCargo [_x,6]} foreach _mags1;
_box AddweaponCargo [_weapon,1];
_box AddweaponCargo [_weapon1,1];
_box AddweaponCargo [_item select floor (random count _item), 1];
_box AddMagazineCargo [_item1 select floor (random count _item1), 1];


0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.