Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wpnid = {}
- function get_base_section(section)
- local ini = system_ini()
- if string.sub(section,-3,-2) == "_m" and tonumber(string.sub(section,-1,-1)) ~= nil then
- return section
- end
- local sub = string.sub(section,1,(string.len(section)-3))
- local base_section
- if ini:section_exist(sub) then
- base_section = sub
- else
- base_section = section
- end
- return base_section
- end
- function nv_effect(section)
- local nv_on = xr_logic.pstor_retrieve(db.actor, "nv_on", "nil") -- P
- local ini = system_ini()
- local ppe = ini:r_string(section, "ppe")
- local lamp
- if ini:line_exist(section, "light_amp") then
- lamp = ini:r_float(section, "light_amp")
- else
- lamp = 1
- end
- if nv_on == section then -- если используем тот ПНВ, что уже включен, значит отключаем
- ppe = "nightvision_nil"
- lamp = 1
- xr_logic.pstor_store(db.actor, "nv_on", "nil")
- else
- xr_logic.pstor_store(db.actor, "nv_on", section)
- end
- alife():create(section, db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
- nightvision.pnv(ppe,lamp)
- end
- function convert_wpn(sect,id)
- if sect == "wpn_binoc" or sect == "wpn_knife" then return end
- local base_sect = get_base_section(sect)
- if sect == base_sect and not string.find(sect,"_arena") then
- sect = base_sect.."_aa"
- local wobj = alife():object(id)
- local wdat = weap_data.get_weapon_data(wobj)
- alife():release(wobj, true)
- local pos = db.actor:position() --vector():set(0,100,0)
- pos.x = pos.x + 0.5
- local sobj = alife():create(sect, pos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
- if sobj then
- table.insert(wpnid,sobj.id)
- weap_data.set_weapon_data(wdat,sobj)
- end
- end
- end
- function convert_addon(sect,id)
- if is_scope(sect) then
- local base_sect = get_base_section(sect)
- if sect == base_sect then
- sect = base_sect.."_aa"
- end
- local fake_sect = "fake"..string.sub(sect, -(string.len(sect)-3))
- alife():create(fake_sect, db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
- alife():release(alife():object(id), true)
- end
- end
- function is_scope(section)
- local ini = system_ini()
- local addon_class = ini:r_string(section, "class")
- return addon_class == "WP_SCOPE"
- end
- function check_gun_scope(weapon_section, scope_section) -- подходит ли эта линейка прицелов к этой линейке стволов.
- local result
- local newsect, scope_type = "nil", "a"
- if string.find(weapon_section,"_arena") then
- result = false
- return result, newsect
- end
- local weapon_base_section = get_base_section(weapon_section)
- local scope_base_section = get_base_section(scope_section)
- local scope_status, scope_name = 0, "nil"
- if string.sub(weapon_base_section,1,4) ~= "wpn_" then
- result = false
- return result, newsect
- end
- local ini = system_ini()
- scope_status = ini:r_float(weapon_section, "scope_status")
- if scope_status == 0 then
- result = false
- return result, newsect
- end
- if not ini:line_exist(weapon_section, "scope_name") then
- result = false
- return result, newsect
- else
- scope_name = get_base_section(ini:r_string(weapon_section, "scope_name"))
- if scope_name == scope_base_section then
- result = true
- if weapon_base_section == weapon_section then
- newsect = weapon_section.."_a" -- если оружие в базовой секции, ставим стандартные патроны, информацию о прицеле не ставим
- else
- newsect = string.sub(weapon_section,1,(string.len(weapon_section)-1)) -- иначе сбрасываем информацию о прицеле
- end
- if scope_base_section == scope_section then
- scope_type = "a" -- если прицел в базовой секции (врядли, ну а вдруг?), ставим стандарт не разбираясь
- else
- scope_type = string.sub(scope_section,-1) -- иначе смотрим, что за прицел
- end
- newsect = newsect..scope_type
- else
- result = false
- return result, newsect
- end
- end
- return result, newsect
- end
- function fake_scope_effect(sect)
- local real_sect = "wpn"..string.sub(sect, -(string.len(sect)-4))
- if not is_scope(real_sect) then
- return
- end
- local scope_type = string.sub(sect,-1)
- local weapon1, weapon2 = db.actor:item_in_slot(1), db.actor:item_in_slot(2)
- local aweapon, pweapon, pslot, ss, sn = nil, nil, nil, nil, nil
- local aslot = db.actor:active_slot()
- if aslot == 1 then -- если активен первый слот, сначала пытаемся поставить прицел туда
- aweapon = weapon1
- pweapon = weapon2
- pslot = 2
- else -- иначе начинаем со 2 слота
- aslot = 2
- aweapon = weapon2
- pweapon = weapon1
- pslot = 1
- end
- local newsect
- if aweapon ~= nil then -- если в слоте есть оружие,
- local result, newsect = check_gun_scope(aweapon:section(),real_sect)
- if result then --и на него можно поставить данный прицел
- if check_scope_attached(aweapon) == false or scope_type ~= string.sub(aweapon:section(),-1) then
- fake_scope_effect_set_scope(aslot,newsect) -- ставим именно сюда
- return
- else
- end
- end
- else
- end
- if pweapon ~= nil then -- если в первой попытке прицел не поставился, и в слоте есть оружие,
- local result, newsect = check_gun_scope(pweapon:section(),real_sect)
- if result then --и на него можно поставить данный прицел
- if check_scope_attached(pweapon) == false or scope_type ~= string.sub(pweapon:section(),-1) then
- fake_scope_effect_set_scope(pslot,newsect) -- ставим именно сюда
- return
- else
- end
- end
- else
- end
- -- попробовали на оба слота, никуда не ставится. Возвращаем прицел в инвентарь
- alife():create(sect, db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
- --]]
- end
- function fake_scope_effect_set_scope(slot, newsect)
- local wpn = db.actor:item_in_slot(slot)
- if wpn then
- local ss = system_ini():r_float(wpn:section(), "scope_status")
- local wsect = newsect --
- local wobj = alife():object(wpn:id())
- local wdat = weap_data.get_weapon_data(wobj)
- wdat.visual = system_ini():r_string(newsect, "visual") -- обновляем визуал
- if ss == 1 then
- detach_old_scope(wpn:section()) -- если прицел предустановленный, возвращаем его в инвентарь.
- elseif wdat.addon_flags/2 == math.floor(wdat.addon_flags/2) then -- если флаги 0,2,4 или 6 - прицел не установлен.
- wdat.addon_flags = wdat.addon_flags + 1 -- устанавливаем
- if wdat.addon_flags > 7 then -- если флаги зашкаливают
- wdat.addon_flags = wdat.addon_flags - 8 -- возвращаем на круги своя
- end
- else
- detach_old_scope(wpn:section()) -- если уже был установленный прицел, возвращаем его в инвентарь.
- end
- alife():release(wobj,true)
- local pos = db.actor:position()
- pos.x = pos.x + 0.5
- local sobj = alife():create(wsect, pos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
- if sobj then
- table.insert(wpnid,sobj.id)
- weap_data.set_weapon_data(wdat,sobj)
- end
- return sobj
- end
- end
- function fake_scope_effect_take_wpn()
- if table.getn(wpnid) > 0 then
- while table.getn(wpnid) > 0 do
- local wid = wpnid[1]
- local weapon = level.object_by_id(wpnid[1])
- if weapon then
- db.actor:transfer_item(weapon,db.actor)
- table.remove(wpnid,1)
- else
- return
- end
- end
- end
- end
- function detach_old_scope(weapon_section)
- local ini = system_ini()
- local scope_name = get_base_section(ini:r_string(weapon_section, "scope_name"))
- local scope_type = string.sub(weapon_section,-1)
- local fake_scope_section = "fake"..string.sub(scope_name, -(string.len(scope_name)-3)).."_"..scope_type..scope_type
- alife():create(fake_scope_section, db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
- end
- function check_scope_attached(wpn)
- local ss = system_ini():r_float(wpn:section(), "scope_status")
- local wobj = alife():object(wpn:id())
- local wdat = weap_data.get_weapon_data(wobj)
- return (wdat.addon_flags/2 ~= math.floor(wdat.addon_flags/2)) or (ss == 1) -- если флаги 1,2,5 или 5 - прицел установлен.
- end
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement