SHARE
TWEET

ExileServer_system_lootManager_spawnLootInBuilding.sqf

secondcoming May 21st, 2016 (edited) 263 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * ExileServer_system_lootManager_spawnLootInBuilding
  3.  *
  4.  * Exile Mod
  5.  * www.exilemod.com
  6.  * © 2015 Exile Mod Team
  7.  *
  8.  * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
  9.  * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
  10.  */
  11.  
  12. private["_building","_buildingConfig","_lootTableName","_localPositions","_lootConfig","_maximumNumberOfLootPositions","_maximumPositionCoverage","_maximumNumberOfItemsPerLootSpot","_numberOfPositionsToUse","_lootPositions","_spawnedItemClassNames","_lootWeaponHolderNetIDs","_lootPosition","_lootHolder","_numberOfItemsToSpawn","_n","_itemClassName","_cargoType","_magazineClassNames","_magazineClassName","_numberOfMagazines"];
  13. _building = _this;
  14. _building setVariable ["ExileLootSpawnedAt", time];
  15. _building setVariable ["ExileHasLoot", true];
  16. _buildingConfig = configFile >> "CfgBuildings" >> typeOf _building;
  17. _lootTableName = getText (_buildingConfig >> "table");
  18. _localPositions = getArray (_buildingConfig >> "positions");
  19. _lootConfig = missionConfigFile >> "CfgExileLootSettings";
  20. _maximumNumberOfLootPositions = getNumber (_lootConfig >> "maximumNumberOfLootSpotsPerBuilding");
  21. _maximumPositionCoverage = getNumber (_lootConfig >> "maximumPositionCoverage");
  22. _maximumNumberOfItemsPerLootSpot = getNumber (_lootConfig >> "maximumNumberOfItemsPerLootSpot");
  23. _numberOfPositionsToUse = 1 max (((count _localPositions) * 100 / _maximumPositionCoverage) min _maximumNumberOfLootPositions);
  24. _localPositions = _localPositions call ExileClient_util_array_shuffle;
  25. _lootPositions = _localPositions select [0, _numberOfPositionsToUse];
  26. _spawnedItemClassNames = [];
  27. _lootWeaponHolderNetIDs = [];
  28. {
  29.     _lootPosition = ASLToATL (AGLToASL (_building modelToWorld _x));
  30.     if (_lootPosition select 2 < 0.05) then
  31.     {
  32.         _lootPosition set [2, 0.05];
  33.     };
  34.     _lootHolder = objNull;
  35.     _numberOfItemsToSpawn = (floor (random _maximumNumberOfItemsPerLootSpot)) + 1;
  36.     for "_n" from 1 to _numberOfItemsToSpawn do
  37.     {
  38.         _itemClassName = _lootTableName call ExileServer_system_lootManager_dropItem;
  39.         if !(_itemClassName in _spawnedItemClassNames) then
  40.         {
  41.             if (isNull _lootHolder) then
  42.             {
  43.                 _lootHolder = createVehicle ["LootWeaponHolder", _lootPosition, [], 0, "CAN_COLLIDE"];
  44.                 _lootHolder setDir (random 360);
  45.                 _lootHolder setPosATL _lootPosition;
  46.                 _lootHolder setVariable ["ExileSpawnedAt", time];
  47.                 _lootWeaponHolderNetIDs pushBack (netId _lootHolder);                                          
  48.             };
  49.             _cargoType = _itemClassName call ExileClient_util_cargo_getType;
  50.             switch (_cargoType) do
  51.             {
  52.                 case 1:    
  53.                 {
  54.                     if (_itemClassName isEqualTo "Exile_Item_MountainDupe") then
  55.                     {
  56.                         _lootHolder addMagazineCargoGlobal [_itemClassName, 2];
  57.                     }
  58.                     else
  59.                     {
  60.                         _lootHolder addMagazineCargoGlobal [_itemClassName, 1];
  61.                     };
  62.                 };
  63.                 case 3:    
  64.                 {
  65.                     _lootHolder addBackpackCargoGlobal [_itemClassName, 1];
  66.                 };
  67.                 case 2:    
  68.                 {
  69.                     _lootHolder addWeaponCargoGlobal [_itemClassName, 1];
  70.                     /*
  71.                     if (_itemClassName != "Exile_Melee_Axe") then
  72.                     {
  73.                         _magazineClassNames = getArray(configFile >> "CfgWeapons" >> _itemClassName >> "magazines");
  74.                         if (count(_magazineClassNames) > 0) then
  75.                         {
  76.                             _magazineClassName = selectRandom _magazineClassNames;
  77.                             _numberOfMagazines = 2 + floor(random 3);
  78.                             _lootHolder addMagazineCargoGlobal [_magazineClassName, _numberOfMagazines];
  79.                             _spawnedItemClassNames pushBack _magazineClassName;
  80.                         };
  81.                     };
  82.                     */
  83.                     _numberOfItemsToSpawn = -1;
  84.                 };
  85.                 default
  86.                 {
  87.                     _lootHolder addItemCargoGlobal [_itemClassName, 1];
  88.                 };
  89.             };
  90.             _spawnedItemClassNames pushBack _itemClassName;
  91.         };
  92.     };
  93. }
  94. forEach _lootPositions;
  95. _building setVariable ["ExileLootWeaponHolderNetIDs", _lootWeaponHolderNetIDs];
  96. ExileServerBuildingNetIdsWithLoot pushBack (netId _building);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top