Rossymond

spawn_loot.sqf

May 30th, 2013
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. private["_iItem","_iClass","_iPos","_radius","_itemTypes","_index","_item","_qty","_max","_tQty","_canType","_weights","_cntWeights","_dateNow"];
  2. _iItem = _this select 0;
  3. _iClass = _this select 1;
  4. _iPos = _this select 2;
  5. _radius = _this select 3;
  6.  
  7. switch (_iClass) do {
  8. default {
  9. //Item is food, add random quantity of cans along with an item (if exists)
  10. _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  11.  
  12. _itemTypes = [] + ((getArray (missionconfigFile >> "cfgLoot" >> _iClass)) select 0);
  13. _index = dayz_CLBase find _iClass;
  14. _weights = dayz_CLChances select _index;
  15. _cntWeights = count _weights;
  16. _qty = 0;
  17. _max = ceil(random 2) + 1;
  18. while {_qty < _max} do {
  19. _tQty = round(random 1) + 1;
  20. _index = floor(random _cntWeights);
  21. _index = _weights select _index;
  22. _canType = _itemTypes select _index;
  23. _item addMagazineCargoGlobal [_canType,_tQty];
  24. _qty = _qty + _tQty;
  25. };
  26. if (_iItem != "") then {
  27. _item addWeaponCargoGlobal [_iItem,1];
  28. };
  29. };
  30. case "weapon": {
  31. //Item is a weapon, add it and a random quantity of magazines
  32. _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  33. _item addWeaponCargoGlobal [_iItem,1];
  34. _mags = [] + getArray (configFile >> "cfgWeapons" >> _iItem >> "magazines");
  35. if ((count _mags) > 0) then {
  36. if (_mags select 0 == "Quiver") then { _mags set [0, "WoodenArrow"] }; // Prevent spawning a Quiver
  37. _item addMagazineCargoGlobal [(_mags select 0), (round(random 2))];
  38. };
  39. };
  40. case "magazine": {
  41. //Item is one magazine
  42. _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  43. _item addMagazineCargoGlobal [_iItem,1];
  44. };
  45. case "object": {
  46. //Item is one magazine
  47. _item = createVehicle [_iItem, _iPos, [], _radius, "CAN_COLLIDE"];
  48. };
  49. };
  50.  
  51. // timestamp for later clearing
  52. _dateNow = (DateToNumber date);
  53. _item setVariable ["looted",_dateNow,true];
  54.  
  55. if ((count _iPos) > 2) then {
  56. _item setPosATL _iPos;
  57. };
Advertisement
Add Comment
Please, Sign In to add comment