Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Advanced Weapons Repair Mod 0.2 [Binder] by Faustle (2017)
- ]]--
- local settings_list = {}
- local angles_t = {}
- local compare_name = {}
- local wpn_data = {}
- local wpn_details = {}
- local mech_list_key = {}
- local ini = ini_file("plugins\\awr_settings.ltx")
- local mesh_test_mode = ini:r_bool_ex("awr_mode","mesh_test_mode",false)
- local settings = alun_utils.collect_section(ini,"awr_settings")
- local mesh_list = alun_utils.collect_section(ini,"awr_angles")
- local weapons_list = alun_utils.collect_section(ini,"awr_weapon_list")
- local test_list = alun_utils.collect_section(ini,"awr_test")
- local scopes = alun_utils.collect_sections(system_ini(), {"addons_table"})
- local awr_sf = awr_shared_functions
- for _, k in ipairs(settings) do
- settings_list[k] = ini:r_float_ex("awr_settings", k)
- end
- for _, k in ipairs(mesh_list) do
- local t = alun_utils.parse_list(ini,"awr_angles", k)
- angles_t[k] = {}
- for _, v in ipairs(t) do
- table.insert(angles_t[k], v)
- end
- end
- for key, val in pairs(angles_t) do
- mech_list_key[val[1]] = 0
- end
- local test_wep = 1
- local wpn_condition, wpn, wpn_sect, delay, ui
- local f_details = {
- tc_t = 'trigger_components',
- b_t = 'bolt',
- bc_t = 'bolt_carrier',
- gt_t = 'gas_tube',
- br_t = 'barrel'
- }
- local n_details = {
- 'barrel',
- 'trigger_components',
- 'bolt_carrier',
- 'bolt',
- 'gas_tube'
- }
- function on_game_start()
- RegisterScriptCallback("physic_object_on_use_callback", physic_object_on_use_callback)
- RegisterScriptCallback("CUIActorMenu_OnItemFocusReceive", on_item_focus)
- RegisterScriptCallback("actor_on_first_update", actor_on_first_update)
- RegisterScriptCallback("npc_on_death_callback", npc_on_death_callback)
- end
- function actor_on_first_update()
- local caller = debug.getinfo(1, "n").name
- awr_sf.dout(nil, caller, "Called on first update")
- for i=1, 65535 do
- local s_obj = alife():object(i)
- if s_obj then
- local name = s_obj:name()
- --// Если тиски заспавнены all.spawn - сохраняем их значения в store
- if string.match(name, '%w+%_awr%_tiski%_%d+') then
- awr_sf.dout(nil, caller, "%s is parent. Loading table angles_t[%s] from Store", name, name)
- angles_t[name] = awr_sf.l_v(name, angles_t[name])
- --// Если тиски были заспавнены актором, находим изначальное имя, и загружаем в таблицу соответствующее значение
- elseif string.match(name, 'awr%_m%_wpn.*%d+') or string.match(name, '^awr%_tiski.*%d+') then
- local p_name = awr_sf.get_p_name(name)
- if p_name then
- awr_sf.dout(nil, caller, "%s is child. Loading parent table angles_t[%s] from Store", name, p_name)
- t = awr_sf.l_v(p_name, nil)
- if (t) then
- angles_t[p_name] = t
- end
- end
- elseif string.match(name, '_awr_lamp') then
- local lamp_obj = level.object_by_id(s_obj.id)
- if lamp_obj then
- if not (db.actor:has_info("awr_go_away")) then
- lamp_obj:get_hanging_lamp():turn_off()
- end
- end
- end
- end
- end
- for key, val in pairs(angles_t) do
- for _, v in ipairs(angles_t[key]) do
- if angles_t[key][3] == 'dead' then
- awr_sf.dout(nil, caller, "%s is dead. Enable lamp(s) which assigned for %s ", angles_t[key][1], key)
- awr_sf.LampOn(angles_t[key][1])
- end
- end
- end
- compare_name = awr_sf.l_v('compare_name') or {}
- if compare_name then
- awr_sf.dout(nil, caller, "compare_name table loaded")
- else
- awr_sf.dout(nil, caller, "compare_name table is empty")
- end
- wpn_data = awr_sf.l_v('wpn_data') or {}
- if wpn_data then
- awr_sf.dout(nil, caller, "wpn_data table loaded")
- else
- awr_sf.dout(nil, caller, "wpn_data table is empty")
- end
- end
- --// Доступ к тискам, с учетом возможной смерти механика
- function access(obj)
- local caller = debug.getinfo(1, "n").name
- local current_func = debug.getinfo(2, "n").name
- if not (obj) then
- return
- end
- local name = obj:name()
- local p_name = awr_sf.get_p_name(name)
- awr_sf.dout(caller, current_func, "Request access for %s", name)
- if angles_t[p_name] then
- if angles_t[p_name][3] == 'dead' then
- awr_sf.dout(caller, current_func, "Mechanic is dead. Full access.")
- return true
- end
- end
- if db.actor:has_info("awr_go_away") then
- awr_sf.dout(caller, current_func, "Mechanic gave access.")
- return true
- end
- local npc = get_story_object(angles_t[p_name][1])
- if npc then
- if npc:alive() then
- awr_sf.dout(caller, current_func, "Access not granted. NPC %s by id %s is alive.", angles_t[p_name][1], npc:id())
- else
- awr_sf.dout(caller, current_func, "![ERROR] NPC %s by id %s bugged, becase he is online and is not alive, but function OnDeath was not called.", angles_t[p_name][1], npc:id())
- end
- end
- end
- --// Локальная функция для вызова через CreateTimeEvent. Также участвует в изменении cse_abstract части нет-пакета через callback (se_item.script:381) для изменения direction меша.
- local function create_call(n_obj,new,pos,lv,gv,yaw,wpn_fn,wpn_condition)
- local caller = 'create_call'
- local current_func = 'physic_object_on_use_callback'
- local obj_name, p_name
- if (n_obj) then
- obj_name = n_obj:name()
- p_name = awr_sf.get_p_name(obj_name)
- if level.map_has_object_spot(n_obj.id, "ui_pda2_mechanic_location") ~= 0 then
- level.map_remove_object_spot(n_obj.id, "ui_pda2_mechanic_location")
- end
- alife():release(n_obj)
- end
- local s_obj = alife():create(new, pos, lv, gv)
- if s_obj then
- s_obj.repack = { ["direction"] = vector():set(0,tonumber(yaw),0) }
- local c_name = {}
- local m_name = s_obj:name()
- if string.match(obj_name, '%w+%_awr%_tiski%_%d+') then
- awr_sf.dout(caller, current_func, "%s is parent name", m_name)
- c_name[obj_name] = m_name
- else
- c_name[p_name] = m_name
- end
- --// Запись данных об оружии
- if string.match(m_name, 'awr_m_wpn') then
- awr_sf.dout(caller, current_func, "Save data of wpn %s with cond %s to store wpn_data[%s]", wpn_fn, wpn_condition, m_name)
- wpn_data[m_name] = {}
- wpn_data[m_name]['wpn_name'] = wpn_fn
- wpn_data[m_name]['condition'] = wpn_condition
- wpn_data[m_name]['time'] = alun_utils.CTime2table(game.get_game_time())
- awr_sf.s_v('wpn_data', wpn_data)
- db.actor:give_info_portion(string.format("awr_%s_on_table", angles_t[p_name][1]))
- if db.actor:has_info(string.format("awr_%s_on_table", angles_t[p_name][1])) then
- awr_sf.dout(caller, current_func, "Get infoportion awr_%s_on_table", angles_t[p_name][1])
- end
- end
- --// Изменение логики мешей
- local name = awr_sf.get_p_name(obj_name)
- local num = string.gsub(name, '(.*%_)(%d+)$', '%2')
- local lvl = string.gsub(level.name(), '(%w%d+%_)(.*)', '%2')
- awr_sf.set_logic(s_obj, lvl, num)
- awr_sf.s_v('compare_name', c_name)
- end
- if string.match(obj_name, 'awr_m_wpn') then
- awr_sf.d_v('wpn_data', obj_name)
- end
- if db.actor:has_info(string.format("awr_%s_dead", angles_t[p_name][1])) then
- level.map_add_object_spot_ser(s_obj.id, "ui_pda2_mechanic_location", "st_mech_tiski")
- end
- return true
- end
- --// Функция-биндер при использовании меша тисков
- function physic_object_on_use_callback(_obj,who)
- local current_func = debug.getinfo(1, "n").name
- awr_sf.dout(nil, current_func, "Physic object on use.")
- if not (mesh_test_mode) then
- if not (_obj) or not (string.match(_obj:name(), "awr")) then
- return
- end
- local ch_obj = alife():object(_obj:id())
- local pos, lvID, gvID = _obj:position(), _obj:level_vertex_id(), _obj:game_vertex_id()
- if (axr_main.config:r_value("mm_options","enable_extra_animations",1,false) == false) then
- delay = 0
- else
- delay = 100
- end
- if access(_obj) and string.match(_obj:name(), "awr_tiski") and _obj:position():distance_to(db.actor:position()) < 1.5 then
- if (db.actor:active_slot() == 2 or db.actor:active_slot() == 3) then
- wpn = db.actor:active_item()
- local wpn_fn = wpn:name()
- wpn_sect = db.actor:active_item():section()
- for _, k in ipairs(weapons_list) do
- if wpn and (string.gsub(wpn_sect,k, "") == "") then
- awr_sf.dout(nil, caller, "WPN recognized and has not scopes")
- wpn_condition = wpn:condition()
- if (rx_utils.addon_attached(wpn,"sl") and not (string.match(wpn_sect, "wpn_val")) and not (string.match(wpn_sect, "wpn_vintorez"))) and not (string.match(wpn_sect, "wpn_vsk94")) or rx_utils.addon_attached(wpn,"gl") or wpn:get_ammo_in_magazine() > 0 then
- SetHudMsg(game.translate_string("st_unload"),3)
- awr_sf.dout(nil, caller, "WPN recognized, but has attached addons or magazine is not empty")
- else
- actor_effects.use_item("awr_repair_dummy")
- if not awr_sf.IsWorn(wpn_sect) and not awr_sf.IsRusty(wpn_sect) then
- awr_sf.dout(nil, caller, "WPN quiality is good. Delay %s, new mesh name [awr_m_], angle %s, wpn name [%s], wpn condition %s", delay, wpn_sub, GetAngle(_obj), wpn_fn, wpn_condition)
- local wpn_sub = string.gsub(k, wpn_sect, wpn_sect)
- CreateTimeEvent("create_mesh","delay",delay,create_call,ch_obj,"awr_m_"..wpn_sub,pos,lvID,gvID,GetAngle(_obj),wpn_fn,wpn_condition)
- else
- awr_sf.dout(nil, caller, "WPN quiality is good. Delay %s, new mesh name [awr_m_], angle %s, wpn name [%s], wpn condition %s. Calling create_call()", delay, wpn_sub, GetAngle(_obj), wpn_fn, wpn_condition)
- CreateTimeEvent("create_mesh","delay",delay,create_call,ch_obj,"awr_m_"..wpn_sect,pos,lvID,gvID,GetAngle(_obj),wpn_fn,wpn_condition)
- awr_sf.dout(nil, caller, "WPN quiality is %s. Delay %s, new mesh name [awr_m_], angle %s, wpn name [%s], wpn condition %s. Calling create_call()", string.gsub(wpn_sect, 'wpn.*%_(.*)', '%1'), delay, wpn_sect, GetAngle(_obj), wpn_fn, wpn_condition)
- end
- db.actor:drop_item(wpn)
- local se_obj = alife():object(wpn:id())
- if (se_obj) then
- alife():release(se_obj)
- end
- end
- end
- end
- if HasScope(wpn_sect) then
- SetHudMsg(game.translate_string("st_unload"),3)
- return
- elseif not (InWpnLst(wpn_sect)) then
- SetHudMsg(game.translate_string("st_not_in_list"),3)
- return
- end
- else
- SetHudMsg(game.translate_string("st_no_weap"),3)
- awr_sf.dout(nil, caller, "WPN is not in hands -> return")
- return
- end
- elseif access(_obj) and string.match(_obj:section(),"awr_m_wpn_") and _obj:position():distance_to(db.actor:position()) < 1.5 then
- if (wpn) then
- awr_sf.dout(nil, caller, "WPN variable exist")
- if not db.actor:active_item() then
- awr_sf.dout(nil, caller, "WPN is not in hands, call UI")
- local hud = get_hud()
- ui = ui_awr_menu and ui_awr_menu.awr_main_ui(hud,wpn,wpn_sect,wpn_condition,ch_obj)
- if (ui) then
- ui:ShowDialog(true)
- ui:FillList()
- end
- else
- SetHudMsg(game.translate_string("st_handsfree"),3)
- awr_sf.dout(nil, caller, "WPN in hands -> return")
- return
- end
- else
- actor_effects.use_item("awr_repair_dummy")
- CreateTimeEvent("create_mesh","delay",delay,create_call,ch_obj,"awr_tiski",pos,lvID,gvID,GetAngle(_obj))
- awr_sf.dout(nil, caller, "Delay %s, new mesh name [awr_tiski], angle %s. Calling create_call()", delay, GetAngle(_obj))
- local m_name = _obj:name()
- if m_name then
- if wpn_data then
- local new_cond = wpn_data[m_name]['condition']
- local time = alun_utils.table2CTime(wpn_data[m_name]['time']) or 0
- if game.get_game_time():diffSec(time) > settings_list.steal_delay then
- new_cond = new_cond - math.random(0,25)/100
- awr_sf.dout(nil, caller, "Difference time %s > %s -> some parts was stolen for WPN %s, old condition %s, new condition %s", game.get_game_time():diffSec(time), settings_list.steal_delay, wpn_data[m_name]['wpn_name'], wpn_data[m_name]['condition'], new_cond)
- SetHudMsg(game.translate_string("st_stolen_"..math.random(1,3)),3)
- else
- awr_sf.dout(nil, caller, "Difference time %s < %s -> parts was not stolen", game.get_game_time():diffSec(time), settings_list.steal_delay)
- end
- end
- db.actor:disable_info_portion(string.format("awr_%s_on_table", angles_t[m_name][1]))
- if not (db.actor:has_info(string.format("awr_%s_on_table", angles_t[p_name][1]))) then
- awr_sf.dout(caller, current_func, "Remove infoportion awr_%s_on_table", angles_t[p_name][1])
- end
- end
- local function wpn_alife(id, obj)
- obj:set_condition(new_cond)
- obj:unload_magazine()
- end
- local sobj = alife():create(string.gsub(_obj:section(), '^(.*)(%_)(wpn)(.*)$', '%3%4'), db.actor:position(),0,0,0)
- if sobj then
- level.client_spawn_manager():add(sobj.id, 0, wpn_alife)
- end
- end
- end
- elseif mesh_test_mode then --// Режим тестирования мешей
- local ch_obj = alife():object(_obj:id())
- local pos, lvID, gvID = _obj:position(), _obj:level_vertex_id(), _obj:game_vertex_id()
- if string.match(_obj:name(), "awr_tiski") or string.match(_obj:name(), "awr_m_") then
- if (ch_obj) then
- alife():release(ch_obj)
- end
- local s_obj = alife():create(test_list[test_wep], pos, lvID, gvID)
- if s_obj then
- s_obj.repack = { ["direction"] = vector():set(0,tonumber(GetAngle(_obj)),0) }
- end
- test_wep = test_wep + 1
- end
- end
- end
- --// Функция подсветки деталей при наведении на оружие и оружия при наведении на детали
- function on_item_focus(item)
- local t = {}
- local sec = nil
- local c_wpn = {}
- local det_arg = {}
- local wpn_parts_gen_t = {}
- if IsWeapon(item) then
- for _, k in ipairs(weapons_list) do
- if string.match(item:section(), k) then
- c_wpn = alun_utils.parse_list(ini,"awr_weapon_list", k)
- wpn_parts_gen_t = {
- br_t = c_wpn[1],
- tc_t = c_wpn[2],
- bc_t = c_wpn[3],
- b_t = c_wpn[4],
- gt_t = c_wpn[5]
- }
- sec = k
- end
- end
- if sec then
- for key, val in pairs(f_details) do
- table.insert(t, string.format("awr_%s_%s_good", val, wpn_parts_gen_t[key]))
- table.insert(t, string.format("awr_%s_%s_worn", val, wpn_parts_gen_t[key]))
- table.insert(t, string.format("awr_%s_%s_rusty", val, wpn_parts_gen_t[key]))
- for i=1,#t do
- ActorMenu.get_actor_menu():highlight_section_in_slot(t[i],EDDListType.iActorBag)
- end
- end
- end
- elseif IsDetail(item,"good") then
- for _, k in ipairs(weapons_list) do
- det_arg[k] = alun_utils.parse_list(ini,"awr_weapon_list", k)
- local type = string.gsub(string.gsub(item:section(), '^(%w+%_)(%w*)', '%2'), '(%_%d+%_%w+)$', '')
- local num = string.gsub(item:section(), '^(.*)(%_)(%d+)(.*)$', '%3')
- for n, v in ipairs(n_details) do
- if v == type then
- if det_arg[k][n] == num then
- table.insert(t, k)
- for _, z in ipairs(scopes) do
- table.insert(t, string.format("%s_%s", k, z))
- end
- end
- end
- end
- end
- for i=1,#t do
- ActorMenu.get_actor_menu():highlight_section_in_slot(t[i],EDDListType.iActorBag)
- end
- else
- return
- end
- end
- --// Функция для работы с контекстным меню инвентаря (use2_functor) (вызывается из default_weapon_params, defines.ltx)
- --// Если функция вернет строку - она появится в контекстном меню при нажатии ПКМ на оружие в инвентаре
- --// Нажатие на строку, вызовет use2_action_functor - disassembly_weapon()
- function disassembly_weapon_text(weapon_obj)
- local n = nil
- if (not weapon_obj) or not (IsWeapon(weapon_obj)) then
- return
- end
- --// Обратная функция InWpnList(), для поиска секции из списка в текущей секции оружия (например для оружия с прицелом, которое имеет секцию вида "wpn_..._..._1p29")
- for _, k in ipairs(weapons_list) do
- if string.match(weapon_obj:section(), k) then
- n = 1
- end
- end
- if not (n) then
- return
- end
- return game.translate_string("st_awr_disassembly")
- end
- --// Функтор контекстного вызова разборки оружия
- function disassembly_weapon(weapon_obj)
- local caller = debug.getinfo(1, "n").name
- local current_func = nil
- local details_am
- local get_detail
- local num
- local wpn_details = {}
- local result_details = {}
- local result_details_names = ""
- local get_ammo = {}
- local with_scope = nil
- local a_name
- local wpn_s = weapon_obj:section()
- local wpn_name = game.translate_string(rx_utils.read_from_ini2(nil,wpn_s,"inv_name","string","error"))
- awr_sf.dout(caller, current_func, "Trying to disassemble %s", wpn_s)
- if (axr_main.config:r_value("mm_options","enable_extra_animations",1,false) == false) then
- delay = 0
- else
- delay = 100
- end
- if not (db.actor:object("leatherman_tool")) then
- awr_sf.SendAwrMsg('fail', 'weapon', "st_dis_text_3", " ")
- awr_sf.dout(caller, current_func, "Actor dont have leathernam_tool -> return", wpn_s)
- return
- end
- local details_q = { 'good', 'worn', 'rusty' }
- local on_drop_details = {
- 'barrel',
- 'trigger_components',
- 'bolt_carrier',
- 'bolt',
- 'gas_tube'
- }
- if IsWeapon(weapon_obj) then
- for key, val in pairs(scopes) do
- if string.match(wpn_s, key) then
- with_scope = key
- end
- end
- --// Проверка наличия аддонов
- if with_scope then
- table.insert(result_details, with_scope)
- wpn_s = string.gsub(wpn_s, "_"..with_scope, "")
- end
- if (rx_utils.addon_attached(weapon_obj,"sc")) then
- local scope_section = rx_utils.read_from_ini2(nil,wpn_s,"scopes_sect","string",nil)
- table.insert(result_details, rx_utils.read_from_ini2(nil,scope_section,"scope_name","string",nil))
- end
- if (rx_utils.addon_attached(weapon_obj,"sl") and not (string.match(wpn_s, "wpn_val")) and not (string.match(wpn_s, "wpn_vintorez")) and not (string.match(wpn_s, "wpn_vsk94"))) then
- table.insert(result_details, rx_utils.read_from_ini2(nil,wpn_s,"silencer_name","string",nil))
- end
- if (rx_utils.addon_attached(weapon_obj,"gl")) and not (string.match(wpn_s, "wpn_groza")) then
- table.insert(result_details, rx_utils.read_from_ini2(nil,wpn_s,"grenade_launcher_name","string",nil))
- end
- --// Проверка наличия патронов в рожке
- local data = stpk_utils.get_weapon_data(alife():object(weapon_obj:id()))
- if data.ammo_elapsed > 0 then
- local ammos = alun_utils.parse_list(system_ini(), wpn_s, "ammo_class")
- get_ammo = { data.ammo_elapsed, ammos[data.ammo_type+1] }
- end
- local wpn_cond = weapon_obj:condition()
- local _wpn_details = alun_utils.parse_list(ini,"awr_weapon_list", wpn_s)
- for i, k in ipairs(_wpn_details) do
- wpn_details[on_drop_details[i]] = k
- end
- if awr_sf.IsRusty(wpn_s) then
- details_am = 2 --// Количество деталей при разборке ржавого оружия
- elseif awr_sf.IsWorn(wpn_s) then
- details_am = 2 --// Количество деталей при разборке изношенного оружия
- else
- details_am = 3 --// Количество деталей при разборке нового оружия
- end
- local i = details_am
- while i > 0 do
- if (wpn_cond*100)+settings_list.condition >= math.random(1, 100) then
- num = math.random(1,#on_drop_details)
- get_detail = on_drop_details[num]
- if awr_sf.IsRusty(wpn_s) then
- table.insert(result_details, string.format("awr_%s_%i_%s", get_detail, wpn_details[get_detail], details_q[math.random(2,3)])) --// Рандом для создания ржавых деталей
- else
- table.insert(result_details, string.format("awr_%s_%i_%s", get_detail, wpn_details[get_detail], details_q[math.random(1,2)])) --// Рандом для создания изношенных и новых деталей
- end
- table.remove(on_drop_details, num)
- end
- i = i - 1
- end
- for _, k in ipairs(result_details) do
- result_details_names = result_details_names.."\\n"..game.translate_string(rx_utils.read_from_ini2(nil,k,"inv_name","string","error"))
- end
- local se_obj = alife():object(weapon_obj:id())
- if (se_obj) then
- alife():release(se_obj)
- end
- local function disasm()
- if get_ammo and get_ammo[1] and get_ammo[2] then
- a_name = string.format(game.translate_string("st_dis_text_4"), get_ammo[1], string.gsub(game.translate_string(rx_utils.read_from_ini2(nil,get_ammo[2],"inv_name","string",0)), "^(.*%s)(%d+)", "%2"))
- create_ammo(get_ammo[2], db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id(), get_ammo[1])
- end
- if #result_details > 0 then
- if get_ammo and get_ammo[1] and get_ammo[2] then
- awr_sf.SendAwrMsg('success', 'weapon_ammo', "st_dis_text_7", wpn_name, a_name, result_details_names)
- else
- awr_sf.SendAwrMsg('success', 'weapon', "st_dis_text_1", wpn_name, result_details_names)
- end
- else
- awr_sf.SendAwrMsg('fail', 'weapon', "st_dis_text_2", wpn_name)
- end
- for _, k in ipairs(result_details) do
- alife():create(k, db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
- end
- return true
- end
- actor_effects.use_item("cleaning_kit_u_dummy")
- CreateTimeEvent("disasm","delay",delay,disasm,weapon_obj)
- else
- return
- end
- end
- --// Функтор контекстного вызова восстановления детали (текст)
- function r_detail_text(itm)
- if not (itm) and not (IsDetail(itm,'worn')) and not (IsDetail(itm,'rusty')) then
- return
- end
- return game.translate_string("st_awr_r_detail")
- end
- --// Функтор контекстного вызова восстановления детали
- function r_detail(itm)
- if (ui) and ui:IsShown() then
- ui:HideDialog()
- end
- local hud = get_hud()
- ui = ui_awr_mini and ui_awr_mini.awr_mini_ui(hud,itm)
- if (ui) then
- ui:ShowDialog(true)
- end
- end
- --// Функция проверки, является ли предмет деталью. Список генерируется динамически. При изменении количества деталей, изменить значения в файле awr_settings на соответствующее.
- function IsDetail(item,type)
- local caller = debug.getinfo(1, "n").name
- local current_func = debug.getinfo(2, "n").name
- local x = 1
- local all_details_f = {}
- local all_details = {
- bolt = settings_list.bolt,
- barrel = settings_list.barrel,
- gas_tube = settings_list.gas_tube,
- bolt_carrier = settings_list.bolt_carrier,
- trigger_components = settings_list.trigger
- }
- for key, val in pairs(all_details) do
- while x < val+1 do
- table.insert(all_details_f, "awr_"..key.."_"..x.."_"..type)
- x = x + 1
- end
- x = 1
- end
- if item then
- for _, k in ipairs(all_details_f) do
- if k == item:section() then
- awr_sf.dout(caller, current_func, "%s is detail", item:section())
- return true
- end
- end
- else
- awr_sf.dout(caller, current_func, "Detail object is nil -> return")
- return
- end
- end
- --// Функция проверки наличия itm в списке подходящего оружия из файла awr_settings
- function InWpnLst(itm)
- local caller = debug.getinfo(1, "n").name
- local current_func = debug.getinfo(2, "n").name
- for _, k in ipairs(weapons_list) do
- if k == itm then
- awr_sf.dout(caller, current_func, "WPN %s in AWR weapons compatible list", itm)
- return true
- end
- end
- awr_sf.dout(caller, current_func, "WPN %s is NOT in AWR weapons compatible list", itm)
- end
- function HasScope(wpn_sect)
- local caller = debug.getinfo(1, "n").name
- local current_func = debug.getinfo(2, "n").name
- for _, k in ipairs(scopes) do
- if string.match(wpn_sect, string.format('wpn.*%_%s$', k)) then
- awr_sf.dout(caller, current_func, "WPN %s has attached %s scope -> return", wpn_sect, k)
- return true
- end
- end
- end
- --// Функция получения значения угла для установки меша, исходя из секции механика в радиусе n-метров
- function GetAngle(obj)
- local caller = debug.getinfo(1, "n").name
- local current_func = debug.getinfo(2, "n").name
- awr_sf.dout(caller, current_func, "Called for %s", obj:name())
- if not (obj) or not (string.match(obj:name(), "awr")) then --// У объектов, заспавненных через all.spawn, секция physic object
- return
- end
- local name = awr_sf.get_p_name(obj:name())
- if angles_t[name] then
- awr_sf.dout(caller, current_func, "Angle for %s = %s", name, angles_t[name][2] or 0)
- awr_sf.s_v(name, angles_t[name])
- return angles_t[name][2] or 0
- end
- end
- --// Коллбэк при смерти механика
- function OnDeath(npc)
- local caller = debug.getinfo(1, "n").name
- local current_func = debug.getinfo(2, "n").name
- awr_sf.dout(caller, current_func, "Called for NPC, %s", npc:section())
- if IsStalker(npc) and not (npc:alive()) then
- local npc_s = npc:section()
- awr_sf.dout(caller, current_func, "NPC %s exist and dead", npc:section())
- for key, val in pairs(angles_t) do
- for _, v in ipairs(angles_t[key]) do
- if angles_t[key][1] == npc_s then
- angles_t[key][3] = 'dead'
- if db.actor:has_info("awr_go_away") then
- db.actor:disable_info_portion("awr_go_info")
- end
- level.map_add_object_spot_ser(get_story_object(angles_t[key][1]):id(), "ui_pda2_mechanic_location", "st_mech_tiski")
- db.actor:give_info_portion(string.format("awr_%s_dead", npc_s))
- awr_sf.LampOn(npc_s)
- awr_sf.s_v(key, angles_t[key])
- end
- end
- end
- end
- end
- --// Функция закрытия UI AWR по окончании времени (при условии, что UI вызван, и actor находится в пределах 2 метров от меша)
- function CloseDl()
- local caller = debug.getinfo(1, "n").name
- local current_func = debug.getinfo(2, "n").name
- for i=1, 65535 do
- local s_obj = alife():object(i)
- if s_obj then
- local c_obj = level.object_by_id(s_obj.id)
- if c_obj then
- if string.match(s_obj:name(), "awr_m_") and c_obj:position():distance_to(db.actor:position()) <= 2 then
- awr_sf.dout(caller, current_func, "Called for %s, distance = %s <= 2", s_obj:name(), c_obj:position():distance_to(db.actor:position()))
- if (ui) and ui:IsShown() then
- awr_sf.dout(caller, current_func, "UI exist and show")
- ui:Exit()
- end
- end
- end
- end
- end
- end
- function npc_on_death_callback(victim, who)
- if not (victim) or not (who) then
- return
- end
- local name = string.gsub(victim:name(), '%d+', '')
- if mech_list_key[name] then
- local caller = debug.getinfo(1, "n").name
- local current_func = debug.getinfo(2, "n").name
- awr_shared_functions.dout(caller, current_func, "NPC %s was killed by %s.", victim:name(), who:name())
- OnDeath(victim)
- local killer_name = who:character_name()
- if who:id() == db.actor:id() then
- local alife = alife()
- local se_actor = alife:actor()
- killer_name = se_actor:character_name()
- end
- awr_shared_functions.SendAwrMsg('success', 'npc', "st_awr_dead_mechanic", victim:character_name(), killer_name or game.translate_string("st_by_unknown"))
- else
- return
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement