-- Получение предмета
function checking_taken_item(obj)
	checking_taken_zonedocs(obj)
	checking_taken_pdas(obj)
	checking_taken_item_vzn(obj)
	peshera_go(obj)
end

-- stealth
function stealth_start()
	timer("run",1.0,"kostya_dialog.stealth_start2()")
end
function stealth_start2()
	level.add_pp_effector ("teleport.ppe", 2006, false)
	say([[anomaly\teleport_work_1]])
	create("tm_brother_labirint",xyz(-313.31903076172,62.234169006348,202.46311950684),38734,2987)
end
function stealth1_have()
	local obj = snp.object_by_section_offline("arhara_seif")
	if obj then
		release(obj)
	end
	news_manager.relocate_item("out", "arhara_seif")
end
function stealth1_done()
	timer("run",0.5,"kostya_dialog.stealth1_done2()")
end
function stealth1_done2()
	level.add_pp_effector ("teleport.ppe", 2006, false)
	say([[anomaly\teleport_work_1]])
	release(server_object(snp.object_by_section("tm_brother_labirint"):id()))
	tm_brother_2chaes_spawn()
end
function tm_brother_2chaes_spawn()
	local se_obj = create("tm_brother_2chaes",xyz(84.960639953613,8.7271690368652,113.30625152588),56965,2566)
	ai:assign_story_id(se_obj.id,9969)
create("tm_brother_2chaes1",xyz(84.08,8.73,115.83),56874,2566)
create("tm_brother_2chaes2",xyz(83.90,8.73,112.32),56869,2566)
end
function stealth2_done()
	local obj = create("s_inventory_box_stealth1",xyz(157.05128479004,12.03516960144,82.391082763672),39526,1229)
	map_spot(obj.id, "treasure", "Squealer's Stash")
	local obj = create("s_inventory_box_stealth2",xyz(-73.545913696289,15.663717269897,2.5357427597046),129042,319)
	map_spot(obj.id, "treasure", "Squealer's Stash")
	local obj = create("s_inventory_box_stealth3",xyz(-136.37683105469,9.9986381530762,-196.55345275879),102496,629)
	map_spot(obj.id, "treasure", "Squealer's Stash")
	local obj = create("s_inventory_box_stealth4",xyz(-163.355,5.15,-61.527),21204,8344)
	map_spot(obj.id, "treasure", "Squealer's Stash")
	local obj = create("s_inventory_box_stealth5",xyz(23.35853767395,0.18157379329205,-24.917425918579),209456,1046)
	map_spot(obj.id, "treasure", "Squealer's Stash")
	sms("Received a tip on the cache", nil, nil, 10000)
end
function stealth5_done()
	find_and_release("tm_brother_2chaes")
	find_and_release("tm_brother_2chaes1")
	find_and_release("tm_brother_2chaes2")
end
-- проверка на провал при убийстве, снятии амулета или одевании маскхалата
function stealth_fail_task(victim, who)
	if has_info("stealth2_done") and not has_info("stealth_find_pda_done") and (not who or who:id() == db.actor:id()) then
		give_info("stealth_find_pda_fail")
	end
end
-- подъем рюкзака
function stealth_on_take(box)
	local section = box:section()
	if string.find(section, "s_inventory_box_stealth") then
		give_info("stealth_find_pda_have"..string.sub(section,24,24))
	end
end
-- сдача ПДА
function stealth_find_pda_done()
	lost_all("stealth_pda")
end
function stealth_blow_sidor_done()
	create("m_inventory_box_tmpresent",xyz(-322.77,62.23,196.61),32818,2909)
	braad_test.lab_sar()
end

function krest_topor()
local b = {
	{position={x=-90.577209472656,y=4.2523427009583,z=89.188056945801},gv=2881,lv=115499},
	{position={x=116.68508911133,y=-0.00091594457626343,z=103.09552001953},gv=2885,lv=282454},
	{position={x=44.239944458008,y=-0.0053302049636841,z=16.853719711304},gv=2885,lv=224518}
}
    local a = table.random(b)
    create("skelet_ded", xyz(a.position.x,a.position.y,a.position.z), a.lv, a.gv)
end

local peshera_table = keyvals("OP2"):get("peshera_table", {})

local ignore_items={
	["device_torch"]=true,
	["device_pda"]=true,
	["bolt"]=true
}
function peshera_go(obj)
	if has_info("peshera_go") and level.name()=="peshera" then
		if not ignore_items[obj:section()] then
			peshera_table[obj:id()] = true
		end
	end
end

function peshera_start()
	level.start_stop_menu(level.main_input_receiver(), true)
	if not spawn_level_changer.telepot_allowed("snotvornoe_tele_custom",false) then
		spawn_level_changer.teleport_fail("snotvornoe_tele")
		return
	end
	
	local box = level_object(server_object("l01_escape_inventory_box_0003").id)
	give_info("biznes_remove_special_item")
	db.actor:iterate_inventory(
		function(dummy,item)
			if not protected_items.actor_items_keep(item:section()) then
				db.actor:transfer_item(item, box)
			end
		end
	,db.actor)
	create("zamok", xyz(0,0,0), 0, 0, box:id())
	disable_info("biznes_remove_special_item")

	create_teleport("peshera_blok_tp",xyz(-112.609199523926,-9.9281539916992,-34.9218902587891),12288,2868)

	give_info("peshera_go")
	if level.get_game_difficulty() < 3 then
		snp.invul_on()
	end
	spawn_level_changer.teleport_start("snotvornoe_tele_custom") 
end

function peshera_end()
	give_info("teleport_started")
	level.start_stop_menu(level.main_input_receiver(), true)
	
	if not spawn_level_changer.telepot_allowed("shaxter_tele_custom",false) then
		spawn_level_changer.teleport_fail("shaxter_tele")
		return
	end
	
	snp.invul_off()
	give_info("biznes_remove_special_item")
	db.actor:iterate_inventory(
		function(dummy,item)
			if not protected_items.actor_items_keep(item:section()) then
				release(server_object(item:id()))
			end
		end
	,db.actor)

	local obj
	for id,v in pairs(peshera_table) do
		obj = server_object(id) --and obj.parent_id ~= db.actor:id() 
		if obj and not protected_items.actor_items_keep(obj:section_name()) then
			release(obj)
		end
	end
	disable_info("biznes_remove_special_item")
	peshera_table = nil
	container:remove("peshera_table")

	for id,obj in pairs(db.creatures) do
		if obj and iAmMonster[obj:clsid()] then
			release(server_object(id))
		end
	end

	for i=1,65535 do
		obj = server_object(i)
		if obj then
			if obj:section_name() == "af_part_monolit" or obj:section_name() == "m_inventory_box16" then
				release(obj)
			end
		end
	end

	release_teleport("peshera_blok_tp")
	disable_info("peshera_go")
	spawn_level_changer.teleport_start("shaxter_tele_custom") 
end

function kuv_hit(who)
	if not db.actor:active_item() or not who or who:id() ~= db.actor:id() then return end

	local wpn = db.actor:active_item()
	local active_slot = db.actor:active_slot()

	-- Падение выносливости от кувалды
	if wpn:section() == "wpn_kuvalda" then
		db.actor.power = -level.get_game_difficulty()/10
	end

	-- Взрыв убитого ствола
	if wpn:condition() < 0.1 and math.random() < 0.2-wpn:condition()*2 and wpn:section() ~= "wpn_shmel" and not isKnifeWeapon(wpn) then
		amk_particle.amk_particle({
			particle="explosions\\explosion_fuelcan",
			pos=db.actor:position(),
			sound=[[weapons\t_rgd5_explosion]]
		})
		level.add_pp_effector("amk_shoot.ppe", 2011, false)

		local h = hit()
		h.draftsman = db.actor
		h.direction = vector_rotate_y(db.actor:direction(), 180)
		h:bone("bip01_spine")
		h.type = hit.explosion
		h.power = 60
		h.impulse = 500
		db.actor:hit(h)

		timer("run", 0.2, "kostya_dialog.remove_wpn("..tostring(wpn:id())..")")
	end
end
function remove_wpn(id)
	local obj = server_object(id)
	if obj then
		release(obj, true)
	end
end

-- Взносы
function vzn_begin()
	return has_money(2000000) and
		has_info("sar_monolith_destroy")
end
function vzn()
	return
		has_money(2000000) and
		has_info("vzn_begin") and
		not	has_info("vzn_start") and
		not	has_info("acv_vzn1") and
		not (
			has_info("vzn1") and
			has_info("vzn2") and
			has_info("vzn3") and
			has_info("vzn4") and
			has_info("vzn5") and
			has_info("vzn6") and
			has_info("vzn7") and
			has_info("vzn8") and
			has_info("vzn9") and
			has_info("vzn10") and
			has_info("vzn11") and
			has_info("vzn12") and
			has_info("vzn13") and
			has_info("vzn14") and
			has_info("vzn15") and
			has_info("vzn16")
		)
end
function vzn_end()
	return
		has_info("vzn1_done") and
		has_info("vzn2_done") and
		has_info("vzn3_done") and
		has_info("vzn4_done") and
		has_info("vzn5_done") and
		has_info("vzn6_done") and
		has_info("vzn7_done") and
		has_info("vzn8_done") and
		has_info("vzn9_done") and
		has_info("vzn10_done") and
		has_info("vzn11_done") and
		has_info("vzn12_done") and
		has_info("vzn13_done") and
		has_info("vzn14_done") and
		has_info("vzn15_done") and
		has_info("vzn16_done")
end

local vzn_sections={
		["vzn_mogila"]=true,
		["vzn_platok"]=true,
		["vzn_vodka"]=true,
		["vzn_prez_zapis"]=true,
		["vzn_voen_zapis"]=true,
		["vzn_ganteli"]=true,
		["vzn_grob"]=true,
		["vzn_rover"]=true,
		["vzn_pesok"]=true,
		["vzn_darwin"]=true,
		["vzn_treasure_item"]=true,
		["vzn_mladen"]=true,
		["vzn_pensia"]=true,
		["vzn_noty"]=true,
		["vzn_kuvalda"]=true
}

function checking_taken_item_vzn(obj) -- взятие тайника
	local section = obj:section()
	if	vzn_sections[section] then
		give_info("vzn_have")
	end
	if section == "vzn_treasure_item" then
		-- лотерея
		lost_item("vzn_treasure_item")
		amk.spawn_item_in_inv("treasure_item", db.actor)
		amk.spawn_item_in_inv("vzn_medal", db.actor)
		amk.spawn_item_in_inv(vzn_taynik_stvol(), db.actor)
	end
	if section == "vzn_mladen" then
		-- младенец
		local snd = voice([[characters_voice\scenario\trader\plach]])
		snd:stop()
		snd:play_no_feedback(db.actor, sound_object.s2d, 1.0, vector(), 1.0)
	end
end

function vzn_fill(vzn) -- создание тайника
	if     vzn == 11 then
		-- контрик
		create("vzn_stalker_kontrik",xyz(-209.23837280273,-20.614948272705,-149.44313049316),43943,61)
		lost_money(450000)
	elseif vzn == 12 then
		-- лотерея
		spawn_restrictor.vzn12_restr()
		lost_money(100000)
	else
		-- спавним тайник и получаем ссылку на него
		local obj = taynik_spawn.vzn_taynik()

		-- Наполняем тайник
		vzn_fill_taynik(vzn_taynik_stvol(), 1, obj)

		if     vzn == 1 then
			vzn_fill_taynik("vzn_venok", 10, obj)
			vzn_fill_taynik("vzn_lopata", 2, obj)
			vzn_fill_taynik("vzn_mogila", 1, obj)
			lost_money(200000)
		elseif vzn == 2 then
			vzn_fill_taynik("vzn_platok", 100, obj)
			lost_money(300000)
		elseif vzn == 3 then
			vzn_fill_taynik("vodka", 100, obj)
			vzn_fill_taynik("vzn_vodka", 1, obj)
			lost_money(400000)
		elseif vzn == 4 then
			if     has_info("vzn_temp1") then
				vzn_fill_taynik("vzn_prez", 1, obj)
				vzn_fill_taynik("vzn_stirka", 1, obj)
				vzn_fill_taynik("vzn_vivarka", 1, obj)
				vzn_fill_taynik("vzn_polovnik", 1, obj)
			elseif has_info("vzn_temp2") then
				vzn_fill_taynik("vzn_prez", 2, obj)
				vzn_fill_taynik("vzn_stirka", 2, obj)
				vzn_fill_taynik("vzn_vivarka", 2, obj)
				vzn_fill_taynik("vzn_polovnik", 2, obj)
			elseif has_info("vzn_temp3") then
				vzn_fill_taynik("vzn_prez", 3, obj)
				vzn_fill_taynik("vzn_stirka", 3, obj)
				vzn_fill_taynik("vzn_vivarka", 3, obj)
				vzn_fill_taynik("vzn_polovnik", 3, obj)
			end
			vzn_fill_taynik("vzn_prez_zapis", 1, obj)
			lost_money(650000)
		elseif vzn == 5 then
			vzn_fill_taynik("voen_exo_outfit", 12, obj)
			vzn_fill_taynik("vzn_voen_zapis", 1, obj)
			lost_money(350000)
		elseif vzn == 6 then
			vzn_fill_taynik("vzn_ganteli", 1, obj)
			vzn_fill_taynik("vzn_gira", 2, obj)
			lost_money(200000)
		elseif vzn == 7 then
			vzn_fill_taynik("vzn_grob", 1, obj)
			lost_money(300000)
		elseif vzn == 8 then
			vzn_fill_taynik("vzn_rover", 1, obj)
			lost_money(800000)
		elseif vzn == 9 then
			vzn_fill_taynik("vzn_pesok", 3, obj)
			lost_money(500000)
		elseif vzn == 10 then
			vzn_fill_taynik("vzn_darwin", 1, obj)
			vzn_fill_taynik("vzn_darwin_zapis", 1, obj)
			lost_money(250000)
		elseif vzn == 13 then
			vzn_fill_taynik("vzn_mladen", 3, obj)
			lost_money(300000)
			voice([[characters_voice\scenario\trader\plach]]):play_at_pos(db.actor, obj.position, 0, sound_object.s3d+sound_object.looped)
		elseif vzn == 14 then
			vzn_fill_taynik("vzn_pensia", 1, obj)
			vzn_fill_taynik("vzn_polis", 1, obj)
			lost_money(250000)
		elseif vzn == 15 then
			vzn_fill_taynik("balalaika_a", 1, obj)
			vzn_fill_taynik("guitar_a", 1, obj)
			vzn_fill_taynik("harmonica_a", 1, obj)
			vzn_fill_taynik("vzn_torch", 1, obj)
			vzn_fill_taynik("vzn_noty", 1, obj)
			lost_money(400000)
		elseif vzn == 16 then
			vzn_fill_taynik("vzn_kuvalda", 1, obj)
			vzn_fill_taynik("vzn_krovosos_cocoon", 1, obj)
			lost_money(50000)
		end
	end

	give_info("vzn"..tostring(vzn))
	give_info("vzn_start")
end
function vzn_fill_taynik(section, cnt, obj)
	for i = 1,cnt do
		spawn_item_in_taynik(section, obj)
	end
end
function spawn_item_in_taynik(section, box)
	local item = create(section, xyz(0,0,0), 0, 0, box.id)
	level.client_spawn_manager():add(item.id, -1, fix_spawn_item_in_taynik, box)
end
function fix_spawn_item_in_taynik(box, id, item)
	local online_box = level_object(box.id) -- к моменту выхода предмета в онлайн box уже в онлайне
    online_box:transfer_item(item, online_box)
end

function vzn_done(vzn) -- удаление уникального хабара
	if     vzn == 1 then
		lost_all("vzn_venok")
		lost_all("vzn_lopata")
		lost_all("vzn_mogila")
	elseif vzn == 2 then
		lost_all("vzn_platok")
	elseif vzn == 3 then
		lost_all("vzn_vodka")
	elseif vzn == 4 then
		lost_all("vzn_prez")
		lost_all("vzn_prez_zapis")
		lost_all("vzn_stirka")
		lost_all("vzn_vivarka")
		lost_all("vzn_polovnik")
	elseif vzn == 5 then
		lost_all("vzn_voen_zapis")
	elseif vzn == 6 then
		lost_all("vzn_ganteli")
		lost_all("vzn_gira")
	elseif vzn == 7 then
		lost_all("vzn_grob")
	elseif vzn == 8 then
		lost_all("vzn_rover")
	elseif vzn == 9 then
		lost_all("vzn_pesok")
	elseif vzn == 10 then
		play_tush()
		lost_all("vzn_darwin")
		lost_all("vzn_darwin_zapis")
		got_money(300000)
	elseif vzn == 11 then
		find_and_release("vzn_stalker_kontrik")
	elseif vzn == 12 then
		lost_all("vzn_medal")
	elseif vzn == 13 then
		lost_all("vzn_mladen")
	elseif vzn == 14 then
		lost_all("vzn_pensia")
		lost_all("vzn_polis")
	elseif vzn == 15 then
		lost_all("vzn_torch")
		lost_all("vzn_noty")
		got_money(200000)
	elseif vzn == 16 then
		lost_all("vzn_kuvalda")
		lost_all("vzn_krovosos_cocoon")
	end

	give_info("vzn"..tostring(vzn).."_done")
	disable_info("vzn_start")
	disable_info("vzn_have")
	disable_info("vzn_temp1")
	disable_info("vzn_temp2")
	disable_info("vzn_temp3")
	disable_info("vzn_temp4")
end
function vzn_taynik_stvol()
	local vzn_stvol = {
		"wpn_benelli_m3_tactik",
		"wpn_akms_m1",
		"wpn_fn_fal_c1",
		"wpn_kord_m1",
		"wpn_vepr12_col",
		"wpn_svd_m3",
		"wpn_rpk16",
		"wpn_tkpd",
		"wpn_awm",
		"wpn_mk11",
		"wpn_fist_m",
		"wpn_cs5_m1",
		"wpn_hand_bat",
		"wpn_awm_f",
		"wpn_hk417_gl"
	}
	local i
	-- Ищем неиспользованный ствол
	repeat
		i = math.random(#vzn_stvol)
	until not has_info("vzn_stvol"..tostring(i))

	give_info("vzn_stvol"..tostring(i))
	return vzn_stvol[i]
end

function vzn1()			vzn_fill(1) end
function vzn1_done()	vzn_done(1) end
function vzn2() 		vzn_fill(2) end
function vzn2_done()	vzn_done(2) end
function vzn3() 		vzn_fill(3) end
function vzn3_done()	vzn_done(3) end
function vzn4()			vzn_fill(4) end
function vzn4_done()	vzn_done(4) end
function vzn5()			vzn_fill(5) end
function vzn5_done()	vzn_done(5) end
function vzn6()			vzn_fill(6) end
function vzn6_done()	vzn_done(6) end
function vzn7()			vzn_fill(7) end
function vzn7_done()	vzn_done(7) end
function vzn8()			vzn_fill(8) end
function vzn8_done()	vzn_done(8) end
function vzn9()			vzn_fill(9) end
function vzn9_done()	vzn_done(9) end
function vzn10()		vzn_fill(10) end
function vzn10_done()	vzn_done(10) end
function vzn11()		vzn_fill(11) end
function vzn11_done()	vzn_done(11) end
function vzn12()		vzn_fill(12) end
function vzn12_done()	vzn_done(12) end
function vzn13()		vzn_fill(13) end
function vzn13_done()	vzn_done(13) end
function vzn14()		vzn_fill(14) end
function vzn14_done()	vzn_done(14) end
function vzn15()		vzn_fill(15) end
function vzn15_done()	vzn_done(15) end
function vzn16()		vzn_fill(16) end
function vzn16_done()	vzn_done(16) end

function play_tush()
	give_info("sidor_tush")
	timer("stop_tush", 18.3, 0)
end
function give_ak_strelka()
	got("wpn_ak104t",1)
end
function play_video_strelok()
  game.start_tutorial("intro_game_2")
end
function play_video_kontrik()
  game.start_tutorial("death_machine_dream_2")
end
function play_video_good_end()
  game.start_tutorial("mov_refuse_osoznanie_2")
end
function actor_vzn_back()
	got("vzn_pochet_gramota")
	play_tush()
	give_info("vzn_reset")
	disable_info("vzn_reset")
end
function gg_monolit()
	db.actor:set_character_community("monolith", 0, 0)
end
function vzn5_have_voen_exo()
	return has_good("voen_exo_outfit",12)
end
function vzn5_lost_voen_exo()
	lost_good("voen_exo_outfit",12)
end
-- Взносы end

-- рандомная выдача редких патронов qty раз
function give_ammo(qty)
	local ammo = {
		"ammo_gauss",
		"ammo_minigun",
		"ammo_23x76_shrap",
		"ammo_7.62x54r",
		"ammo_7.62x51box",
		"ammo_7.62x51_box",
		"ammo_8.6x70_jsp",
		"ammo_8.6x70_ap",
		"ammo_12.7x55_fmj",
		"ammo_12.7x55_ap",
		"ammo_12.7x108"
	}
	for i =1,qty do
		got(ammo[math.random(#ammo)],1)
	end
end

function checking_taken_tm_docs(obj)
	if 	has("tm_docs01") and has("tm_docs02") and has("tm_docs03") and 
		has("tm_docs04") and has("tm_docs05") and has("tm_docs06") and 
		has("tm_docs07") and has("tm_docs08") and has("tm_docs09") and 
		has("tm_docs10") and has("tm_docs11") and has("tm_docs12") and 
		has("tm_docs13") then
		if not has_info("tm_find_all") then
			give_info("tm_find_all")
			sms("%c[sender]"..translate("name_dragunov")..":\\n%c[sms_red]"..translate("checking_taken_item63_0_0"), nil, "dragunof", 31000, nil, [[sms\dragunov\tm_docs]])
			spawn_tm_taynik()
			local se_obj = create("tm_teleport_1",xyz(24.6673412323,56.192798614502,-5.0582308769226),5907,2417)
			set_value("tm_teleport_1", se_obj.id)
			se_obj = create("tm_teleport_2",xyz(23.798603057861,70.392623901367,45.316135406494),5395,2417)
			set_value("tm_teleport_2", se_obj.id)
			spawn_restrictor.tm_sr1()
		end
	end
end

function tm_spawn1()
	local obj = create("z_inventory_box01",xyz(10.472078323364,49.034076690674,-15.613767623901),3388,2417)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box02",xyz(19.680177688599,48.432109832764,-4.1294741630554),4341,2417)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box03",xyz(3.4836528301239,56.036026000977,35.414047241211),2518,2405)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box04",xyz(60.87622833252,53.735683441162,26.076965332031),9266,2417)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box05",xyz(60.85319519043,53.796840667725,21.076036453247),9788,2417)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box06",xyz(61.789813995361,60.531970977783,41.451103210449),9966,2402)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box07",xyz(9.1720209121704,20.386127471924,-11.211741447449),6333,2453)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box08",xyz(44.268180847168,58.320827484131,-24.319999694824),8050,2417)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box09",xyz(-19.819829940796,64.045745849609,-31.615013122559),591,2417)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box10",xyz(80.993240356445,71.973617553711,-40.810508728027),6403,2417)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box11",xyz(42.494750976563,69.035263061523,38.658748626709),4591,2417)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box12",xyz(64.846755981445,67.564109802246,45.584968566895),4591,2417)
	map_spot(obj.id, "treasure", "Monolith Guard")
	local obj = create("z_inventory_box13",xyz(51.092010498047,49.359004974365,-17.654895782471),8798,2416)
	map_spot(obj.id, "treasure", "Monolith Guard")
	sms("Received a tip on the cache", nil, nil, 10000)
end
function checking_take_tm_docs14(obj)
	for a=1,65534,1 do
	local obj=server_object(a)
	if obj and string.find(obj:name(),"tm_docs") then
		release(obj,true)
	end
	end
	release_teleport("tm_teleport_4")
	give_info("tm_find_done")
end
function spawn_tm_taynik()
	local obj = create("z_inventory_box14",xyz(23.798603057861,70.392623901367,45.316135406494),5395,2417)
	map_spot(obj.id, "treasure", "Cache")
	sms("Received a tip on the cache", nil, nil, 10000)
end
function remove_tm_taynik()
	release(snp.object_by_section_offline("z_inventory_box14"))
end


-- Proper71 docs
-- Вниманию оптимизаторов: в разделе docs ничего не оптимизировать! Даже не трогать порядок выполнения команд! Из-за использования disable в поршнях и некоторых глюков из-за 
--параллельного выполнения процессов в движке не все работает так, как кажется на первый взгляд. Поэтому ничего здесь не трогайте.
function checking_taken_zonedocs(obj)
	if string.find(obj:section(),"zonedocs") then
		give_info("zonedocs_have"..string.sub(obj:section(),string.find(obj:section(),"_")+1))

		local total = 60
		if     has_info("voronin_docs1_start_as") then
			total = 24
		elseif has_info("voronin_docs1_start_yan") then
			total = 23
		elseif has_info("voronin_docs1_start_dt") then
			total = 22
		elseif has_info("voronin_docs1_start_atp") then
			total = 15
		elseif has_info("voronin_docs1_start_td") then
			total = 30
		elseif has_info("voronin_docs1_start_puzir") then
			total = 6
		elseif has_info("voronin_docs1_start_agro") then
			total = 26
		elseif has_info("voronin_docs1_start_marsh") then
			total = 30
		elseif has_info("voronin_docs1_start_esc") then
			total = 60
		elseif has_info("voronin_docs1_start_garbage") then
			total = 60
		elseif has_info("voronin_docs1_start_bar") then
			total = 60
		end

		if     has("zone_docs",total-1) then
			give_info("voronin_docs1_have")
		elseif has("zone_docs",total-3) then
			give_info("voronin_docs1_almost_have")
		end

		release(obj:id())
		-- удаляем дубликаты
		if  (obj:section()=="zonedocs_26" and level.name() == "l03u_agr_underground") or
			(obj:section()=="zonedocs_22" and (level.name() == "l06_rostok" or level.name() == "l05_bar"))
		then
			local sobj
			for i = 1,65534 do
				sobj = server_object(i)
				if sobj then
					if  (sobj:section_name() == "zonedocs_26" and level.name() == "l03u_agr_underground") or
						(sobj:section_name() == "zonedocs_22" and (level.name() == "l06_rostok" or level.name() == "l05_bar"))
					then
						release(sobj,true)
						break
					end
				end
			end
		end

		create("zone_docs",xyz(0,0,0),0,0,0)
	end
end

function zonedocs_buy()
	got("zonedocs_0",1)
	give_info("acv_docs_fail")
end

function voronin_docs1_done()
	lost_all("zone_docs")
	god_docs_off()
	if not has_info("voronin_docs1_have") then -- удаляем ненайденные части
		local sobj
		for i = 1,65534 do
			sobj = server_object(i)
			if sobj and string.find(sobj:name(),"zonedocs") then
				release(sobj,true)
			end
		end
	end

	if     has_info("voronin_docs1_start_as") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_as")
		else
			give_info("voronin_docs1_fail_as")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_yan") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_yan")
		else
			give_info("voronin_docs1_fail_yan")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_dt") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_dt")
		else
			give_info("voronin_docs1_fail_dt")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_atp") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_atp")
		else
			give_info("voronin_docs1_fail_atp")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_td") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_td")
		else
			give_info("voronin_docs1_fail_td")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_puzir") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_puzir")
		else
			give_info("voronin_docs1_fail_puzir")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_agro") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_agro")
		else
			give_info("voronin_docs1_fail_agro")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_marsh") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_marsh")
		else
			give_info("voronin_docs1_fail_marsh")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_esc") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_esc")
		else
			give_info("voronin_docs1_fail_esc")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_garbage") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_garbage")
		else
			give_info("voronin_docs1_fail_garbage")
			give_info("acv_docs_fail")
		end
	elseif has_info("voronin_docs1_start_bar") then
		if has_info("voronin_docs1_have") then
			give_info("voronin_docs1_done_bar")
		else
			give_info("voronin_docs1_fail_bar")
			give_info("acv_docs_fail")
		end
	end

	if has_info("zonedocs_have0") then
		give_info("acv_docs_fail")
	end
	if has_info("voronin_docs1_have") then
		this.give_ammo(3)
	end
	give_info("voronin_docs1_reset")
end

function voronin_docs1_refuse()
	lost_all("zone_docs")
	god_docs_off()
	if not has_info("voronin_docs1_have") then -- удаляем ненайденные части
		local sobj
		for i = 1,65534 do
			sobj = server_object(i)
			if sobj and string.find(sobj:name(),"zonedocs") then
				release(sobj,true)
			end
		end
	end

	give_info("voronin_docs1_done_as")
	give_info("voronin_docs1_done_yan")
	give_info("voronin_docs1_done_dt")
	give_info("voronin_docs1_done_atp")
	give_info("voronin_docs1_done_td")
	give_info("voronin_docs1_done_puzir")
	give_info("voronin_docs1_done_agro")
	give_info("voronin_docs1_done_marsh")
	give_info("voronin_docs1_done_esc")
	give_info("voronin_docs1_done_garbage")
	give_info("voronin_docs1_done_bar")
	give_info("voronin_docs1_end_refuse")
	give_info("acv_docs_fail")
	give_info("voronin_docs1_reset")
end

function t_zonedocs_bar()
	taynik_spawn.t_zonedocs("bar")
end
function t_zonedocs_garbage()
	taynik_spawn.t_zonedocs("garbage")
end
function t_zonedocs_esc()
	taynik_spawn.t_zonedocs("esc")
end
function t_zonedocs_marsh()
	taynik_spawn.t_zonedocs("marsh")
end
function t_zonedocs_agro()
	taynik_spawn.t_zonedocs("agro")
end
function t_zonedocs_puzir()
	taynik_spawn.t_zonedocs("puzir")
end
function t_zonedocs_td()
	taynik_spawn.t_zonedocs("td")
end
function t_zonedocs_atp()
	taynik_spawn.t_zonedocs("atp")
end
function t_zonedocs_dt()
	taynik_spawn.t_zonedocs("dt")
end
function t_zonedocs_yan()
	taynik_spawn.t_zonedocs("yan")
end
function t_zonedocs_as()
	taynik_spawn.t_zonedocs("as")
end

function zonedocs_gg_kill()
	db.actor:kill(db.actor)
end
function zonedocs_gg_reward()
	this.give_ammo(30)
	got("wpn_kac_pdw",1)
	got("wpn_sayga_un",1)
	got("wpn_bren_ten_cr",1)
	got("wpn_cs5",1)
	got("af_pero",1)
	archievements.acv_docs()
end

function add_docs_spot()
	for i=1,65534 do
		obj = server_object(i)

		if obj and string.find(obj:section_name(), "zonedocs") then
			map_spot(obj.id, "profi", "add_docs_spot_0")
			db.god.c[5] = db.god.c[5]+1
		end
	end
end

function remove_docs_spot()
	for i=1,65534 do
		obj = server_object(i)

		if obj and string.find(obj:section_name(), "zonedocs") and has_map_spot(obj.id, "profi") ~= 0 then
			del_map_spot(obj.id, "profi")
		end
	end
end

function god_docs_off()
	db.god.u[5] = false
	ui_mm_opt_main.GodHudUpdate()
end

function kostya_biznes1_have()
	return has("af_buliz",5)
end
function kostya_biznes1_done()
	lost("af_buliz",5)
end

function doktor_lekar1_have()
	if not has_info("doktor_lekar1_start") or has_info("acv_lekar2") then return end

	local cnt = get_value("lekar",0)
	cnt = cnt+1

	if cnt == 1 then
		sms("%c[sender]"..translate("name_doktor")..":\\n%c[sms_red]"..translate("sms_doctor_doktor_lekar1_have_1_0"), nil, "doctor", 30000, nil, [[sms\doctor\doktor_lekar1_have_1]])
	elseif cnt == 4 then
		sms("%c[sender]"..translate("name_doktor")..":\\n%c[sms_red]"..translate("sms_doctor_doktor_lekar1_have_2_0"), nil, "doctor", 30000, nil, [[sms\doctor\doktor_lekar1_have_2]])
	elseif cnt == 7 then
		sms("%c[sender]"..translate("name_doktor")..":\\n%c[sms_red]"..translate("sms_doctor_doktor_lekar1_have_3_0"), nil, "doctor", 30000, nil, [[sms\doctor\doktor_lekar1_have_3]])
	elseif cnt == 10 then
		sms("%c[sender]"..translate("name_doktor")..":\\n%c[sms_red]"..translate("sms_doctor_doktor_lekar1_have_4_0"), nil, "doctor", 30000, nil, [[sms\doctor\doktor_lekar1_have_4]])
		give_info("doktor_lekar1_have")
	elseif cnt == 20 then
		give_info("acv_lekar")
	elseif cnt == 30 then
		give_info("acv_lekar2")
		del_value("lekar")
		return
	end

	set_value("lekar",cnt)
end

function doktor_lekar1_money()
	if has_info("acv_lekar2") then
		got_money(math.random(500,1000))
	end
end

function check_pair_pda_1(pda_section)
	if has(pda_section) then
		if not has_info("strelok_taynik_stop") then
			if not has_info("strelok_taynik_pda3_12_have") then
				local obj = create("s_inventory_box3_3",xyz(73.26683807373,1.484278678894,241.13470458984),29207,1244)
				map_spot(obj.id, "treasure", "Strelok's Stash")
				sms("Received a tip on the cache", nil, nil, 10000)
				give_info("strelok_taynik_pda3_12_have")
			end
		end
	end
end

function check_pair_pda_2(pda_section)
	if has(pda_section) then
		if not has_info("strelok_taynik_stop") then
			give_info("strelok_taynik_pda2_have")
		end
	end
end

local pda_sections={
	["strelok_taynik_pda1"]=function() 
		if has_info("strelok_taynik_pda1_found") then
			if not has_info("strelok_taynik_stop") then
				give_info("strelok_taynik_pda1_have")
				if not has_info("strelok_taynik_pda1_xvatit_spawn") then
					local obj = create("s_inventory_box1_2",xyz(176.28475952148,17.963838577271,40.265209197998),256932,2145)
					map_spot(obj.id, "treasure", "Strelok's Stash")
					sms("Received a tip on the cache", nil, nil, 10000)
					create("m_controller_normal",xyz(87.854019165039,-2.5235424041748,86.012077331543),199525,2143)
					create("m_controller_normal_fat",xyz(87.854019165039,-2.5235424041748,86.012077331543),199525,2143)
					create("m_controller_old",xyz(160.51348876953,-2.2140634059906,89.546524047852),249284,2177)
					create("m_controller_old_fat",xyz(160.51348876953,-2.2140634059906,89.546524047852),249284,2177)
					xr_effects.play_zvuk3()
					give_info("strelok_taynik_pda1_xvatit_spawn")
				end
			end
		else
			give_info("strelok_taynik_stop")
		end
	end,
	["strelok_taynik_pda1_2"]=function(obj)
	    if not has_info("strelok_taynik_pda1_done") then
			sms("%c[sender]"..translate("name_strelok")..":\\n%c[sms_red]"..translate("sms_strelok_strelok_taynik_pda1_2_0"), nil, "strelok", 30000, nil, [[sms\strelok\strelok_taynik_pda1_2]])
			this.spawn_s_teleport1_2()
			spawn_restrictor.strelok_taynik_pda1_3_1_sr1()
		end
		amk.remove_item(obj)
	end,
	["strelok_taynik_pda1_3"]=function(obj)
		if not has_info("strelok_taynik_pda1_done") then
			sms("%c[sender]"..translate("name_strelok")..":\\n%c[sms_red]"..translate("sms_strelok_strelok_taynik_pda1_3_0"), nil, "strelok", 30000, nil, [[sms\strelok\strelok_taynik_pda1_3]])
			spawn_restrictor.strelok_taynik_pda1_3_2_sr1()
			end
		amk.remove_item(obj)
	end,
	["strelok_taynik_pda1_4"]=function(obj)
		if not has_info("strelok_taynik_pda1_done") then
			sms("%c[sender]"..translate("name_strelok")..":\\n%c[sms_red]"..translate("sms_strelok_strelok_taynik_pda1_4_0"), nil, "strelok", 30000, nil, [[sms\strelok\strelok_taynik_pda1_4]])
			this.spawn_s_teleport1_4()
			spawn_restrictor.strelok_taynik_pda1_4_sr1()
		end
		amk.remove_item(obj)
	end,
	["strelok_taynik_pda1_5"]=function(obj)
		if not has_info("strelok_taynik_pda1_done") then
			sms("%c[sender]"..translate("name_strelok")..":\\n%c[sms_red]"..translate("sms_strelok_strelok_taynik_pda1_5_0"), nil, "strelok", 30000, nil, [[sms\strelok\strelok_taynik_pda1_5]])
			braad_test.kor_bar_pri()
			give_info("strelok_perehody_izbara")
			release_teleport("s_teleport1_1")
			release_teleport("s_teleport1_3_1")
			release_teleport("s_teleport1_3_2")
			release_teleport("s_teleport1_4")
		end
		amk.remove_item(obj)
	end,
	["strelok_taynik_pda30"]=function(obj)
		if not has_info("strelok_taynik_stop") then
			give_info("strelok_taynik_pda30_have")
		end
	end,
	["strelok_taynik_pda2_1"]=function(obj)
		check_pair_pda_2("strelok_taynik_pda2_2")
	end,
	["strelok_taynik_pda2_2"]=function(obj)
		check_pair_pda_2("strelok_taynik_pda2_1")
	end,
	["strelok_taynik_pda3_1"]=function(obj)
		check_pair_pda_1("strelok_taynik_pda3_2")
	end,
	["strelok_taynik_pda3_2"]=function(obj)
		check_pair_pda_1("strelok_taynik_pda3_1")
	end,
	["strelok_taynik_pda3"]=function(obj)
		if not has_info("strelok_taynik_stop") then
			if not has_info("strelok_taynik_pda3_have") then
				local obj = create("s_inventory_box3_1",xyz(-99.41,1.37,-171.46),12046,3241)
				map_spot(obj.id, "treasure", "Unknown Stash")
				local obj = create("s_inventory_box3_2",xyz(-155.51449584961,-4.6265954971313,-262.34503173828),5644,3238)
				map_spot(obj.id, "treasure", "Strelok's Stash")
				sms("Received a tip on the cache", nil, nil, 10000)
				this.spawn_s_teleport3_2()
				give_info("strelok_taynik_pda3_have")
			end
		end
	end,
	["strelok_taynik_pda3_3"]=function(obj)
		if not has_info("strelok_taynik_stop") and not has_info("strelok_taynik_pda3_3_have") then
			this.strelok_taynik_pda3_drop()
			give_info("strelok_taynik_pda3_3_have")
		end
	end,
	["strelok_taynik_pda4"]=function(obj)
		if has_info("strelok_taynik_pda4_found") then
			if not has_info("strelok_taynik_stop") and not has_info("strelok_taynik_pda4_have") then
				this.delete_s_teleport4_1()
				give_info("strelok_taynik_pda4_have")
			end
		else
			give_info("strelok_taynik_stop")
		end
	end,
	["strelok_taynik_pda5"]=function(obj)
		if not has_info("strelok_taynik_stop") then
			give_info("strelok_taynik_pda5_have")
		end
	end,
	["strelok_taynik_pda6"]=function(obj)
		if not has_info("strelok_taynik_stop") then
			give_info("strelok_taynik_pda6_have")
			if not has_info("strelok_taynik_pda6_xvatit_spawn") then
				create("bloodsucker_strong",xyz(-194.36819458008,49.02271270752,-535.56390380859),112200,3082)
				create("bloodsucker_normal",xyz(-189.69694519043,47.406341552734,-548.29016113281),117716,3082)
				create("bloodsucker_normal",xyz(-174.30001831055,49.662406921387,-521.21356201172),135088,3089)
				create("bloodsucker_normal",xyz(-170.43768310547,46.646286010742,-550.90631103516),139967,3088)
				xr_effects.play_zvuk3()
				give_info("strelok_taynik_pda6_xvatit_spawn")
			end
		end
	end,
	["strelok_taynik_pda7"]=function(obj)
		if has_info("strelok_taynik_pda7_found") then
			if not has_info("strelok_taynik_stop") then
				sms("%c[sender]"..translate("name_strelok")..":\\n%c[sms_red]"..translate("sms_strelok_strelok_taynik_pda7_0")..user_name()..translate("sms_strelok_strelok_taynik_pda7_1")..user_name()..translate("sms_strelok_strelok_taynik_pda7_2")..user_name()..translate("sms_strelok_strelok_taynik_pda7_3"), nil, "strelok", 50000, nil, [[sms\strelok\strelok_taynik_pda7]])
				give_info("strelok_taynik_pda7_done")
			end
		else
			give_info("strelok_taynik_stop")
		end
		if has_info("strelok_taynik_pda0_done") then
			this.delete_s_teleport0_1()
		end
		amk.remove_item(obj)		
	end,
	["strelok_taynik_pda0"]=function(obj)
		if not has_info("strelok_taynik_stop") then
			sms("%c[sender]"..translate("name_strelok")..":\\n%c[sms_red]"..translate("sms_strelok_strelok_taynik_pda0_0")..user_name()..translate("sms_strelok_strelok_taynik_pda0_1"), nil, "strelok", 30000, nil, [[sms\strelok\strelok_taynik_pda0]])
			this.spawn_s_teleport0_1()
			give_info("strelok_taynik_pda0_done")
			create("amk_kanistra",xyz(30.90,7.33,-39.75),210337,1045)
			spawn_restrictor.stdt1_sr1()
		end
		amk.remove_item(obj)
	end,
	["stdt_pda1"]=function(obj)
		sms("%c[sender]"..translate("name_strelok")..":\\n%c[sms_red]"..translate("sms_strelok_stdt_pda1_0")..user_name()..translate("sms_strelok_stdt_pda1_1"), nil, "strelok", 30000, nil, [[sms\strelok\stdt_pda1]])
		local se_obj = db.actor:object("stdt_pda1")
		amk.remove_item(se_obj)
	end,
	["kostya_taynik_pda4"]=function(obj)
		if not has_info("kostya_taynik_pda4_xvatit_spawn") then
			sms("%c[sender]"..translate("name_starii_zhil")..":\\n%c[sms_red]"..translate("checking_taken_item59_3_0"), nil, "starogil", 10000, nil, [[sms\starii_zhil\checking_taken_item59_3]])
			this.spawn_t_teleport4_1()
			create("m_controller_normal",xyz(293.54354858398,-6.1697669029236,-306.34655761719),1388412,2903)
			create("m_controller_normal",xyz(293.54354858398,-6.1697669029236,-306.34655761719),1388412,2903)
			create("m_controller_old_fat",xyz(343.52505493164,-1.7487429380417,-291.03280639648),1481127,2903)
			create("m_controller_normal_fat",xyz(343.52505493164,-1.7487429380417,-291.03280639648),1481127,2903)
			give_info("kostya_taynik_pda4_xvatit_spawn")
		end
	end,
	["kostya_taynik_pda8"]=function(obj)
		if not has_info("kostya_taynik_pda8_xvatit_spawn") then
			create("m_controller_normal",xyz(-245.26629638672,-0.0019612908363342,108.61695098877),11654,1358)
			create("m_controller_old_fat",xyz(-268.68731689453,-0.0014384984970093,67.68074798584),4443,1410)
			create("m_controller_old",xyz(-208.81796264648,-0.00040912628173828,164.56384277344),25007,1332)
			give_info("kostya_taynik_pda8_xvatit_spawn")
		end
	end,
	["ktdt_pda1"]=function(obj)
		if has_info("ktdt1_found") then
			give_info("ktdt2")
			sms("checking_taken_item59_4", nil, nil, 20000)
			local obj = create("x_inventory_box2",xyz(-0.79496783018112,1.145513176918,10.266807556152),309442,1582)
			map_spot(obj.id, "treasure", "Cache of the Old Timer")
			sms("Received a tip on the cache", nil, nil, 10000)
			this.spawn_x_teleport2()
			release_teleport("x_teleport1")
			local se_obj = db.actor:object("ktdt_pda1")
			amk.remove_item(se_obj)
		end
	end,
	["ktdt_pda2"]=function(obj)
		if has_info("ktdt2_found") then
			got_money(1000000)
			give_info("ktdt3")
			sms("checking_taken_item59_5", nil, nil, 20000)
			this.spawn_x_teleport3()
			local se_obj = db.actor:object("ktdt_pda2")
			amk.remove_item(se_obj)
		end
	end,
	["ktdt_pda3"]=function(obj)
		if has_info("ktdt3_found") then
			sms("%c[sender]"..translate("name_starii_zhil")..":\\n%c[sms_red]"..translate("checking_taken_item59_6_0")..user_name()..translate("checking_taken_item59_6_1"), nil, "starogil", 5000, nil, [[sms\starii_zhil\checking_taken_item59_6]])
			local se_obj = db.actor:object("ktdt_pda3")
			amk.remove_item(se_obj)
		end
	end,
	["kostya_taynik_pda1_%d"]=function(obj)
		local obj_sect=obj:section()
		local pda_id=string.match(obj_sect,"kostya_taynik_pda1_(%d)")
		if not pda_id then
			abort("kostya_dialog: Invalid extractng pda_id from object section!")
		end
		give_info("kostya_taynik_pda_have_1_"..pda_id)
		if not has_info("kostya_taynik_pda1_tele") then
			sms("checking_taken_item59_0", nil, nil, 30000)
			this.spawn_t_teleport1_1()
			give_info("kostya_taynik_pda1_tele")
		end
		if obj_sect=="kostya_taynik_pda1_2" then
			if not has_info("kostya_taynik_pda1_2_xvatit_spawn") then
				sms("checking_taken_item59_1", nil, nil, 30000)
				give_info("kostya_taynik_pda1_2_xvatit_spawn")
			end
		end
		if has_info("kostya_taynik_pda_have_1_1") and has_info("kostya_taynik_pda_have_1_2") and has_info("kostya_taynik_pda_have_1_3") and has_info("kostya_taynik_pda_have_1_4") and has_info("kostya_taynik_pda_have_1_5") then
			if not has_info("kostya_taynik_pda1_have") then
				this.delete_t_teleport1_1()
				this.spawn_t_teleport1_2()
				sms("checking_taken_item59_2", nil, nil, 30000)
				give_info("kostya_taynik_pda1_have")
			end
		end
	end
}

setmetatable(pda_sections,_G.patternSearchTable)

function checking_taken_pdas(obj)
	local check_func=pda_sections[obj:section()]
	if check_func then
		check_func(obj)
	end
end

function s_inventory_box1()
  local obj = create("s_inventory_box1",xyz(126.61811828613,15.248512268066,90.880737304688),225170,2143)
  map_spot(obj.id, "treasure", "Strelok's Stash")
  sms("Received a tip on the cache", nil, nil, 10000)
--  create_teleport("s_teleport1_1",xyz(122.58910369873,4.5209398269653,87.757598876953),229491,2143)
  spawn_restrictor.strelok_taynik_pda1_sr1()
end

function s_inventory_box2()
  taynik_spawn.s_new_inventory2_1()
  local obj = create("s_inventory_box2_2",xyz(-77.04369354248,-7.4020524024963,-20.482629776001),90914,892)
  map_spot(obj.id, "treasure", "Strelok's Stash")
  sms("Received a tip on the cache", nil, nil, 10000)
end

function s_inventory_box30()
  local obj = create("s_inventory_box30",xyz(73.863845825195,-0.0094784200191498,121.16677093506),29686,1221)
  map_spot(obj.id, "treasure", "Strelok's Stash")
  sms("Received a tip on the cache", nil, nil, 10000)
end

function s_inventory_box3()
  local obj = create("s_inventory_box3",xyz(16.393283843994,37.914726257324,2.0604181289673),6342,2453)
  map_spot(obj.id, "treasure", "Strelok's Stash")
  sms("Received a tip on the cache", nil, nil, 10000)
end

function s_inventory_box4()
  local obj = create("s_inventory_box4",xyz(596.83740234375,-49.984550476074,-24.092365264893),214270,1899)
  map_spot(obj.id, "treasure", "Strelok's Stash")
  sms("Received a tip on the cache", nil, nil, 10000)
  this.spawn_s_teleport4_1()
  spawn_restrictor.strelok_taynik_pda4_sr1()
  obj = create("af_dummy_spring_red",xyz(664.32122802734,-44.515979766846,-37.01086807251),227163,1896)
  obj = create("af_dummy_battery_red",xyz(664.32122802734,-44.515979766846,-37.01086807251),227163,1896)
  obj = create("af_dummy_pellicle_red",xyz(664.32122802734,-44.515979766846,-37.01086807251),227163,1896)
end

function s_inventory_box5()
  local obj = create("s_inventory_box5",xyz(984.81433105469,11.019639015198,245.36875915527),261708,2646)
  map_spot(obj.id, "treasure", "Strelok's Stash")
  sms("Received a tip on the cache", nil, nil, 10000)
end

function s_inventory_box6()
  spawn_restrictor.strelok_taynik_pda6_sr1()
  spawn_restrictor.strelok_taynik_pda6_sr2()
  spawn_restrictor.strelok_taynik_pda6_sr3()
end

function s_inventory_box7()
  local obj = create("s_inventory_box7",xyz(-17.708236694336,17.989824295044,-4.267804145813),5646,2026)
  map_spot(obj.id, "treasure", "Strelok's Stash")
  sms("Received a tip on the cache", nil, nil, 10000)
  spawn_restrictor.strelok_taynik_pda7_sr1()
  spawn_restrictor.strelok_taynik_pda7_sr2()
end

function strelok_taynik_pda1_have(task, objective)
  if db.actor ~= nil then
    if has_info("strelok_taynik_pda1_found") then
      return has("strelok_taynik_pda1")
	end
  end
  return false
end
function strelok_taynik_pda1_done(first_speaker, second_speaker)
  lost("strelok_taynik_pda1")
  this.delete_s_teleport1_2()
end

function strelok_taynik_pda2_have(task, objective)
  if db.actor ~= nil then
    return has("strelok_taynik_pda2_1") and has("strelok_taynik_pda2_2")
  end
  return false
end
function strelok_taynik_pda2_done(first_speaker, second_speaker)
  lost("strelok_taynik_pda2_1")
  lost("strelok_taynik_pda2_2")
end

function strelok_taynik_pda30_have(task, objective)
  if db.actor ~= nil then
    return has("strelok_taynik_pda30")
  end
  return false
end
function strelok_taynik_pda30_done(first_speaker, second_speaker)
  lost("strelok_taynik_pda30")
end

function strelok_taynik_pda3_have(task, objective)
  if db.actor ~= nil then
    return has("strelok_taynik_pda3")
  end
  return false
end
function strelok_taynik_pda3_done(first_speaker, second_speaker)
  lost("strelok_taynik_pda3")
end
function strelok_taynik_pda3_drop()
    this.delete_s_teleport3_2()
	local se_obj = db.actor:object("strelok_taynik_pda3_1")
	amk.drop_item(db.actor,se_obj)
	amk.remove_item(se_obj)
	se_obj = db.actor:object("strelok_taynik_pda3_2")
	amk.drop_item(db.actor,se_obj)
	amk.remove_item(se_obj)
	se_obj = db.actor:object("strelok_taynik_pda3_3")
	amk.drop_item(db.actor,se_obj)
	amk.remove_item(se_obj)
end

function strelok_taynik_pda4_have(task, objective)
  if db.actor ~= nil then
    if has_info("strelok_taynik_pda4_found") then
      return has("strelok_taynik_pda4")
	end
  end
  return false
end
function strelok_taynik_pda4_done(first_speaker, second_speaker)
  lost("strelok_taynik_pda4")
end

function strelok_taynik_pda5_have(task, objective)
  if db.actor ~= nil then
    return has("strelok_taynik_pda5")
  end
  return false
end
function strelok_taynik_pda5_done(first_speaker, second_speaker)
  lost("strelok_taynik_pda5")
end

function strelok_taynik_pda6_have(task, objective)
  if db.actor ~= nil then
    if has_info("strelok_taynik_pda6_found") then
      return has("strelok_taynik_pda6")
	end
  end
  return false
end
function strelok_taynik_pda6_done(first_speaker, second_speaker)
  lost("strelok_taynik_pda6")
end

function strelok_taynik_pda7_have(task, objective)
  if db.actor ~= nil then
    if has_info("strelok_taynik_pda7_found") then
      return has("strelok_taynik_pda7")
	end
  end
  return false
end

function spawn_s_teleport1_2()
    local se_obj = create("s_teleport1_2",xyz(207.23626708984,17.963800430298,48.94217300415),260660,2145)
	set_value("s_teleport1_2", se_obj.id)
end
function delete_s_teleport1_2(story_id)
	local obj_id = get_value("s_teleport1_2", -1, true)
	local se_obj = server_object(obj_id)
if se_obj then
  release(se_obj, true)
end
end
function spawn_s_teleport1_3_1()
    local se_obj = create("s_teleport1_3_1",xyz(98.162727355957,28.547431945801,38.083969116211),225595,2143)
	set_value("s_teleport1_3_1", se_obj.id)
end
function spawn_s_teleport1_3_2()
    local se_obj = create("s_teleport1_3_2",xyz(-17.820304870605,13.85008430481,11.088830947876),81517,2160)
	set_value("s_teleport1_3_2", se_obj.id)
end
function spawn_s_teleport1_4()
    local se_obj = create("s_teleport1_4",xyz(-90.959411621094,13.623492240906,28.934303283691),7528,2253)
	set_value("s_teleport1_4", se_obj.id)
end
function spawn_s_teleport1_5()
    local se_obj = create("s_teleport1_5",xyz(43.850486755371,11.828426361084,37.138198852539),155631,2225)
	set_value("s_teleport1_5", se_obj.id)
end

function spawn_s_teleport3_2()
    local se_obj = create("s_teleport3_2",xyz(-150.38586425781,-5.7839937210083,-278.90524291992),6896,3238)
	set_value("s_teleport3_2", se_obj.id)
end
function delete_s_teleport3_2(story_id)
	local obj_id = get_value("s_teleport3_2", -1, true)
	local se_obj = server_object(obj_id)
if se_obj then
  release(se_obj, true)
end
end

function spawn_s_teleport4_1()
    local se_obj = create("s_teleport4_1",xyz(308.16702270508,-37.625602722168,-21.087753295898),69058,1930)
	set_value("s_teleport4_1", se_obj.id)
end
function delete_s_teleport4_1(story_id)
	local obj_id = get_value("s_teleport4_1", -1, true)
	local se_obj = server_object(obj_id)
if se_obj then
  release(se_obj, true)
end
end

function spawn_s_teleport0_1()
    local se_obj = create("s_teleport0_1",xyz(-1.5840334892273,5.1518805027008,-44.498065948486),10089,1961)
	set_value("s_teleport0_1", se_obj.id)
end
function delete_s_teleport0_1(story_id)
	local obj_id = get_value("s_teleport0_1", -1, true)
	local se_obj = server_object(obj_id)
if se_obj then
  release(se_obj, true)
end
end

function t_inventory_box1()
  spawn_restrictor.kostya_taynik_pda1_sr1()
end
function kostya_taynik_pda1_have(task, objective)
    return has_info("kostya_taynik_pda1_have")
end
function kostya_taynik_pda1_done()
  lost("kostya_taynik_pda1_1")
  lost("kostya_taynik_pda1_2")
  lost("kostya_taynik_pda1_3")
  lost("kostya_taynik_pda1_4")
  lost("kostya_taynik_pda1_5")
end

function t_inventory_box2()
  taynik_spawn.t_new_inventory2()
end
function kostya_taynik_pda2_have(task, objective)
	if has("kostya_taynik_pda2") then
		give_info("kostya_taynik_pda2_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda2_done(first_speaker, second_speaker)
  lost("kostya_taynik_pda2")
end

function t_inventory_box3()
  taynik_spawn.t_new_inventory3_1()
  taynik_spawn.t_new_inventory3_2()
  local obj = create("t_inventory_box3_3",xyz(4.5460352897644,31.063150405884,67.978546142578),27143,2659)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  obj = create("t_inventory_box3_4",xyz(242.60501098633,73.895149230957,138.61387634277),76288,2573)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  sms("Received a tip on the cache", nil, nil, 10000)
end
function kostya_taynik_pda3_have(task, objective)
	if has("kostya_taynik_pda3_1") and has("kostya_taynik_pda3_2") and has("kostya_taynik_pda3_3") and has("kostya_taynik_pda3_4") then
		give_info("kostya_taynik_pda3_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda3_done(first_speaker, second_speaker)
  lost("kostya_taynik_pda3_1")
  lost("kostya_taynik_pda3_2")
  lost("kostya_taynik_pda3_3")
  lost("kostya_taynik_pda3_4")
end

function t_inventory_box4()
  local obj = create("t_inventory_box4",xyz(316.57379150391,-12.273648262024,-261.89810180664),1431070,2903)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  sms("Received a tip on the cache", nil, nil, 10000)
end
function kostya_taynik_pda4_have(task, objective)
	if has("kostya_taynik_pda4") then
		give_info("kostya_taynik_pda4_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda4_done(first_speaker, second_speaker)
  lost("kostya_taynik_pda4")
end

function t_inventory_box5()
  taynik_spawn.t_new_inventory5()
end
function kostya_taynik_pda5_have(task, objective)
	if has("kostya_taynik_pda5") then
		give_info("kostya_taynik_pda5_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda5_done(first_speaker, second_speaker)
  lost("kostya_taynik_pda5")
end

function t_inventory_box6()
  taynik_spawn.t_new_inventory6_1()
  taynik_spawn.t_new_inventory6_2()
end
function kostya_taynik_pda6_have(task, objective)
	if has("kostya_taynik_pda6_1") and has("kostya_taynik_pda6_2") then
		give_info("kostya_taynik_pda6_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda6_done(first_speaker, second_speaker)
  lost("kostya_taynik_pda6_1")
  lost("kostya_taynik_pda6_2")
end

function t_inventory_box7()
  local obj = create("t_inventory_box7",xyz(94.308715820313,14.254689216614,50.491359710693),40199,3324)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  sms("Received a tip on the cache", nil, nil, 10000)
end
function kostya_taynik_pda7_have(task, objective)
	if has("kostya_taynik_pda7") then
		give_info("kostya_taynik_pda7_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda7_done(first_speaker, second_speaker)
  lost("kostya_taynik_pda7")
end

function t_inventory_box8()
  taynik_spawn.t_new_inventory8()
end
function kostya_taynik_pda8_have(task, objective)
	if has("kostya_taynik_pda8") then
		give_info("kostya_taynik_pda8_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda8_done(first_speaker, second_speaker)
  lost("kostya_taynik_pda8")
end

function t_inventory_box9()
  taynik_spawn.t_new_inventory9_1()
  local obj = create("t_inventory_box9_2",xyz(-108.54,0.61,-244.63),11031,3241)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  sms("Received a tip on the cache", nil, nil, 10000)
  taynik_spawn.t_new_inventory9_3()
end
function kostya_taynik_pda9_have(task, objective)
	if has("kostya_taynik_pda9_1") and has("kostya_taynik_pda9_2") and has("kostya_taynik_pda9_3") then
		give_info("kostya_taynik_pda9_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda9_done(first_speaker, second_speaker)
  lost("kostya_taynik_pda9_1")
  lost("kostya_taynik_pda9_2")
  lost("kostya_taynik_pda9_3")
end

function t_inventory_box10()
  local obj = create("t_inventory_box10_1",xyz(-116.87435913086,4.8685846328735,-149.80033874512),89560,562)
  obj = create("t_inventory_box10_2",xyz(-26.37,-0.58,-25.53),280608,1593)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  obj = create("t_inventory_box10_3",xyz(27.953716278076,20.462240219116,684.33978271484),307284,208)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  obj = create("t_inventory_box10_4",xyz(106.7265625,13.199247360229,153.22033691406),272568,374)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  sms("Received a tip on the cache", nil, nil, 10000)
  spawn_restrictor.kostya_taynik_pda10_sr1()
end
function kostya_taynik_pda10_have(task, objective)
	if has("kostya_taynik_pda10_1") and has("kostya_taynik_pda10_2") and has("kostya_taynik_pda10_3") and has("kostya_taynik_pda10_4") then
		give_info("kostya_taynik_pda10_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda10_done(first_speaker, second_speaker)
  lost("kostya_taynik_pda10_1")
  lost("kostya_taynik_pda10_2")
  lost("kostya_taynik_pda10_3")
  lost("kostya_taynik_pda10_4")
end

function t_inventory_box11()
  local obj = create("t_inventory_box11_1",xyz(192.18560791016,12.331077575684,101.35523986816),260351,2221)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  sms("Received a tip on the cache", nil, nil, 10000)
  taynik_spawn.t_new_inventory11_2()
  obj = create("t_inventory_box11_3",xyz(6.5773458480835,8.061222076416,138.07514953613),109702,2147)
  map_spot(obj.id, "treasure", "Cache of the Old Timer")
  sms("Received a tip on the cache", nil, nil, 10000)
end
function kostya_taynik_pda11_have(task, objective)
	if has("kostya_taynik_pda11_1") and has("kostya_taynik_pda11_2") and has("kostya_taynik_pda11_3") then
		give_info("kostya_taynik_pda11_have")
		return true
	else
		return false
	end
end
function kostya_taynik_pda11_done(first_speaker, second_speaker)
  give_info("ktdt1")
  sms("kostya_taynik_pda11_done_0", nil, nil, 20000)
  this.spawn_x_teleport1()
  lost("kostya_taynik_pda11_1")
  lost("kostya_taynik_pda11_2")
  lost("kostya_taynik_pda11_3")
end

function spawn_t_teleport1_1()
    local se_obj = create("t_teleport1_1",xyz(190.83657836914,2.7860803604126,217.42588806152),260274,2219)
	set_value("t_teleport1_1", se_obj.id)
end
function delete_t_teleport1_1(story_id)
	local obj_id = get_value("t_teleport1_1", -1, true)
	local se_obj = server_object(obj_id)
if se_obj then
  release(se_obj, true)
end
end
function spawn_t_teleport1_2()
    local se_obj = create("t_teleport1_2",xyz(23.953285217285,10.699913024902,162.15838623047),131398,2199)
	set_value("t_teleport1_2", se_obj.id)
end

function spawn_t_teleport4_1()
    local se_obj = create("t_teleport4_1",xyz(-50.95,-29.72,-139.41),796684,2897)
	set_value("t_teleport4_1", se_obj.id)
end

function spawn_x_teleport1()
    local se_obj = create("x_teleport1",xyz(9.4039793014526,11.447186470032,90.041458129883),114619,2142)
	set_value("x_teleport1", se_obj.id)
	spawn_restrictor.ktdt1_sr1()
end
function spawn_x_teleport2()
    local se_obj = create("x_teleport2",xyz(-15.461825370789,-3.8673331737518,-5.0735273361206),283384,1593)
	set_value("x_teleport2", se_obj.id)
	spawn_restrictor.ktdt2_sr1()
end
function spawn_x_teleport3()
    local se_obj = create("x_teleport3",xyz(47.420116424561,-2.4642562866211,-209.0924987793),63669,1469)
	set_value("x_teleport3", se_obj.id)
    se_obj = create("x_teleport3_1",xyz(-47.345569610596,0.74647736549377,-160.83731079102),16808,1490)
	set_value("x_teleport3_1", se_obj.id)
    se_obj = create("x_teleport3_2",xyz(-25.791805267334,0.7459944486618,-150.2300567627),16808,1490)
	set_value("x_teleport3_2", se_obj.id)
    se_obj = create("x_teleport3_3",xyz(-67.088394165039,1.2463047504425,-154.01571655273),15216,1490)
	set_value("x_teleport3_3", se_obj.id)
    local obj = create("x_inventory_box3",xyz(-27.107929229736,0.74637401103973,-160.10646057129),16808,1490)
	map_spot(obj.id, "treasure", "Cache of the Old Timer")
    sms("Received a tip on the cache", nil, nil, 10000)
	spawn_restrictor.ktdt3_sr1()
end

function taynik_kostya2_call()
	if has_info("kostya_sacharov_pda_start") and has_info("sahar_sumka_done") and has_info("kostya_biznes1_done") then
		sms("%c[sender]"..translate("name_kostya")..":\\n%c[sms_red]"..translate("sms_kostya_taynik_kostya2_call_1_0"), 12, "kostya", 20000, nil, [[sms\kostya\taynik_kostya2_call_1]])
	end
end

function esc_pda_have(task, objective)
if db.actor ~= nil then
return has("kostya_pda")
end
return false
end

function esc_pda_done(first_speaker, second_speaker)
lost("kostya_pda")
second_speaker:set_relation(game_object.friend, first_speaker)
end

function esc_art_have(task, objective)
if db.actor ~= nil then
return has("kostya_af_gold_fish")
end
return false
end

function esc_art_done(first_speaker, second_speaker)
lost("kostya_af_gold_fish")
second_speaker:set_relation(game_object.friend, first_speaker)
end


function esc_pda2_have(task, objective)
if db.actor ~= nil then
return has("kostya_pda2")
end
return false
end

function esc_pda2_done(first_speaker, second_speaker)
lost("kostya_pda2")
end


function esc_pda3_have(task, objective)
if db.actor ~= nil then
return has("kostya_pda3")
end
return false
end

function esc_pda3_done(first_speaker, second_speaker)
lost("kostya_pda3")
end


function esc_pda4_have(task, objective)
if db.actor ~= nil then
return has("kostya_pda4")
end
return false
end

function esc_pda4_done(first_speaker, second_speaker)
lost("kostya_pda4")
end


function esc_pda5_have(task, objective)
if db.actor ~= nil then
return has("kostya_pda5")
end
return false
end

function esc_pda5_done(first_speaker, second_speaker)
lost("kostya_pda5")
end


function esc_pda6_have(task, objective)
if db.actor ~= nil then
return has("kostya_pda6")
end
return false
end

function esc_pda6_done(first_speaker, second_speaker)
lost("kostya_pda6")
end


function esc_pda7_have(task, objective)
if db.actor ~= nil then
return has("kostya_pda7")
end
return false
end

function esc_pda7_done(first_speaker, second_speaker)
lost("kostya_pda7")
end


function esc_pda8_have(task, objective)
if db.actor ~= nil then
return has("kostya_pda8")
end
return false
end

function esc_pda8_done(first_speaker, second_speaker)
lost("kostya_pda8")
end


function esc_pda9_have(task, objective)
if db.actor ~= nil then
return has("kostya_pda9")
end
return false
end

function esc_pda9_done(first_speaker, second_speaker)
	lost("kostya_pda9")
	xr_effects.clean_teleport40()
end


function sacharov_pda_have(task, objective)
if db.actor ~= nil then
return has("pda_vasilyev")
end
return false
end

function sacharov_pda_done(first_speaker, second_speaker)
	lost("pda_vasilyev",1)
	sms("sacharov_pda_done_0", nil, nil, 30000)
end

function kostya_art2_have(task, objective)
if db.actor ~= nil then
return has("af_dummy_battery")
end
return false
end

function kostya_art2_done()
	lost("af_dummy_battery")
end

function document_done()
	lost("kostya_documents",1)
end

function kostya_teleport()
	got("science_teleport")
end
function kostya_teleport2()
	got("science_teleport2")
end
function kostya_teleport3()
	got("science_teleport3")
end
function kostya_teleport4()
	got("device_teleport")
end

function info_recieved()
	sms("info_recieved_0", nil, nil, 10000)
end

-- Вероятности появления фраз в диалогах
function probability_05()
	return math.random() <= 0.05
end

function actor_has_money_100000()
  return has_money(100000)
end
function give_money_100000(t1,t2)
  lost_money(100000)
end

function actor_has_money_40000()
  return has_money(40000)
end
function give_money_40000(t1,t2)
  lost_money(40000)
end

function actor_has_money_20000()
  return has_money(20000)
end
function give_money_20000(t1,t2)
  lost_money(20000)
end

function actor_out_money_190000()
	lost_money(190000)
end
function actor_in_money_190000()
	got_money(190000)
end

function actor_has_money_200000()
  return has_money(200000)
end
function actor_dont_has_money_200000()
  return not has_money(200000)
end
function give_money_200000(t1,t2)
  lost_money(200000)
end

function actor_has_money_20000()
  return has_money(20000)
end
function actor_dont_has_money_20000()
  return not has_money(20000)
end
function give_money_20000(t1,t2)
  lost_money(20000)
end

function actor_has_money_25000()
  return has_money(25000)
end
function actor_dont_has_money_25000()
  return not has_money(25000)
end
function give_money_25000(t1,t2)
  lost_money(25000)
end
