Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function create_random_stash(no_spot,hint)
- last_secret = nil
- if (caches_count <= 0) then
- return
- end
- last_secret = true
- -- create a temporary table to use math.random
- local t = {}
- for id,v in pairs(caches) do
- -- false means box is available
- if (v == false) then
- table.insert(t,id)
- end
- end
- local index = #t > 0 and math.random(#t)
- if not (index) then
- return
- end
- local sim = alife()
- local id = t[index]
- local se_box = id and sim:object(id)
- -- find box by id and make sure it still exists and is still an inventory_box_s
- if (se_box == nil or se_box:clsid() ~= clsid.inventory_box_s) then
- caches[id] = nil
- caches_count = caches_count - 1
- return
- end
- -- switch cache true, indicating it has treasure
- caches[id] = true
- -- create map spot
- if (no_spot ~= true and level.map_has_object_spot(id,"treasure") == 0) then
- level.map_add_object_spot_ser(id, "treasure", hint or "")
- news_manager.send_treasure(0)
- end
- -- setup possible loot table
- local loot = {}
- -- common
- loot[1] = {"bandage","conserva","kolbasa","bread","energy_drink","vodka"}
- loot[2] = {"medkit","drug_booster","drug_coagulant","drug_anabiotic"}
- loot[3] = {"medkit_scientic","drug_psy_blockade","drug_radioprotector"}
- -- fairly common
- loot[4] = {"medkit_army","grenade_f1","detector_simple"}
- loot[5] = {"grenade_rgd5","itm_backpack","itm_pda_common"}
- loot[6] = {"detector_advanced","itm_gunsmith_toolkit","itm_sleepbag"}
- -- uncommon
- 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"}
- 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"}
- 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"}
- -- rare
- loot[10] = {"itm_pda_rare","wpn_bm16","wpn_addon_scope_susat_night","af_blood","af_glass","af_gold_fish","novice_outfit"}
- loot[11] = {"wpn_addon_scope_susat_dusk","wpn_sig550","wpn_protecta","stalker_outfit","helm_respirator","helm_hardhat","helm_protective"}
- 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"}
- -- extremely rare
- loot[13] = {"wpn_svu","wpn_svd","wpn_g36","wpn_fn2000","wpn_pkm","stalker_outfit","svoboda_light_outfit","wpn_sig550_luckygun"}
- loot[14] = {"wpn_rg-6","wpn_rpg7","specops_outfit","military_outfit","scientific_outfit","svoboda_heavy_outfit","cs_heavy_outfit","dolg_outfit"}
- loot[15] = {"ammo_gauss","exo_outfit","dolg_heavy_outfit"}
- math.random()
- math.random()
- math.random()
- local rnd = math.random(1,1000)
- local max_roll = 1
- if (rnd == 5) then
- max_roll = 15
- elseif (rnd <= 15) then
- max_roll = 14
- elseif (rnd <= 30) then
- max_roll = 13
- elseif (rnd <= 50) then
- max_roll = 12
- elseif (rnd <= 75) then
- max_roll = 11
- elseif (rnd <= 95) then
- max_roll = 10
- elseif (rnd <= 130) then
- max_roll = 9
- elseif (rnd <= 170) then
- max_roll = 8
- elseif (rnd <= 215) then
- max_roll = 7
- elseif (rnd <= 265) then
- max_roll = 6
- elseif (rnd <= 400) then
- max_roll = 5
- else
- max_roll = 4
- end
- local spawned_item = {}
- local max_weight = (max_roll * math.random(1,100)/25)
- repeat
- rnd = math.random(1,max_roll)
- if (max_roll-1 >= 1) then
- max_roll = max_roll - 1
- else
- max_roll = 1
- end
- max_weight = max_weight - rnd
- table.insert(spawned_item,loot[rnd][math.random(#loot[rnd])])
- until (max_weight <= 0)
- local sec
- local ini = system_ini()
- for i=1,#spawned_item do
- sec = spawned_item[i]
- if (sec ~= "" and ini:section_exist(sec)) then
- sim:create(sec,vector(),0,0,id)
- else
- alun_utils.printf("coc_treasure_manager.script: invalid section %s",sec)
- end
- end
- return id
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement