Guest User

spawn_loot.sqf

a guest
Dec 31st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1.  
  2. private ["_iItem","_iClass","_iPos","_radius","_iPosZ","_item","_itemTypes","_qty","_max","_index","_weights","_cntWeights","_tQty","_canType","_mags","_magQty","_uniq"];
  3.  
  4. _iItem = _this select 0;
  5. _iClass = _this select 1;
  6. _iPos = _this select 2;
  7. _radius = _this select 3;
  8. _uniq = ["ItemWaterbottle", "ItemWaterbottleUnfilled"];
  9.  
  10. _iPosZ = _iPos select 2;
  11. if((isNil "_iPosZ") OR {( _iPosZ < 0)}) then { _iPos = [_iPos select 0,_iPos select 1,0]; };
  12.  
  13. switch (_iClass) do {
  14. default {
  15. //Item is food, add random quantity of cans along with an item (if exists)
  16. _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  17.  
  18. _itemTypes = [];
  19. {
  20. _itemTypes set [count _itemTypes, _x select 0]
  21. } foreach getArray (configFile >> "CfgLoot" >> _iClass);
  22. _qty = 0;
  23. _max = ceil(random 2) + 1;
  24. while {_qty < _max} do {
  25. _index = dayz_CLBase find _iClass;
  26. _weights = dayz_CLChances select _index;
  27. _cntWeights = count _weights;
  28. _index = floor(random _cntWeights);
  29. _index = _weights select _index;
  30. _canType = _itemTypes select _index;
  31. _tQty = round(random 1) + 1;
  32. if (_canType in _uniq) then {
  33. _tQty = if (({_x in _uniq} count magazines _item) == 0) then {1} else {0};
  34. if (_tQty == 0) then {diag_log(format["%1 Prevent any duplicate member %2 from family %3",__FILE__, _canType, _uniq]);};
  35. //diag_log(format["%1 %2 DUP? type:%3 mag:%4 _this:%5",__FILE__, __LINE__, _canType, magazines _item, _this]);
  36. };
  37. if (_tQty > 0) then {
  38. _item addMagazineCargoGlobal [_canType,_tQty];
  39. _qty = _qty + _tQty;
  40. };
  41. };
  42. if (_iItem != "") then {
  43. _item addWeaponCargoGlobal [_iItem,1];
  44. };
  45. };
  46. case "weapon": {
  47. //Item is a weapon, add it and a random quantity of magazines
  48. _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  49. _item addWeaponCargoGlobal [_iItem,1];
  50. _mags = [] + getArray (configFile >> "cfgWeapons" >> _iItem >> "magazines");
  51. if ((count _mags) > 0) then {
  52. // if (_mags select 0 == "Quiver") then { _mags set [0, "WoodenArrow"] }; // Prevent spawning a Quiver
  53. if (!(_iItem in MeleeWeapons)) then {
  54. _magQty = round(random 10);
  55. if (_magQty > 3) then {
  56. _item addMagazineCargoGlobal [(_mags select 0), (round(random 1) + 1)];
  57. };
  58. };
  59. };
  60. };
  61. case "magazine": {
  62. //Item is one magazine
  63. _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  64. _item addMagazineCargoGlobal [_iItem,1];
  65. };
  66. case "object": {
  67. //Item is one magazine
  68. _item = createVehicle [_iItem, _iPos, [], _radius, "CAN_COLLIDE"];
  69. };
  70. };
  71. if ((count _iPos) > 2) then {
  72. _item setPosATL _iPos;
  73. };
  74.  
  75. _item // used in server_spawnCrashSite
Add Comment
Please, Sign In to add comment