Advertisement
Guest User

random_stashes

a guest
Feb 27th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.23 KB | None | 0 0
  1. function create_random_stash(no_spot,hint)
  2.     last_secret = nil
  3.  
  4.     if (caches_count <= 0) then
  5.         return
  6.     end
  7.  
  8.     last_secret = true
  9.  
  10.     -- create a temporary table to use math.random
  11.     local t = {}
  12.     for id,v in pairs(caches) do
  13.         -- false means box is available
  14.         if (v == false) then
  15.             table.insert(t,id)
  16.         end
  17.     end
  18.  
  19.     local index = #t > 0 and math.random(#t)
  20.     if not (index) then
  21.         return
  22.     end
  23.  
  24.     local sim = alife()
  25.     local id = t[index]
  26.     local se_box = id and sim:object(id)
  27.  
  28.     -- find box by id and make sure it still exists and is still an inventory_box_s
  29.     if (se_box == nil or se_box:clsid() ~= clsid.inventory_box_s) then
  30.         caches[id] = nil
  31.         caches_count = caches_count - 1
  32.         return
  33.     end
  34.  
  35.     -- switch cache true, indicating it has treasure
  36.     caches[id] = true
  37.  
  38.     -- create map spot
  39.     if (no_spot ~= true and level.map_has_object_spot(id,"treasure") == 0) then
  40.         level.map_add_object_spot_ser(id, "treasure", hint or "")
  41.         news_manager.send_treasure(0)
  42.     end
  43.  
  44.     -- setup possible loot table
  45.     local loot = {}
  46.     -- common
  47.     loot[1] = {"bandage","conserva","kolbasa","bread","energy_drink","vodka"}
  48.     loot[2] = {"medkit","drug_booster","drug_coagulant","drug_anabiotic"}
  49.     loot[3] = {"medkit_scientic","drug_psy_blockade","drug_radioprotector"}
  50.  
  51.     -- fairly common
  52.     loot[4] = {"medkit_army","grenade_f1","detector_simple"}
  53.     loot[5] = {"grenade_rgd5","itm_backpack","itm_pda_common"}
  54.     loot[6] = {"detector_advanced","itm_gunsmith_toolkit","itm_sleepbag"}
  55.  
  56.     -- uncommon
  57.     loot[7] = {"itm_pda_uncommon","wpn_pm","wpn_pb","detector_elite","wpn_addon_scope","wpn_addon_silencer","ammo_9x18_fmj","ammo_9x18_pmm","ammo_9x19_pbp","ammo_9x19_fmj","ammo_og-7b","ammo_og-7b","af_fireball"}
  58.     loot[8] = {"wpn_fort","wpn_hpsa","wpn_usp","medkit_army","wpn_addon_scope_susat_x1.6","wpn_addon_scope_susat","ammo_12x70_buck","ammo_12x76_zhekan","ammo_9x39_pab9","ammo_pkm_100","ammo_m209","af_fire","af_gravi"}
  59.     loot[9] = {"wpn_wincheaster1300","wpn_toz34","wpn_desert_eagle","wpn_beretta","wpn_walther","wpn_sig220","wpn_colt1911","detector_scientific","wpn_addon_grenade_launcher","wpn_addon_grenade_launcher_m203","ammo_11.43x23_fmj","ammo_11.43x23_hydro","ammo_5.45x39_ap","ammo_5.45x39_fmj","ammo_9x39_ap","ammo_5.56x45_ss190","ammo_5.56x45_ap","ammo_7.62x54_7h1"}
  60.  
  61.     -- rare
  62.     loot[10] = {"itm_pda_rare","wpn_bm16","wpn_addon_scope_susat_night","af_blood","af_glass","af_gold_fish","novice_outfit"}
  63.     loot[11] = {"wpn_addon_scope_susat_dusk","wpn_sig550","wpn_protecta","stalker_outfit","helm_respirator","helm_hardhat","helm_protective"}
  64.     loot[12] = {"wpn_spas12","wpn_ak74u","wpn_mp5","wpn_ak74","wpn_abakan","wpn_l85","wpn_lr300","wpn_groza","wpn_val","wpn_vintorez","helm_tactic","helm_battle"}
  65.  
  66.     -- extremely rare
  67.     loot[13] = {"wpn_svu","wpn_svd","wpn_g36","wpn_fn2000","wpn_pkm","stalker_outfit","svoboda_light_outfit","wpn_sig550_luckygun"}
  68.     loot[14] = {"wpn_rg-6","wpn_rpg7","specops_outfit","military_outfit","scientific_outfit","svoboda_heavy_outfit","cs_heavy_outfit","dolg_outfit"}
  69.     loot[15] = {"ammo_gauss","exo_outfit","dolg_heavy_outfit"}
  70.  
  71.     math.random()
  72.     math.random()
  73.     math.random()
  74.  
  75.     local rnd = math.random(1,1000)
  76.     local max_roll = 1
  77.  
  78.     if (rnd == 5) then
  79.         max_roll = 15
  80.     elseif (rnd <= 15) then
  81.         max_roll = 14
  82.     elseif (rnd <= 30) then
  83.         max_roll = 13
  84.     elseif (rnd <= 50) then
  85.         max_roll = 12
  86.     elseif (rnd <= 75) then
  87.         max_roll = 11
  88.     elseif (rnd <= 95) then
  89.         max_roll = 10
  90.     elseif (rnd <= 130) then
  91.         max_roll = 9
  92.     elseif (rnd <= 170) then
  93.         max_roll = 8
  94.     elseif (rnd <= 215) then
  95.         max_roll = 7
  96.     elseif (rnd <= 265) then
  97.         max_roll = 6
  98.     elseif (rnd <= 400) then
  99.         max_roll = 5
  100.     else
  101.         max_roll = 4
  102.     end
  103.  
  104.     local spawned_item = {}
  105.     local max_weight = (max_roll * math.random(1,100)/25)
  106.  
  107.     repeat
  108.         rnd = math.random(1,max_roll)
  109.         if (max_roll-1 >= 1) then
  110.             max_roll = max_roll - 1
  111.         else
  112.             max_roll = 1
  113.         end
  114.         max_weight = max_weight - rnd
  115.         table.insert(spawned_item,loot[rnd][math.random(#loot[rnd])])
  116.     until (max_weight <= 0)
  117.  
  118.     local sec
  119.     local ini = system_ini()
  120.     for i=1,#spawned_item do
  121.         sec = spawned_item[i]
  122.         if (sec ~= "" and ini:section_exist(sec)) then
  123.             sim:create(sec,vector(),0,0,id)
  124.         else
  125.             alun_utils.printf("coc_treasure_manager.script: invalid section %s",sec)
  126.         end
  127.     end
  128.  
  129.     return id
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement