Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------------------------------
- ------------------------- A.R.E.A Craft based on Fieldcraf_v1 ----------------------------
- ------------------------------------------------------------------------------------------
- --Modified by Holodilnik
- local recipes, retain
- local function init_recipes()
- local ini = system_ini()
- ini:section_for_each(function(section)
- if ini:line_exist(section,"craft_ingredient1") and ini:line_exist(section,"craft_ingredient2") then
- local igr1 = alun_utils.parse_list(ini,section,"craft_ingredient1")
- local igr2 = alun_utils.parse_list(ini,section,"craft_ingredient2")
- local fail = ini:r_float_ex(section,"craft_fail")
- local multi = ini:r_float_ex(section,"craft_skill_multi")
- local amt = ini:r_float_ex(section,"craft_amt")
- local timer = ini:r_float_ex(section,"craft_time")
- local anim = ini:r_string_ex(section,"craft_anim") or "make_something"
- local skill = ini:r_string_ex(section,"craft_skill") or "craft"
- skill = skill.."_skill"
- recipes[section] = #igr1 > 0 and #igr2 > 0 and {ingredients = {igr1,igr2}, options = {fail,multi,amt,timer,anim,skill}}
- end
- end)
- --alun_utils.print_table(recipes, "recipes table")
- end
- local function activate_feature()
- --[RECIPES]--
- -- place recipes in table or item ltx, ltx entries have precedence over table data.
- recipes = {
- medkit_scientic = {ingredients = {{"medkit","medkit_army"},{"antirad"}}, options = {}},
- }
- --list non weapon items retained after crafting in retain table
- retain = {
- itm_gunsmith_toolkit = "keep",
- itm_outfit_toolkit = "keep",
- itm_repairkit_tier_1 = "keep",
- itm_repairkit_tier_2 = "keep",
- itm_repairkit_tier_3 = "keep"
- }
- init_recipes()
- RegisterScriptCallback("CUIActorMenu_OnItemDropped",OnItemDropped)
- end
- local function deactivate_feature()
- recipes = nil
- retain = nil
- UnregisterScriptCallback("CUIActorMenu_OnItemDropped",OnItemDropped)
- end
- local function opt_menu_on_init(menu)
- -- craft
- menu.gameplay_add_options["craft"] = {default=false, debug_only=false, typ="check",
- on_accept=function(handler,optMgr,ctrl)
- if (level.present()) then
- if (ctrl:GetCheck()) then
- activate_feature()
- else
- deactivate_feature()
- end
- end
- end
- }
- end
- function on_game_start()
- RegisterScriptCallback("opt_menu_on_init",opt_menu_on_init)
- if (axr_main.config:r_value("mm_options","enable_craft",1,false) == false) then return end
- local function actor_on_first_update()
- activate_feature()
- end
- RegisterScriptCallback("actor_on_first_update",actor_on_first_update)
- end
- function OnItemDropped(itm_from,itm_to,slot_from,slot_to)
- if not (slot_from == EDDListType.iActorBag and slot_to == EDDListType.iActorBag) then
- return
- end
- local itm_to_sec = itm_to and itm_to:section()
- local itm_from_sec = itm_from and itm_from:section()
- local sys_ini = system_ini()
- local tmp = (itm_to_sec == itm_from_sec)
- if tmp then
- local r_uses_to,r_uses_from = itm_to:get_remaining_uses(),itm_from:get_remaining_uses()
- local max_uses, t_uses = itm_to:get_max_uses(), r_uses_to + r_uses_from
- local n_uses_to = t_uses > max_uses and max_uses or t_uses
- local n_uses_from = t_uses > max_uses and (t_uses - max_uses) or 0
- itm_to:set_remaining_uses(n_uses_to)
- if n_uses_from > 0 then
- itm_from:set_remaining_uses(n_uses_from)
- else
- if (sys_ini:r_bool_ex(sec,"remove_after_use",true)) then
- local se_obj = alife_object(itm_from:id())
- if (se_obj) then
- alife():release(se_obj,true)
- end
- else
- itm_from:set_remaining_uses(0)
- end
- end
- return
- end
- local function clear(item)
- local sec = item:section()
- local uses = sys_ini:r_bool_ex(sec,"use_condition",false) and item:get_remaining_uses() or 1
- if IsWeapon(item) or (retain[sec] == "keep") then
- return
- end
- --
- local next_items = sys_ini:line_exist(sec,"next_use_item") and alun_utils.parse_list(sys_ini,sec,"next_use_item") or {}
- if (#next_items > 0) and not (sec:find("_radiated")) then
- local se_obj = alife_object(item:id())
- if (se_obj) then
- alife():release(se_obj,true)
- end
- if next_items[#next_items] == "random" then
- alife():create(next_items[math.random(#next_items-1)], db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
- else
- for i=1, #next_items do
- alife():create(next_items[i], db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
- end
- end
- return
- end
- --
- if (sys_ini:r_bool_ex(sec,"remove_after_use",true) and (uses == 1)) or (sec:find("_radiated")) then
- local se_obj = alife_object(item:id())
- if (se_obj) then
- alife():release(se_obj,true)
- end
- elseif (uses >1) then
- item:set_remaining_uses(uses-1)
- end
- end
- local new_item_sec = nil
- for k,v in pairs(recipes) do
- for i=1, #v.ingredients[1] do
- if (v.ingredients[1][i] == itm_to_sec) or (v.ingredients[1][i] == itm_from_sec) then
- for j=1, #v.ingredients[2] do
- if (v.ingredients[2][j] ~= v.ingredients[1][i]) and ((v.ingredients[2][j] == itm_to_sec) or (v.ingredients[2][j] == itm_from_sec)) then
- new_item_sec = k
- break
- end
- end
- end
- if new_item_sec == k then
- break
- end
- end
- if new_item_sec then
- local fail = v.options[1] or 0
- local multi = v.options[2] or 1
- local amount = v.options[3] or 1
- local s_time = v.options[4]
- local anim = v.options[5] or "make_something"
- local skill = v.options[6] or "craft_skill"
- local craft_chance = area_skills and area_skills.skills_table[skill] and (50+(50*(area_skills.skills_table[skill]/area_skills.max_skills_level))) or 100
- if (craft_chance >= fail) then
- if actor_effects then actor_effects.use_item(anim) end
- if (s_time) then
- level.change_game_time(0,0,s_time)
- end
- if area_skills and area_skills.skills_table[skill] then
- area_skills.raise_skill(skill,multi)
- end
- --// this may all be unnecessary
- local new_use = sys_ini:r_string_ex(new_item_sec,"max_uses") or 1
- local cond_frac = 1/new_use
- new_use = new_use - math.floor((itm_to:get_max_uses() - itm_to:get_remaining_uses() + itm_from:get_max_uses() - itm_from:get_remaining_uses())/2)
- new_use = new_use > 1 and new_use or 1
- local cond = cond_frac * new_use
- --//--
- --local cond = (itm_from:condition() + itm_to:condition())/2 --may not want to use this-- remaining charges isn't ideal either
- for i = 1, amount do
- local se_obj = alife():create(new_item_sec, db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
- se_obj.condition = cond --may not want to use this--
- end
- else
- SetHudMsg(game.translate_string("st_craft_skill_fail"),3)
- if actor_effects then actor_effects.use_item("toolkit_p_dummy") end
- end
- clear(itm_from)
- clear(itm_to)
- break
- end
- end
- if not (new_item_sec) then
- printf("No recipes for %s and %s",itm_from_sec,itm_to_sec)
- return
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement