Forum Jump :

Author Message


Posts: 22
Rank:


Level: Member

Country: us
Location: Jupiter, Cloud 9
Occupation: Plant Burner
Age: 86
In-game name: war1ox

 
#1 Posted at 2015-08-12 17:53        
     
Hello everyone, basically what I'm looking for is a script for Arma 3 that gathers all enterable building locations & spawns loot inside of them, a totally automated randomized loot system. Something like this but with Arma 3: Loot System. This one created by Ed for Arma 2 OA works insanely well:
taken from here: 404Games. Is there a loot script out there like the one PLAYERUNKNOWN's Battle Royale mission uses? I've found a few loot scripts but they aren't automated & randomized:
    1. Loot and Food script
    2. Loot System

PS- This guy was on the right track it seemed, but the thread went dead: Random Loot

This post was edited by war1ox (2015-08-13 12:00, ago)

Steam: war1ox

Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 59
In-game name: Kobayashi Maru

 
#2 Posted at 2015-08-13 01:21        
     
So, for the automated weapon list, you can try this script:
_weapons = [];
_configArray = ("isclass _x" configclasses (configfile >> "cfgweapons"));
_types = [1,2,4,131072];
for "_i" from 0 to 2 do {
        {
         _class = _x;
         _className = configname _x;
         _scope = getnumber (_class >> "scope");
         _type = getnumber (_class >> "type");
         _mags = getArray (_class >> "magazines");
         if (_type == _types select _i) then {
          if (_scope == 2 && {gettext (_class >> "model") != ""}) then {
            _weapons pushback [_className,_mags];
          }};
        } foreach _configArray;  };
_random_loot_array = _weapons select (floor random (count _weapons));
_random_loot_weapon = _random_loot_array select 0;
_random_loot_mags = _random_loot_array select 1 select (floor random (count (_random_loot_array select 1)));  _random_loot = [_random_loot_weapon,_random_loot_mags];
_random_loot will return an array with updated weapons (in Arma and addons) and a randomized magazine. You can limit this search as far as:
type = 1 means primary weapons;
type = 2 for handguns
type = 4 for launchers
type = 131072 for uniforms and accessories, items.

Your script isn't really optimized as you run it foreach house in map! but here is what it does with my suggest above:
_odd1 = 40;
_odd2 = 30;
_weapons = [];
_configArray = ("isclass _x" configclasses (configfile >> "cfgweapons"));
_types = [1,2,4,131072];
for "_i" from 0 to 2 do {
      {
        _class = _x;
        _className = configname _x;
        _scope = getnumber (_class >> "scope");
        _type = getnumber (_class >> "type");
        _mags = getArray (_class >> "magazines");
          if (_type == _types select _i) then {
        if (_scope == 2 && {gettext (_class >> "model") != ""}) then {
          _weapons pushback [_className,_mags];
        }};
      } foreach _configArray;
};
_pos = [0,0];
randomweapon_buildings = nearestObjects [_pos, ["house"], 60000];
{
_building = _x;
_buildingpos = [];
_endloop = false;
_poscount = 0;
while {!_endloop} do {
  if(((_building buildingPos _poscount) select 0) != 0 && ((_building buildingPos _poscount) select 1) != 0) then {
    _buildingpos = _buildingpos + [_building buildingPos _poscount];
    _poscount = _poscount + 1;
  } else {
   _endloop = true;
  };
};
_num = (random 100);
if (_num < _odd1) then {
if (count _buildingpos > 0) then {
  for "_r" from 0 to (count _buildingpos -1) do {
   _num2 = (random 100);
   if (_num2 < _odd2) then {
    _pos = _buildingpos select _r;
    _posnew = _pos;
    if(_pos select 2 < 0) then {_pos = [_pos select 0, _pos select 1, 1]};
    _z = 0;
    _testpos = true;
    while {_testpos} do {
     if((!lineIntersects[ATLtoASL(_pos), ATLtoASL([_pos select 0, _pos select 1, (_pos select 2) - (0.1 * _z)])]) && (!terrainIntersect[(_pos), ([_pos select 0, _pos select 1, (_pos select 2) - (0.1 * _z)])]) && (_pos select 2 > 0)) then {
      _posnew = [_pos select 0, _pos select 1, (_pos select 2) - (0.01 * _z)];
      _z = _z + 1;
    } else {_testpos = false};
  };
_random_loot_array = _weapons select (floor random (count _weapons));
_random_loot_weapon = _random_loot_array select 0;
_random_loot_mags = _random_loot_array select 1 select (floor random (count (_random_loot_array select 1)));
_random_loot = [_random_loot_weapon,_random_loot_mags];
_weaponholder = createVehicle ["groundWeaponHolder", _posnew, [], 0, "CAN_COLLIDE"];
_weaponholder addWeaponCargoGlobal [_random_loot_weapon, 1];
_weaponholder addMagazineCargoGlobal [_random_loot_mags, floor(random(5))];
_weaponholder setPos _posnew;
};
};
};
};
}foreach randomweapon_buildings;

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Advertisement


Author Message


Posts: 22
Rank:


Level: Member

Country: us
Location: Jupiter, Cloud 9
Occupation: Plant Burner
Age: 86
In-game name: war1ox

 
#3 Posted at 2015-08-13 02:00        
     
You're definitely right, the script isn't very optimized, but it does work now thanks to you. What would you suggest doing to it to further optimize it? Also, is there a way to add objects, not just weapons? Like silencers, nvg's, etc? I wanted to do that but I don't have the knowledge.

I'm very grateful for your help. Thank you. Seriously, this is great work you did.

This post was edited by war1ox (2015-08-13 02:31, ago)

Steam: war1ox

Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 59
In-game name: Kobayashi Maru

 
#4 Posted at 2015-08-13 07:31        
     
Added items, uniforms and other stuffs. And populate only nearest house from players, with these equipments. It saves FPS a lot!
_odd1 = 40;
_odd2 = 30;
_odd3 = 20;
_weapons = [];
_items = [];
_cfgWpnarray = ("isclass _x" configclasses (configfile >> "cfgweapons"));
_types = [1,2,4,131072];
for "_i" from 0 to 3 do {
      {
        _class = _x;
        _className = configname _x;
        _scope = getnumber (_class >> "scope");
        _type = getnumber (_class >> "type");
        _mags = getArray (_class >> "magazines");
          if (_type == _types select _i) then {
        if (_scope == 2 && {gettext (_class >> "model") != ""}) then {
        call {
        if (_type == 131072) exitWith {_items pushback _className};
          _weapons pushback [_className,_mags];
        };
        }};
      } foreach _cfgWpnarray;
};

0 = [_odd1,_odd2,_odd3,_weapons,_items] spawn {
_odd1 = _this select 0;
_odd2 = _this select 1;
_odd3 = _this select 2;
_weapons = _this select 3;
_items = _this select 4;

_buildings = [];
_building_array = [];
while {true} do {
  {_building = nearestBuilding _x; _buildings pushback _building;
  _building_array = _buildings arrayintersect _buildings} forEach allPlayers;
  {
    _building = _x;
    if !(_building getVariable ["treated",false]) then {
      _num1 = random 100;
      if (_num1 < _odd1) then {
        _available_pos = [_building] call BIS_fnc_buildingPositions;
        if (count _available_pos !=0) then {
          for "_i" from 0 to (count _available_pos -1) do {
            _num2 = random 100;
            _num3 = random 100;
            if (_num2 < _odd2) then {
              _pos = _available_pos select _i;
              _random_loot_array = _weapons select (floor random (count _weapons));
              _random_loot_weapon = _random_loot_array select 0;
              _random_loot_mags = _random_loot_array select 1 select (floor random (count (_random_loot_array select 1)));
              _random_loot_item = _items select (floor random (count _items));
              _weaponholder = createVehicle ["groundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"];
              _weaponholder addWeaponCargoGlobal [_random_loot_weapon, 1];
              if (count (_random_loot_array select 1) >0) then {_weaponholder addMagazineCargoGlobal [_random_loot_mags, 1+floor(random(4))]};
            };
            if (_num3 < _odd3) then {
              _pos = _available_pos select _i;
              _random_loot_item = _items select (floor random (count _items));
              _weaponholder = createVehicle ["groundWeaponHolder", _pos, [], 0, "CAN_COLLIDE"];
              _weaponholder addItemCargoGlobal [_random_loot_item,1];
            };
          };
        };
      };
      _building setVariable ["treated", true];
    };
  }foreach _building_array;
sleep 2;
};
};

This post was edited by Pierre MGI (2015-08-13 07:51, ago)

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 22
Rank:


Level: Member

Country: us
Location: Jupiter, Cloud 9
Occupation: Plant Burner
Age: 86
In-game name: war1ox

 
#5 Posted at 2015-08-13 11:50        
     
Hello Pierre, I just tried the script & sadly there are no loot spawns this time. I also tried changing the odds to 100, still nothing spawned. Any idea why?

I apologize for being such a pain in the arse. I'm still learning the art of scripting. Also, this will likely be used by many people in the future, so it's a great script to make for the community!

This post was edited by war1ox (2015-08-13 15:13, ago)

Steam: war1ox

Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 59
In-game name: Kobayashi Maru

 
#6 Posted at 2015-08-13 17:14        
     
Works fine for me. No problem and no error in rpt file. Check how you run the script.
I tested it in an execVMed sqf from a trigger and in debug console.

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 22
Rank:


Level: Member

Country: us
Location: Jupiter, Cloud 9
Occupation: Plant Burner
Age: 86
In-game name: war1ox

 
#7 Posted at 2015-08-13 18:30        
     
Okay if it works fine for you, then it most likely is on my end. Thanks for your help Pierre!

Steam: war1ox

Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 59
In-game name: Kobayashi Maru

 
#8 Posted at 2015-08-14 05:15        
     
check for V1.48 also. I use new function arrayintersect

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 1
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#9 Posted at 2017-02-10 08:26        
     
is there a way to only get the loot to spawn at military buildings areas


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 59
In-game name: Kobayashi Maru

 
#10 Posted at 2017-02-10 14:29        
     
Yes, but you need to define them. Two ways:
- your own marker or trigger areas;
- looking for some locations on map, native or added by script.
The second one is useful for spawning units, but too poorly "military area oriented" in Arma3 for your purpose.
You can also define polygons, very accurate but it's more CPU expensive than markers or triggers.

So, imho, best usage is ellipse or rectangle markers (useful to check the spawn while their alpha color is > 0, then 0 during the game).
the aim is an array of marker areas:
myMarkers = ["mrk1","mrk2"...}; 
// or any filter on allMapMarkers
Don't forget to add this array in the script.
Then, you just have to add a condition for building presence:
The above script:
while {true} do {
  {_building = nearestBuilding _x;
    _buildings pushback _building;
  _building_array = _buildings arrayintersect _buildings} forEach allPlayers;
  ....

becomes:
while {true} do {
  {_building = nearestBuilding _x;
   if ({if (_building inArea _x) exitWith {1}} count myMarkers >0) then {
    _buildings pushback _building};
  _building_array = _buildings arrayintersect _buildings} forEach allPlayers;
  ...

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS