Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function on_game_start()
- RegisterScriptCallback("CUIActorMenu_OnItemDropped",combine_helmets)
- end
- --// ------------- hacky dynamic update install procedure ---------------------
- function delay(id)
- local obj = level.object_by_id(id)
- if obj then
- db.actor:transfer_item(obj,db.actor)
- return true
- end
- end
- function install_upgrades(se_obj, upg)
- local UpgTbl = {upg}
- if type(upg) == "table" then
- UpgTbl = upg
- end
- local data = se_obj and stpk_utils.get_object_data(se_obj)
- if data then
- local tt = data.upgrades
- for i=1, #UpgTbl do
- tt[#tt+1] = UpgTbl[i]
- end
- --alun_utils.print_table(tt,"upgrade table")
- data.upgrades = tt
- stpk_utils.set_object_data(data,se_obj)
- end
- alun_utils.switch_offline(se_obj.id)
- alun_utils.switch_online(se_obj.id)
- end
- --//-----------------------------------------------------------------------
- function combine_helmets(obj1, obj2, slot_from, slot_to)
- --// both items must be in actor ruck
- if not (slot_from == EDDListType.iActorBag and slot_to == EDDListType.iActorBag) then return end
- --// check that both are helms
- local helm_1, helm_2 = obj1:section(), obj2:section()
- if not(helm_1:find("helm_") and helm_2:find("helm_")) then return end
- --// list combo recipes "helm section1", "helm section2", "new helm section"
- --// an upgrade scheme must be assigned in the new item section that uses all branches from the old items
- local helm_combo = {
- {"helm_hardhat", "helm_respirator", "helm_respirator_hardhat"}
- }
- local adds = {}
- local helmet_se_obj
- --// search table for match for two helms
- for i=1, #helm_combo do
- if (helm_combo[i][1] == helm_1) and (helm_combo[i][2] == helm_2) or (helm_combo[i][1] == helm_2) and (helm_combo[i][2] == helm_1) then --//match
- --// grab upgrades on both helms for combo helm
- local function itr(section)
- --local sect = sys_ini:r_string_ex(section, "section")
- adds[#adds+1] = section
- end
- obj1:iterate_installed_upgrades(itr)
- obj2:iterate_installed_upgrades(itr)
- --// adjust update names to accommodate overlap and match new scheme
- local stub1, stub2, stub3 = helm_combo[i][1]:gsub("helm",""), helm_combo[i][2]:gsub("helm",""), helm_combo[i][3]:gsub("helm","")
- --printf("stubs :%s:%s:%s",stub1,stub2,stub3)
- for i=1,#adds do
- if adds[i]:find(stub1) then
- adds[i] = adds[i]:gsub(stub1,stub3)
- elseif adds[i]:find(stub2) then
- adds[i] = adds[i]:gsub(stub2,stub3)
- adds[i] = adds[i]:gsub("first","third")
- end
- end
- --alun_utils.print_table(adds,"pre upgrade table")
- --// create new helm - must not be in actor inventory to allow apply upgrades
- local pos = db.actor:position():sub(db.actor:direction():mul(0.5))
- helmet_se_obj = alife():create(helm_combo[i][3], pos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
- break
- end
- end
- if helmet_se_obj then
- if #adds > 0 then --// if updates then apply to new helm
- install_upgrades(helmet_se_obj, adds)--{up_gr_firstab_helm_respirator_hardhat, up_gr_seconab_helm_respirator_hardhat, up_gr_thirdab_helm_respirator_hardhat}
- end
- CreateTimeEvent(0,"combine_delay",0,delay,se_obj.id)
- --// remove old helms
- local se_obj = alife_object(obj1:id())
- if (se_obj) then
- alife():release(se_obj,true)
- end
- se_obj = alife_object(obj2:id())
- if (se_obj) then
- alife():release(se_obj,true)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment