Guest User

building_spawnLoot.sqf

a guest
Dec 31st, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1.  
  2. private ["_obj","_type", "_config", "_positions", "_itemTypes", "_lootChance", "_countPositions", "_bias", "_rnd", "_iPos", "_nearBy", "_index", "_weights", "_cntWeights", "_itemType", "_qty", "_i"];
  3.  
  4. _obj = _this;
  5. _type = typeOf _obj;
  6. _config = missionConfigFile >> dayzNam_buildingLoot >> _type;
  7. _positions = [] + getArray (_config >> "lootPos");
  8. _itemTypes = [] + getArray (_config >> "lootType");
  9. _lootChance = getNumber (_config >> "lootChance");
  10. _countPositions = count _positions;
  11. _qty = 0; // effective quantity of spawned weaponholder
  12.  
  13. // bias for this building. The lower it is, the lower chance some of the lootpiles will spawn
  14. _bias = 50 max dayz_lootSpawnBias;
  15. _bias = 100 min _bias;
  16. _bias = (_bias + random(100-_bias)) / 100;
  17. //diag_log(format["BIAS:%1 LOOTCHANCE:%2", _bias, _lootChance]);
  18. {
  19. if (count _x == 3) then {
  20. _rnd = (random 1) / _bias;
  21. //diag_log (_type + " ][ " + str(_x));
  22. _iPos = _obj modelToWorld _x;
  23. _nearBy = nearestObjects [_iPos, ["ReammoBox"], 2];
  24.  
  25. if (count _nearBy > 0) then {
  26. _lootChance = _lootChance + 0.05;
  27. };
  28.  
  29. if (_rnd <= _lootChance) then {
  30. if (count _nearBy == 0) then {
  31. //diag_log (str(dayz_CBLBase));
  32. //diag_log ("_type: " +str(_type));
  33. //_index = dayz_CBLBase find _type;
  34. _i = 0;
  35. _index = 0;
  36. {
  37. if (_x == _type) then {
  38. _index = _i;
  39. } else {
  40. _i = _i + 1;
  41. };
  42. } forEach dayz_CBLBase;
  43. //diag_log ("index: " +str(_index));
  44. _weights = dayz_CBLChances select _index;
  45. //diag_log ("weights: " +str(_weights));
  46. _cntWeights = count _weights;
  47. //diag_log ("cntWeights: " +str(_cntWeights));
  48. _index = floor(random _cntWeights);
  49. //diag_log ("_index: " +str(_index));
  50. _index = _weights select _index;
  51. //diag_log ("_index: " +str(_index));
  52. _itemType = _itemTypes select _index;
  53. //diag_log ("_itemType: " +str(_itemType));
  54. //diag_log format["Item: %1, Group: %2", _itemType select 0, _itemType select 1];
  55. [_itemType select 0, _itemType select 1 , _iPos, 0.0] call spawn_loot;
  56. _qty = _qty +1;
  57. };
  58. };
  59. sleep ((random 3) / 1000);
  60. } else {
  61. diag_log(format["%1 Illegal loot position #%3 from %2 in building %4 -- skipped", __FILE__,
  62. configName _config, _forEachIndex+1, typeOf _obj]);
  63. };
  64. } forEach _positions;
  65.  
  66. _qty
Advertisement
Add Comment
Please, Sign In to add comment