Darth_Rogue

ExileServer_system_lootManager_spawnLootforPlayer.sqf w/heli

Dec 14th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1. /**
  2. * Exile Mod
  3. * www.exilemod.com
  4. * © 2015 Exile Mod Team
  5. *
  6. * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
  7. * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
  8. */
  9.  
  10. private["_playerObject","_spawnRadius","_spawnChancePerPosition","_spawnChancePerBuilding","_maximumNumberOfLootSpotsPerBuilding","_maximumNumberOfItemsPerLootSpot","_visualThreshold","_spawnedLoot","_minimumDistanceToTraderZones","_minimumDistanceToTerritories","_playerPosition","_lastKnownPlayerPosition","_buildings","_building","_buildingType","_buildingPosition","_buildingConfig","_lootTableName","_localPositions","_spawnedItemClassNames","_lootWeaponHolderNetIDs","_spawnedLootInThisBuilding","_lootPosition","_numberOfItemsToSpawn","_lootHolder","_n","_itemClassName","_cargoType","_magazineClassNames","_magazineClassName","_numberOfMagazines"];
  11. _playerObject = _this;
  12. _spawnRadius = getNumber (configFile >> "CfgSettings" >> "LootSettings" >> "spawnRadius");
  13. _spawnChancePerPosition = (getNumber (configFile >> "CfgSettings" >> "LootSettings" >> "spawnChancePerPosition") max 0) min 99;
  14. _spawnChancePerBuilding = (getNumber (configFile >> "CfgSettings" >> "LootSettings" >> "spawnChancePerBuilding") max 0) min 99;
  15. _maximumNumberOfLootSpotsPerBuilding = getNumber (configFile >> "CfgSettings" >> "LootSettings" >> "maximumNumberOfLootSpotsPerBuilding");
  16. _maximumNumberOfItemsPerLootSpot = getNumber (configFile >> "CfgSettings" >> "LootSettings" >> "maximumNumberOfItemsPerLootSpot");
  17. _visualThreshold = getNumber (configFile >> "CfgSettings" >> "LootSettings" >> "visualThreshold");
  18. _spawnedLoot = false;
  19. _minimumDistanceToTraderZones = getNumber (configFile >> "CfgSettings" >> "LootSettings" >> "minimumDistanceToTraderZones");
  20. _minimumDistanceToTerritories = getNumber (configFile >> "CfgSettings" >> "LootSettings" >> "minimumDistanceToTerritories");
  21. try
  22. {
  23. if !(alive _playerObject) then
  24. {
  25. throw false;
  26. };
  27. if !(vehicle _playerObject isEqualTo _playerObject) then
  28. {
  29. throw false;
  30. };
  31. _playerPosition = getPosATL _playerObject;
  32. _lastKnownPlayerPosition = _playerObject getVariable["ExilePositionAtLastLootSpawnCircle", [0,0,0]];
  33. if (_lastKnownPlayerPosition distance2D _playerPosition < 11) then
  34. {
  35. throw false;
  36. };
  37. _playerObject setVariable["ExilePositionAtLastLootSpawnCircle", _playerPosition];
  38. _buildings = _playerPosition nearObjects ["House", _spawnRadius];
  39. _truckWrecks = _playerPosition nearObjects ["Land_Wreck_HMMWV_F", _spawnRadius];
  40. _buildings append _truckWrecks;
  41. _heliwrecks2 = _playerPosition nearObjects ["Land_UWreck_Heli_Attack_02_F", _spawnRadius];
  42. _buildings append _heliwrecks2;
  43. _heliWrecks1 = _playerPosition nearObjects ["Land_Wreck_Heli_Attack_01_F", _spawnRadius];
  44. _buildings append _heliWrecks1;
  45. {
  46. _building = _x;
  47. _buildingType = typeOf _building;
  48. if (isClass(configFile >> "CfgBuildings" >> _buildingType)) then
  49. {
  50. if !(_building getVariable ["ExileHasLoot", false]) then
  51. {
  52. if ((floor (random 100)) <= _spawnChancePerBuilding) then
  53. {
  54. _buildingPosition = getPosATL _building;
  55. if (_minimumDistanceToTraderZones > 0) then
  56. {
  57. if ([_buildingPosition, _minimumDistanceToTraderZones] call ExileClient_util_world_isTraderZoneInRange) then
  58. {
  59. throw false;
  60. };
  61. };
  62. if (_minimumDistanceToTerritories > 0) then
  63. {
  64. if ([_buildingPosition, _minimumDistanceToTerritories] call ExileClient_util_world_isTerritoryInRange) then
  65. {
  66. throw false;
  67. };
  68. };
  69. if !([_buildingPosition, _visualThreshold] call ExileClient_util_world_isAlivePlayerInfantryInRange) then
  70. {
  71. _buildingConfig = configFile >> "CfgBuildings" >> _buildingType;
  72. _lootTableName = getText (_buildingConfig >> "table");
  73. _localPositions = getArray (_buildingConfig >> "positions");
  74. _spawnedItemClassNames = [];
  75. _lootWeaponHolderNetIDs = [];
  76. _spawnedLootInThisBuilding = false;
  77. _localPositions = _localPositions call ExileClient_util_array_shuffle;
  78. {
  79. if (_forEachIndex isEqualTo (_maximumNumberOfLootSpotsPerBuilding - 1)) exitWith {};
  80. if ((floor (random 100)) <= _spawnChancePerPosition) then
  81. {
  82. _lootPosition = ASLToATL (AGLToASL (_building modelToWorld _x));
  83. if (_lootPosition select 2 < 0.05) then
  84. {
  85. _lootPosition set [2, 0.05];
  86. };
  87. _numberOfItemsToSpawn = (floor (random _maximumNumberOfItemsPerLootSpot)) + 1;
  88. _lootHolder = objNull;
  89. for "_n" from 1 to _numberOfItemsToSpawn do
  90. {
  91. _itemClassName = _lootTableName call ExileServer_system_lootManager_dropItem;
  92. if !(_itemClassName in _spawnedItemClassNames) then
  93. {
  94. _cargoType = _itemClassName call ExileClient_util_cargo_getType;
  95. if (isNull _lootHolder) then
  96. {
  97. _lootHolder = createVehicle ["LootWeaponHolder", _lootPosition, [], 0, "CAN_COLLIDE"];
  98. _lootHolder setDir (random 360);
  99. _lootHolder setPosATL _lootPosition;
  100. _lootHolder setVariable ["ExileSpawnedAt", time];
  101. _lootWeaponHolderNetIDs pushBack (netId _lootHolder);
  102. };
  103. switch (_cargoType) do
  104. {
  105. case 1:
  106. {
  107. if (_itemClassName isEqualTo "Exile_Item_MountainDupe") then
  108. {
  109. _lootHolder addMagazineCargoGlobal [_itemClassName, 2];
  110. }
  111. else
  112. {
  113. _lootHolder addMagazineCargoGlobal [_itemClassName, 1];
  114. };
  115. };
  116. case 3:
  117. {
  118. _lootHolder addBackpackCargoGlobal [_itemClassName, 1];
  119. };
  120. case 2:
  121. {
  122. _lootHolder addWeaponCargoGlobal [_itemClassName, 1];
  123. if (_itemClassName != "Exile_Melee_Axe") then
  124. {
  125. _magazineClassNames = getArray(configFile >> "CfgWeapons" >> _itemClassName >> "magazines");
  126. if (count(_magazineClassNames) > 0) then
  127. {
  128. _magazineClassName = _magazineClassNames select (floor(random (count _magazineClassNames)));
  129. _numberOfMagazines = 2 + floor(random 3);
  130. _lootHolder addMagazineCargoGlobal [_magazineClassName, _numberOfMagazines];
  131. };
  132. };
  133. };
  134. default { _lootHolder addItemCargoGlobal [_itemClassName,1]; };
  135. };
  136. _spawnedItemClassNames pushBack _itemClassName;
  137. _spawnedLoot = true;
  138. _spawnedLootInThisBuilding = true;
  139. };
  140. };
  141. };
  142. }
  143. forEach _localPositions;
  144. if (_spawnedLootInThisBuilding) then
  145. {
  146. ExileServerBuildingNetIdsWithLoot pushBack (netId _building);
  147. _building setVariable ["ExileLootSpawnedAt", time];
  148. _building setVariable ["ExileHasLoot", true];
  149. _building setVariable ["ExileLootWeaponHolderNetIDs", _lootWeaponHolderNetIDs];
  150. };
  151. };
  152. };
  153. };
  154. };
  155. }
  156. forEach _buildings;
  157. }
  158. catch
  159. {
  160. };
  161. _spawnedLoot
Advertisement
Add Comment
Please, Sign In to add comment