Saethkept

custom spawn_loot.sqf (Chernarus)

May 10th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.92 KB | None | 0 0
  1. private["_iItem","_iClass","_iPos","_obj","_type","_config","_itemChances","_lootChance","_cfgLoot","_radius","_itemTypes","_index","_item","_qty","_max","_tQty","_canType","_weights","_cntWeights","_dateNow"];
  2.  
  3.  
  4. _iItem =    _this select 0;
  5. _iClass =   _this select 1;
  6. _iPos =     _this select 2;
  7. _radius =   _this select 3;
  8. _obj =      _this select 0;
  9. _type =     typeOf _obj;
  10. _config =   configFile >> "cfgLoot" >> _type;
  11. _lootChance = getNumber (_config >> "lootChance");
  12.  
  13.  
  14.  
  15. //Custom Loot Config. //
  16. //___________________//
  17.  
  18.  
  19. _itemTypes = []; //Initialise array
  20. _itemChance = []; //Initialise array
  21.  
  22.  
  23. switch (_cfgLoot) do {
  24.     case "Trash": {
  25.         _itemTypes = [
  26.             ["TrashTinCan"],
  27.             ["TrashJackDaniels"],
  28.             ["ItemSodaEmpty"],
  29.             ["ItemTrashToiletpaper"],
  30.             ["ItemTrashRazor"]
  31.            
  32.         ];
  33.         _itemChance = [
  34.             1,
  35.             0.1,
  36.             0.5,
  37.             0.4,
  38.             0.2
  39.            
  40.         ];
  41.     };
  42.     case "Civilian": {
  43.         _itemTypes = [
  44.             ["TrashTinCan"],
  45.             ["TrashJackDaniels"],
  46.             ["ItemSodaEmpty"],
  47.             ["ItemSodaCoke"],
  48.             ["ItemSodaPepsi"],
  49.             ["FoodCanBakedBeans"],
  50.             ["FoodCanSardines"],
  51.             ["FoodCanFrankBeans"],
  52.             ["FoodCanPasta"],
  53.             ["8Rnd_9x18_Makarov"],
  54.             ["7Rnd_45ACP_1911"],
  55.             ["2Rnd_shotgun_74Slug"],
  56.             ["2Rnd_shotgun_74Pellets"],
  57.             ["ItemBandage"],
  58.             ["ItemPainkiller"]
  59.            
  60.         ];
  61.         _itemChance = [
  62.             0.09,
  63.             0.09,
  64.             0.09,
  65.             0.12,
  66.             0.09,
  67.             0.05,
  68.             0.05,
  69.             0.05,
  70.             0.05,
  71.             0.07,
  72.             0.05,
  73.             0.05,
  74.             0.05,
  75.             0.06,
  76.             0.06
  77.            
  78.         ];
  79.     };
  80.     case "Food": {
  81.         _itemTypes = [
  82.             ["TrashTinCan"],
  83.             ["TrashJackDaniels"],
  84.             ["ItemSodaEmpty"],
  85.             ["ItemSodaCoke"],
  86.             ["ItemSodaPepsi"],
  87.             ["FoodCanBakedBeans"],
  88.             ["FoodCanSardines"],
  89.             ["FoodCanFrankBeans"],
  90.             ["FoodCanPasta"],
  91.             ["FoodCanUnlabeled"],
  92.             //Bags
  93.             ["FoodPistachio"],
  94.             ["FoodNutmix"]
  95.            
  96.         ];
  97.         _itemChance = [
  98.             0.13,
  99.             0.13,
  100.             0.13,
  101.             0.09,
  102.             0.13,
  103.             0.09,
  104.             0.09,
  105.             0.09,
  106.             0.09,
  107.             0.06,
  108.             //Bags
  109.             0.05,
  110.             0.04
  111.            
  112.         ];
  113.     };
  114.     case "Generic": {
  115.         _itemTypes = [
  116.             ["TrashTinCan"],
  117.             ["ItemSodaEmpty"],
  118.             ["ItemSodaCoke"],
  119.             ["ItemSodaPepsi"],
  120.             ["TrashJackDaniels"],
  121.             ["FoodCanBakedBeans"],
  122.             ["FoodCanSardines"],
  123.             ["FoodCanFrankBeans"],
  124.             ["FoodCanPasta"],
  125.             ["ItemWaterbottleUnfilled"],
  126.             ["ItemWaterbottle"],
  127.             ["ItemBandage"],
  128.             ["7Rnd_45ACP_1911"],
  129.             ["5x_22_LR_17_HMR"],
  130.             ["10x_303"],
  131.             ["6Rnd_45ACP"],
  132.             ["2Rnd_shotgun_74Slug"],
  133.             ["2Rnd_shotgun_74Pellets]",
  134.             ["8Rnd_9x18_Makarov"],
  135.             ["15Rnd_W1866_Slug"],
  136.             ["WoodenArrow"],
  137.             ["HandRoadFlare"],
  138.             ["ItemPainkiller"],
  139.             ["HandChemGreen"],
  140.             ["HandChemBlue"],
  141.             ["HandChemRed"],
  142.             ["ItemHeatPack"]
  143.            
  144.         ];
  145.         _itemChance = [
  146.             0.06,
  147.             0.06,
  148.             0.06,
  149.             0.04,
  150.             0.04,
  151.             0.01,
  152.             0.01,
  153.             0.01,
  154.             0.01,
  155.             0.01,
  156.             0.01,
  157.             0.11,
  158.             0.03,
  159.             0.01,
  160.             0.04,
  161.             0.04,
  162.             0.05,
  163.             0.05,
  164.             0.09,
  165.             0.02,
  166.             0.04,
  167.             0.07,
  168.             0.02,
  169.             0.01,
  170.             0.03,
  171.             0.03,
  172.             0.04
  173.        
  174.         ];
  175.     };
  176.     case "Hospital": {
  177.         _itemTypes = [
  178.             ["ItemBandage"],
  179.             ["ItemPainkiller"],
  180.             ["ItemMorphine"],
  181.             ["ItemEpinephrine"],
  182.             ["ItemBloodbag"],
  183.             ["ItemAntibiotic"]
  184.            
  185.         ];
  186.         _itemChance = [
  187.             0.33,
  188.             0.17,
  189.             0.13,
  190.             0.09,
  191.             0.17,
  192.             0.12
  193.            
  194.         ];
  195.     };
  196.     case "Military": {
  197.         _itemTypes = [
  198.             ["TrashTinCan"],
  199.             ["ItemSodaEmpty"],
  200.             ["ItemSodaCoke"],
  201.             ["ItemSodaPepsi"],
  202.             ["ItemBandage"],
  203.             ["ItemAntibiotic"],
  204.             ["ItemPainkiller"],
  205.             ["ItemMorphine"],
  206.             ["30Rnd_556x45_Stanag"],
  207.             ["20Rnd_762x51_DMR"],
  208.             ["17Rnd_9x19_glock17"],
  209.             ["15Rnd_9x19_M9SD"],
  210.             ["15Rnd_9x19_M9"],
  211.             ["30Rnd_762x39_AK47"],
  212.             ["30Rnd_545x39_AK"],
  213.             ["5Rnd_762x51_M24"],
  214.             ["10Rnd_127x99_m107"],
  215.             ["8Rnd_B_Beneli_74Slug"],
  216.             ["1Rnd_HE_M203"],
  217.             ["FlareWhite_M203"],
  218.             ["FlareGreen_M203"],
  219.             ["1Rnd_Smoke_M203"],       
  220.             ["200Rnd_556x45_M249"],
  221.             ["HandGrenade_west"],
  222.             ["SmokeShell"],
  223.             ["SmokeShellRed"],
  224.             ["SmokeShellGreen"],
  225.             ["8Rnd_B_Beneli_Pellets"],
  226.             ["30Rnd_556x45_StanagSD"],
  227.             ["30Rnd_9x19_MP5"],
  228.             ["30Rnd_9x19_MP5SD"],
  229.             ["100Rnd_762x51_M240"],
  230.             ["HandChemGreen"],
  231.             ["HandChemBlue"],
  232.             ["HandChemRed"],
  233.             ["ItemHeatPack"],
  234.             ["FoodMRE"]
  235.            
  236.         ];
  237.         _itemChance = [
  238.             0.18,
  239.             0.09,
  240.             0.01,
  241.             0.01,
  242.             0.04,
  243.             0.04,
  244.             0.04,
  245.             0.01,
  246.             0.04,
  247.             0.04,
  248.             0.05,
  249.             0.01,
  250.             0.02,
  251.             0.04,
  252.             0.04,
  253.             0.01,
  254.             0.01,
  255.             0.04,
  256.             0.01,
  257.             0.01,
  258.             0.01,
  259.             0.01,
  260.             0.01,
  261.             0.01,
  262.             0.04,
  263.             0.02,
  264.             0.02,
  265.             0.04,
  266.             0.01,
  267.             0.02,
  268.             0.01,
  269.             0.01,
  270.             0.02,
  271.             0.02,
  272.             0.02,
  273.             0.04,
  274.             0.03
  275.            
  276.         ];
  277.     };
  278.     case "Policeman": {
  279.         _itemTypes = [
  280.             ["ItemBandage"],
  281.             ["7Rnd_45ACP_1911"],
  282.             ["6Rnd_45ACP"],
  283.             ["15Rnd_W1866_Slug"],
  284.             ["8Rnd_B_Beneli_74Slug"],
  285.             ["HandRoadFlare"]
  286.            
  287.         ];
  288.         _itemChance = [
  289.             1,
  290.             0.8,
  291.             0.3,
  292.             0.3,
  293.             0.5,
  294.             0.3
  295.            
  296.         ];
  297.     };
  298.     case "Hunter": {
  299.         _itemTypes = [
  300.             ["ItemBandage"],
  301.             ["5x_22_LR_17_HMR"],
  302.             ["7Rnd_45ACP_1911"],
  303.             ["10x_303"],
  304.             ["ItemWaterbottleUnfilled"],
  305.             ["WoodenArrow"],
  306.             ["ItemHeatPack"],
  307.             ["FoodMRE"],
  308.             ["FoodNutmix"]
  309.            
  310.         ];
  311.         _itemChance = [
  312.             1,
  313.             0.5,
  314.             0.2,
  315.             0.5,
  316.             0.2,
  317.             1,
  318.             0.2,
  319.             0.04,
  320.             0.1
  321.            
  322.         ];
  323.     }:
  324.  
  325. };
  326.  
  327. //Custom Loot Cfg.//
  328. //________________//
  329.  
  330. switch (_iClass) do {
  331.     default {
  332.         //Item is food, add random quantity of cans along with an item (if exists)
  333.         _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  334.  
  335.         _itemTypes = _itemTypes select _index;
  336.         _index = _weights call BIS_fnc_selectRandom;
  337.         _weights = [_itemTypes,_itemChance] call fnc_buildWeightedArray;
  338.         _cntWeights = count _weights;
  339.         _qty = 0;
  340.         _max = ceil(random 2) + 1;
  341.         while {_qty < _max} do {
  342.             _tQty = round(random 1) + 1;
  343.             _index = floor(random _cntWeights);
  344.             _index = _weights select _index;
  345.             _canType = _itemTypes select _index;
  346.             _item addMagazineCargoGlobal [_canType,_tQty];
  347.             _qty = _qty + _tQty;
  348.         };
  349.         if (_iItem != "") then {
  350.             _item addWeaponCargoGlobal [_iItem,1];
  351.         };
  352.     };
  353.     case "weapon": {
  354.         //Item is a weapon, add it and a random quantity of magazines
  355.         _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  356.         _item addWeaponCargoGlobal [_iItem,1];
  357.         _mags = [] + getArray (configFile >> "cfgWeapons" >> _iItem >> "magazines");
  358.         if ((count _mags) > 0) then {
  359.             if (_mags select 0 == "Quiver") then { _mags set [0, "WoodenArrow"] }; // Prevent spawning a Quiver
  360.             _item addMagazineCargoGlobal [(_mags select 0), (round(random 2))];
  361.         };
  362.     };
  363.     case "magazine": {
  364.         //Item is one magazine
  365.         _item = createVehicle ["WeaponHolder", _iPos, [], _radius, "CAN_COLLIDE"];
  366.         _item addMagazineCargoGlobal [_iItem,1];
  367.     };
  368.     case "object": {
  369.         //Item is one magazine
  370.         _item = createVehicle [_iItem, _iPos, [], _radius, "CAN_COLLIDE"];
  371.     };
  372. };
  373.  
  374. // timestamp for later clearing
  375. _dateNow = (DateToNumber date);
  376. _item setVariable ["looted",_dateNow,true];
  377.  
  378. if ((count _iPos) > 2) then {
  379.     _item setPosATL _iPos;
  380. };
Advertisement
Add Comment
Please, Sign In to add comment