Saethkept

building_spawnLoot.sqf (credit to Seven) adapted for Tavi 2.

Apr 5th, 2013
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.94 KB | None | 0 0
  1. private["_obj","_type","_config","_positions","_iPos","_nearBy","_itemType","_itemTypes","_itemChances","_lootChance","_weights","_cntWeights","_index","_LootClass"];
  2.  
  3. _obj =          _this select 0;
  4. _type =         typeOf _obj;
  5. _config =       configFile >> "CfgBuildingLoot" >> _type;
  6. _positions =    [] + getArray (_config >> "lootPos");
  7. //_itemTypes =  [] + getArray (_config >> "itemType"); // Default System
  8. _lootChance =   getNumber (_config >> "lootChance");
  9.  
  10. //------------------//
  11. //CUSTOM LOOT SPAWNS//
  12. //------------------//
  13. _itemTypes = []; //Initialise array
  14. _itemChance = []; //Initialise array
  15.  
  16. diag_log "SPAWNING WITH CUSTOM LOOT";//Remove This line after testing
  17.  
  18. switch (_type) do { //Assign building classes
  19.     case "Land_HouseV_1I4": { _LootClass = "Residential"; };
  20.     case "Land_kulna": { _LootClass = "Residential"; };
  21.     case "Land_Ind_Workshop01_04": { _LootClass = "Industrial"; };
  22.     case "Land_hut06": { _LootClass = "Residential"; };
  23.     case "Land_Hlidac_budka": { _LootClass = "Residential"; };
  24.     case "Land_HouseV2_02_Interier": { _LootClass = "Residential"; };
  25.     case "Land_A_Pub_01": { _LootClass = "Residential"; };
  26.     case "Land_Shed_wooden": { _LootClass = "Residential"; };
  27.     case "Land_HouseBlock_A1_1": { _LootClass = "Residential"; };
  28.     case "Land_A_MunicipalOffice": { _LootClass = "Residential"; };
  29.     case "Land_ruin_01": { _LootClass = "Residential"; };
  30.     case "Land_HouseV2_04_interier": { _LootClass = "Residential"; };
  31.     case "Land_HouseV2_01A": { _LootClass = "Residential"; };
  32.     case "Land_psi_bouda": { _LootClass = "Residential"; };
  33.     case "Land_KBud": { _LootClass = "Residential"; };
  34.     case "Land_A_Castle_Bergfrit": { _LootClass = "Residential"; };
  35.     case "Land_A_Castle_Stairs_A": { _LootClass = "Residential"; };
  36.     case "Land_A_Castle_Gate": { _LootClass = "Residential"; };
  37.     case "Land_sara_domek_zluty": { _LootClass = "Residential"; };
  38.     case "Land_Church_01": { _LootClass = "Residential"; };
  39.     case "Land_Church_03": { _LootClass = "Residential"; };
  40.     case "Land_HouseB_Tenement": { _LootClass = "Residential"; };
  41.     case "Land_Panelak": { _LootClass = "Residential"; };
  42.     case "Land_Panelak2": { _LootClass = "Residential"; };
  43.     case "Land_rail_station_big": { _LootClass = "Residential"; };
  44.     case "Land_A_Office01": { _LootClass = "Residential"; };
  45.     case "Land_A_Office02": { _LootClass = "Residential"; };
  46.     case "Land_Ind_Workshop01_01": { _LootClass = "Industrial"; };
  47.     case "Land_Ind_Garage01": { _LootClass = "Industrial"; };
  48.     case "Land_Ind_Workshop01_02": { _LootClass = "Industrial"; };
  49.     case "Land_Ind_Workshop01_L": { _LootClass = "Industrial"; };
  50.     case "Land_Hangar_2": { _LootClass = "Industrial"; };
  51.     case "Land_A_FuelStation_Build": { _LootClass = "Industrial"; };
  52.     case "Land_Shed_Ind02": { _LootClass = "Industrial"; };
  53.     case "Land_Misc_PowerStation": { _LootClass = "Industrial"; };
  54.     case "Land_Shed_W01": { _LootClass = "Industrial"; };
  55.     case "Land_Tovarna2": { _LootClass = "Industrial"; };
  56.     case "Land_Ind_Vysypka": { _LootClass = "Industrial"; };
  57.     case "Land_A_BuildingWIP": { _LootClass = "Industrial"; };
  58.     case "Land_A_TVTower_Base": { _LootClass = "Industrial"; };
  59.     case "Land_Misc_Cargo1Ao": { _LootClass = "Industrial"; };
  60.     case "Land_Misc_Cargo1Bo": { _LootClass = "Industrial"; };
  61.     case "Land_Nav_Boathouse": { _LootClass = "Industrial"; };
  62.     case "Land_wagon_box": { _LootClass = "Industrial"; };
  63.     case "Land_Rail_House_01": { _LootClass = "Industrial"; };
  64.     case "Land_A_GeneralStore_01a": { _LootClass = "Supermarket"; };
  65.     case "Land_A_GeneralStore_01": { _LootClass = "Supermarket"; };
  66.     case "Land_A_Hospital": { _LootClass = "Hospital"; };
  67.     case "MASH": { _LootClass = "Hospital"; };
  68.     case "MASH_EP1": { _LootClass = "Hospital"; };
  69.     case "USMC_WarfareBFieldhHospital": { _LootClass = "Hospital"; };
  70.     case "Land_a_stationhouse": { _LootClass = "Military"; };
  71.     case "Land_Mil_ControlTower": { _LootClass = "Military"; };
  72.     case "Land_SS_hangar": { _LootClass = "Military"; };
  73.     case "Land_Mil_House": { _LootClass = "Military"; };
  74.     case "Camp": { _LootClass = "Military"; };
  75.     case "CampEast": { _LootClass = "Military"; };
  76.     case "CampEast_EP1": { _LootClass = "Military"; };
  77.     case "Land_Mil_Barracks_i": { _LootClass = "MilitarySpecial"; };
  78.     case "Land_Misc_deerstand": { _LootClass = "Military"; };
  79.     case "Land_stodola_old_open": { _LootClass = "Farm"; };
  80.     case "Land_Farm_Cowshed_a": { _LootClass = "Farm"; };
  81.     case "Land_stodola_open": { _LootClass = "Farm"; };
  82.     case "Land_Barn_W_01": { _LootClass = "Farm"; };
  83.     case "Land_Mil_Barracks": { _LootClass = "Military"; };
  84.     case "Land_Mil_Barracks_L": { _LootClass = "Military"; };
  85.     case "Land_Barn_W_02": { _LootClass = "Farm"; };
  86.     default { _LootClass = "Residential"; };
  87. };
  88.  
  89. switch (_LootClass) do { //Find correct loot
  90.     case "Residential": {
  91.         _itemTypes = [
  92.             ["ItemSodaMdew","magazine"],
  93.             ["ItemWatch","generic"],
  94.             ["ItemCompass","generic"],
  95.             ["ItemMap","weapon"],
  96.             ["Makarov","weapon"],
  97.             ["Colt1911","weapon"],
  98.             ["ItemFlashlight","generic"],
  99.             ["ItemKnife","generic"],
  100.             ["ItemMatchbox","generic"],
  101.             ["","generic"],
  102.             ["LeeEnfield","weapon"],
  103.             ["revolver_EP1","weapon"],
  104.            
  105.             ["CZ_VestPouch_EP1","object"], // 12
  106.             ["DZ_CivilBackpack_EP1","object"], // 12-0
  107.             ["DZ_ALICE_Pack_EP1","object"],
  108.             ["Winchester1866","weapon"],
  109.             ["WeaponHolder_ItemTent","object"],
  110.             ["","military"],
  111.             ["","trash"],
  112.             ["Crossbow","weapon"],
  113.             ["Binocular","weapon"],
  114.             ["PartWoodPile","magazine"],
  115.             ["Skin_Camo1_DZ","magazine"],
  116.             ["Skin_Sniper1_DZ","magazine"],
  117.             ["WeaponHolder_MeleeCrowbar","object"],
  118.             ["MR43","weapon"] // Remember the last object doesn't not need a comma
  119.          ];
  120.         _itemChance = [
  121.             0.01,
  122.             0.15,
  123.             0.05,
  124.             0.03,
  125.             0.13,
  126.             0.05,
  127.             0.03,
  128.             0.08,
  129.             0.06,
  130.             2,
  131.             0.06,
  132.             0.04,
  133.             0.05, //12
  134.             0.04, // 12-0
  135.             0.02, //16
  136.             0.01,
  137.             0.01,
  138.             0.03,
  139.             0.5,
  140.             0.01,
  141.             0.06,
  142.             0.06,
  143.             0.01,
  144.             0.01,
  145.             0.08,
  146.             0.03
  147.         ];
  148.     };
  149.     case "Industrial": {
  150.         _itemTypes = [
  151.             ["","generic"],
  152.             ["","trash"],
  153.             ["","military"],
  154.             ["WeaponHolder_PartGeneric","object"],
  155.             ["WeaponHolder_PartWheel","object"],
  156.             ["WeaponHolder_PartFueltank","object"],
  157.             ["WeaponHolder_PartEngine","object"],
  158.             ["WeaponHolder_PartGlass","object"],
  159.             ["WeaponHolder_PartVRotor","object"],
  160.             ["WeaponHolder_ItemJerrycan","object"],
  161.             ["WeaponHolder_ItemHatchet","object"],
  162.             ["ItemKnife","military"],
  163.             ["ItemToolbox","weapon"],
  164.             ["ItemWire","magazine"],
  165.             ["ItemTankTrap","magazine"]
  166.         ];
  167.         _itemChance = [
  168.             0.18,
  169.             0.29,
  170.             0.04,
  171.             0.04,
  172.             0.05,
  173.             0.02,
  174.             0.02,
  175.             0.04,
  176.             0.01,
  177.             0.04,
  178.             0.11,
  179.             0.07,
  180.             0.06,
  181.             0.01,
  182.             0.04
  183.         ];
  184.     };
  185.     case "Farm": {
  186.         _itemTypes = [
  187.             ["WeaponHolder_ItemJerrycan","object"],
  188.             ["","generic"],
  189.             ["huntingrifle","weapon"],
  190.             ["LeeEnfield","weapon"],
  191.             ["Winchester1866","weapon"],
  192.             ["","trash"],
  193.             ["Crossbow","weapon"],
  194.             ["PartWoodPile","magazine"],
  195.             ["WeaponHolder_ItemHatchet","object"],
  196.             ["MR43","weapon"],
  197.             ["TrapBear","magazine"]
  198.         ];
  199.         _itemChance = [
  200.             0.06,
  201.             0.28,
  202.             0.01,
  203.             0.04,
  204.             0.03,
  205.             0.22,
  206.             0.03,
  207.             0.11,
  208.             0.17,
  209.             0.06,
  210.             0.03
  211.         ];
  212.     };
  213.     case "Supermarket": {
  214.         _itemTypes = [
  215.             ["ItemWatch","generic"],
  216.             ["ItemCompass","generic"],
  217.             ["ItemMap","weapon"],
  218.             ["Makarov","weapon"],
  219.             ["Colt1911","weapon"],
  220.             ["ItemFlashlight","generic"],
  221.             ["ItemKnife","generic"],
  222.             ["ItemMatchbox","generic"],
  223.             ["","generic"],
  224.             ["LeeEnfield","weapon"],
  225.             ["revolver_EP1","weapon"],
  226.                    
  227.             ["CZ_VestPouch_EP1","object"], // 12
  228.             ["DZ_CivilBackpack_EP1","object"], // 12-0
  229.             ["DZ_ALICE_Pack_EP1","object"], // 16
  230.             ["Winchester1866","weapon"],
  231.             ["WeaponHolder_ItemTent","object"],
  232.             ["","food"],
  233.             ["","trash"],
  234.             ["Crossbow","weapon"],
  235.             ["Binocular","weapon"],
  236.             ["PartWoodPile","magazine"],
  237.             ["MR43","weapon"]
  238.         ];
  239.         _itemChance = [
  240.             0.15,
  241.             0.01,
  242.             0.05,
  243.             0.02,
  244.             0.02,
  245.             0.05,
  246.             0.02,
  247.             0.05,
  248.             0.05,
  249.             0.01,
  250.             0.01,
  251.             0.05, //12
  252.             0.04, // 12-0
  253.             0.02, //16
  254.             0.01,
  255.             0.01,
  256.             0.3,
  257.             0.15,
  258.             0.01,
  259.             0.05,
  260.             0.02,
  261.             0.01
  262.         ];
  263.     };
  264.     case "Hospital": {
  265.         _itemTypes =    [
  266.             ["","trash"],
  267.             ["","hospital"],
  268.             ["MedBox0","object"]
  269.         ];
  270.         _itemChance = [
  271.             0.2,
  272.             1,
  273.             0.2
  274.         ];
  275.     };
  276.     case "Military": {
  277.         _itemTypes = [
  278.             ["M9","weapon"],
  279.             ["M16A2","weapon"],
  280.             ["M16A2GL","weapon"],
  281.             ["M9SD","weapon"],
  282.             ["AK_74","weapon"],
  283.             ["M4A1_Aim","weapon"],
  284.             ["AKS_74_kobra","weapon"],
  285.             ["AKS_74_U","weapon"],
  286.             ["AK_47_M","weapon"],
  287.             ["M24","weapon"],
  288.             ["M1014","weapon"],
  289.             ["DMR","weapon"],
  290.             ["M4A1","weapon"],
  291.             ["M14_EP1","weapon"],
  292.             ["UZI_EP1","weapon"],
  293.             ["Remington870_lamp","weapon"],
  294.             ["glock17_EP1","weapon"],
  295.             ["MP5A5","weapon"],
  296.             ["MP5SD","weapon"],
  297.             ["M4A3_CCO_EP1","weapon"],
  298.             ["Binocular","weapon"],
  299.             ["ItemFlashlightRed","military"],
  300.             ["ItemKnife","military"],
  301.             ["ItemGPS","weapon"],
  302.             ["ItemMap","military"],
  303.            
  304.             ["DZ_Assault_Pack_EP1","object"], // 16
  305.             ["DZ_Patrol_Pack_EP1","object"], // 16
  306.             ["DZ_Backpack_EP1","object"], // 24
  307.            
  308.             //Normal
  309.             ["","medical"],
  310.             ["","generic"],
  311.             ["","military"],
  312.             //["Body","object"],
  313.             ["ItemEtool","weapon"],
  314.             ["ItemSandbag","magazine"]
  315.         ];
  316.         _itemChance = [
  317.             0.05,
  318.             0.05,
  319.             0.01,
  320.             0.02,
  321.             0.15,
  322.             0.01,
  323.             0.08,
  324.             0.05,
  325.             0.05,
  326.             0.01,
  327.             0.10,
  328.             0.01,
  329.             0.02,
  330.             0.01,
  331.             0.05,
  332.             0.08,
  333.             0.10,
  334.             0.04,
  335.             0.02,
  336.             0.01,
  337.             0.06,
  338.             0.10,
  339.             0.10,
  340.             0.01,
  341.             0.05,
  342.             //Bags
  343.             0.08, //16
  344.             0.08, //16
  345.             0.01, //DZ_Backpack_EP1 24
  346.             0.10,
  347.             1.00,
  348.             2.50,
  349.             //0.20,
  350.             0.05,
  351.             0.02
  352.         ];
  353.     };
  354.     case "MilitarySpecial": {
  355.         _itemTypes = [
  356.             ["M16A2","weapon"],
  357.             ["M16A2GL","weapon"],
  358.             ["M249_DZ","weapon"],
  359.             ["M9SD","weapon"],
  360.             //["M136","weapon"],
  361.             ["AK_74","weapon"],
  362.             ["M4A1_Aim","weapon"],
  363.             ["AKS_74_kobra","weapon"],
  364.             ["AKS_74_U","weapon"],
  365.             ["AK_47_M","weapon"],
  366.             ["M24","weapon"],
  367.             ["SVD_CAMO","weapon"],
  368.             ["M1014","weapon"],
  369.             ["M107_DZ","weapon"],
  370.             ["DMR","weapon"],
  371.             ["M4A1","weapon"],
  372.             ["M14_EP1","weapon"],
  373.             ["UZI_EP1","weapon"],
  374.             ["Remington870_lamp","weapon"],
  375.             ["glock17_EP1","weapon"],
  376.             ["M240_DZ","weapon"],
  377.             ["M4A1_AIM_SD_camo","weapon"],
  378.             ["M16A4_ACG","weapon"],
  379.             ["M4A1_HWS_GL_camo","weapon"],
  380.             ["Mk_48_DZ","weapon"],
  381.             ["M4A3_CCO_EP1","weapon"],
  382.             //Ammo
  383.             ["AmmoBoxSmall_556","object"],
  384.             ["AmmoBoxSmall_762","object"],
  385.  
  386.             ["NVGoggles","weapon"],
  387.             ["Binocular","weapon"],
  388.             ["ItemFlashlightRed","military"],
  389.             ["ItemKnife","military"],
  390.             ["ItemGPS","weapon"],
  391.             ["ItemMap","military"],
  392.             ["Binocular_Vector","military"],
  393.  
  394.             ["DZ_Assault_Pack_EP1","object"], // 16
  395.             ["DZ_Patrol_Pack_EP1","object"], // 16
  396.             ["DZ_Backpack_EP1","object"], // 18
  397.  
  398.             ["","medical"],
  399.             ["","generic"],
  400.             ["","military"],
  401.             //["Body","object"],
  402.             ["PipeBomb","magazine"]
  403.         ];
  404.         _itemChance = [
  405.             0.10,
  406.             0.05,
  407.             0.01,
  408.             0.02,
  409.             //0.01, //m136
  410.             0.10,
  411.             0.02,
  412.             0.10,
  413.             0.10,
  414.             0.10,
  415.             0.01,
  416.             0.01,
  417.             0.20,
  418.             0.01,
  419.             0.02,
  420.             0.10,
  421.             0.03,
  422.             0.20,
  423.             0.10,
  424.             0.20,
  425.             0.01,
  426.             0.04,
  427.             0.05,
  428.             0.02,
  429.             0.01,
  430.             0.08,
  431.             0.04,
  432.             0.02,
  433.             0.01, //NVGoggles
  434.             0.10,
  435.             0.05,
  436.             0.15,
  437.             0.01, //ItemGPS
  438.             0.03,
  439.             0.01,
  440.             //Bags
  441.             0.08, //16
  442.             0.08, //16
  443.             0.06, //18
  444.             0.30,
  445.             1.00,
  446.             5.00, //military
  447.             //0.20,
  448.             0.01 //PipeBomb
  449.         ];
  450.     };
  451. };
  452. //------------------//
  453. //CUSTOM LOOT SPAWNS//
  454. //------------------//
  455. {
  456.     if ((random 1) < _lootChance) then {
  457.         _iPos = _obj modelToWorld _x;
  458.         _nearBy = nearestObjects [_iPos, ["WeaponHolder","WeaponHolderBase"], 1];
  459.         if (count _nearBy == 0) then {
  460.             private["_index"];
  461.             _weights = [_itemTypes,_itemChance] call fnc_buildWeightedArray;
  462.             _index = _weights call BIS_fnc_selectRandom;
  463.             _itemType = _itemTypes select _index;
  464.             [_itemType select 0, _itemType select 1 , _iPos, 0.0]  call spawn_loot;
  465.         };
  466.     };
  467. } forEach _positions;
Advertisement
Add Comment
Please, Sign In to add comment