function pda_prizrak()
	amk.spawn_item("pda_priz",xyz(-42.65,19.18,1.97),1530,2557) 
end

function esc_zahar()
	local obj = create("stalker_green_zahar",xyz(111.88757324,0.099669277667,74.2647323608),33195,1225)
	ai:assign_story_id(obj.id,9613)
end

function change_community_gavr()
local gavr_kodla = {9623, 9624, 9625, 9905}
for i = 1,#gavr_kodla do
  local npc = level_story_object(gavr_kodla[i])
  if npc and npc:alive () then
        npc:set_character_community("killer", 0, 0)
  end
 end
end

-- Спавним телохранителей Джеймса
function james_bodyguard_spawn()
local obj= create ("rostok_james_bodyguard",xyz(-263.20,-0.0,22.01),5808,1395)
ai:assign_story_id(obj.id, 22067)
local obj= create ("rostok_james_bodyguard1",xyz(-254.79,-0.00,23.31),8067,1395)
ai:assign_story_id(obj.id, 22068)
local obj= create ("rostok_james_bodyguard2",xyz(-254.29,-0.00,3.14),8258,1396)
ai:assign_story_id(obj.id, 22069)
local obj= create ("rostok_james_bodyguard3",xyz(-262.05,-0.00,8.00),6139,1395)
ai:assign_story_id(obj.id, 22070)
spawn_restrictor.ros_james_sr()
end

function bar_james()
create("ros_killer_respawn_4",xyz(-226.96,-0.00,15.28),19435,1398)
create("ros_killer_respawn_4",xyz(-236.57,-0.00,29.57),15458,1394)
create("ros_killer_respawn_4",xyz(-248.740127,-0.00184855,6.270340919),10240,1396)
create("sniper_james_7",xyz(-232.27,-0.00,34.51),17189,1394)
create("sniper_james_8",xyz(-213.66,0.14,-47.20),23676,1401)
		timer("run", 15.0, "new_spawn.bar_james1()")
end

function bar_james1()
create("sniper_james_5",xyz(-283.17,-0.00,84.83),1025,1411)
create("sniper_james_6",xyz(-257.52,-0.00,102.54),7357,1378)
create("sniper_james_7",xyz(-232.27,-0.00,106.85),17284,1358)
create("sniper_james_1",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_2",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_3",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_4",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_8",xyz(-189.60,-5.97,-66.76),28830,1403)
create("sniper_james_9",xyz(-105.39,-3.47,-106.55),44545,1437)
create("sniper_james_10",xyz(-82.07,-11.35,-116.49),48266,1425)
create("sniper_james_11",xyz(-96.01,-12.66,-138.64),45566,1437)
create("sniper_james_5",xyz(-251.47,-0.00,41.15),9250,1393)
say([[characters_voice\scenario\buusty\merc_leader_regret]])
        disable_info("no_teleport_near_heli_btr")
		timer("run", 45.0, "new_spawn.bar_james2()")
end

function bar_james2()
	if level.get_game_difficulty() > 0 then
create("sniper_james_5",xyz(-283.17,-0.00,84.83),1025,1411)
create("sniper_james_6",xyz(-257.52,-0.00,102.54),7357,1378)
create("sniper_james_7",xyz(-232.27,-0.00,106.85),17284,1358)
create("sniper_james_1",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_3",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_8",xyz(-189.60,-5.97,-66.76),28830,1403)
		timer("run", 160.0, "new_spawn.bar_james3()")
 end
end

function bar_james3()
	if level.get_game_difficulty() > 1 then
create("sniper_james_5",xyz(-283.17,-0.00,84.83),1025,1411)
create("sniper_james_8",xyz(-257.52,-0.00,102.54),7357,1378)
create("sniper_james_7",xyz(-232.27,-0.00,106.85),17284,1358)
create("sniper_james_2",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_4",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_6",xyz(-189.60,-5.97,-66.76),28830,1403)
--create("sniper_james_8",xyz(-213.66,0.14,-47.20),23676,1401)
		timer("run", 180.0, "new_spawn.bar_james4()")
 end
end

function bar_james4()
	if level.get_game_difficulty() > 2 then
create("sniper_james_6",xyz(-283.17,-0.00,84.83),1025,1411)
create("sniper_james_8",xyz(-257.52,-0.00,102.54),7357,1378)
create("sniper_james_7",xyz(-232.27,-0.00,106.85),17284,1358)
create("sniper_james_8",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_2",xyz(-257.52,-0.00,102.54),7357,1378)
create("sniper_james_11",xyz(-283.17,-0.00,84.83),1025,1411)
create("sniper_james_4",xyz(-200.02,0.08,67.97),26723,1374)
create("sniper_james_5",xyz(-189.60,-5.97,-66.76),28830,1403)
 end
end

function under_stalker()
	create("new_book",xyz(157.2386932373,5.0431084632874,-131.07159423828),193472,8370)
	create("pri_arhara_naemnik3",xyz(159.09887695313,7.6420702934265,-123.48909759521),195612,8368)
	create("pri_arhara_naemnik2",xyz(156.95509338379,0.60334551334381,-129.15458679199),194002,8369)
	create("pri_arhara_naemnik1",xyz(163.54020690918,2.3620018959045,-133.23823547363),199234,8369)
	create("naemnik_regular",xyz(197.30619812012,-0.007770836353302,-157.56750488281),221744,8300)
	create("naemnik_veteran",xyz(135.6863861084,14.409547805786,-106.8542175293),179367,8372)
	create("naemnik_sniper",xyz(143.12512207031,20.729141235352,-107.61664581299),184131,8371)
	create("naemnik_regular",xyz(133.75904846191,0.31729319691658,-117.01374053955),177859,8375)
	create("naemnik_veteran",xyz(122.12413024902,-0.0066322088241577,-156.61595153809),169896,8279)
	create_car("auto_turret_2",xyz(147.21649169922,20.731653213501,-106.80419921875),187306,8371, "scripts\\technics\\turret.ltx")
end

function prizrak_true()
create("boev_sniper_rad1",xyz(608.736389160,-52.1336784363,-279.3496398926),218431,1883)
create("boev_sniper_rad2",xyz(593.38671875,-51.838394165039,-289.097137451),210993,1883)
create("boev_sniper_rad3",xyz(597.50213623,-53.779800415039,-255.705276489),213454,1863)
create("boev_sniper_rad4",xyz(611.5910034179,-52.4556274414,-304.1400756836),219774,1882)
create("boev_sniper_rad5",xyz(613.7868041992,-50.43564987183,-8.73648929596),220734,1899)
create("boev_sniper_rad6",xyz(606.57836914063,-53.641632081,-52.6836853027),217655,1897)
create("boev_sniper_rad7",xyz(511.014770507,-49.80339813232,16.531932830811),171492,1920)
create("boev_sniper_rad8",xyz(515.36065673828,-49.98353958129,0.59198832512),173514,1917)
create("boev_sniper_rad9",xyz(394.22698974609,-49.7197265625,15.6820411682),121105,1864)
create("boev_sniper_rad10",xyz(349.57217407227,-49.9717864990,15.1036739349),92719,1927)
create("boev_sniper_rad11",xyz(131.92094421387,-3.201653480529,30.6498222351),51503,1940)
create("boev_sniper_rad12",xyz(105.66445922852,-0.200214698910,-18.860168457),45473,1951)
create("boev_sniper_rad13",xyz(115.53982543945,-0.306800276,-33.98778152466),48501,1951)
create("boev_sniper_rad14",xyz(69.816612243,-0.4328181147575,-0.680386841297),33781,1984)
create("boev_sniper_rad15",xyz(90.30807495117,-0.39964208006,-18.0512924194),40764,1982)
end

function spawn_zver()
local obj=create("esc_zver",xyz(-123.13681793213,-30.051919937134,-368.98876953125),130148,25)
ai:assign_story_id(obj.id,9731)
create("esc_bodyzver1",xyz(-123.13681793213,-30.051919937134,-368.98876953125),130148,25)
create("esc_bodyzver2",xyz(-123.13681793213,-30.051919937134,-368.98876953125),130148,25)
create("esc_bodyzver3",xyz(-123.13681793213,-30.051919937134,-368.98876953125),130148,25)
create("esc_bodyzver4",xyz(-123.13681793213,-30.051919937134,-368.98876953125),130148,25)
create("esc_bodyzver5",xyz(-123.13681793213,-30.051919937134,-368.98876953125),130148,25)
create("esc_mil_def",xyz(-168.19195556641,-31.625070571899,-272.02471923828),83865,35)
create("esc_mil2_def",xyz(-168.19195556641,-31.625070571899,-272.02471923828),83865,35)
create("esc_mil3_def",xyz(-168.19195556641,-31.625070571899,-272.02471923828),83865,35)
create("esc_mil4_def",xyz(-168.19195556641,-31.625070571899,-272.02471923828),83865,35)
create("esc_mil5_def",xyz(-163.01707458496,-25.436334609985,-350.4128112793),86407,31)
create("esc_mil6_def",xyz(-163.01707458496,-25.436334609985,-350.4128112793),86407,31)
create("esc_mil7_def",xyz(-163.01707458496,-25.436334609985,-350.4128112793),86407,31)
create("esc_mil8_def",xyz(-163.01707458496,-25.436334609985,-350.4128112793),86407,31)
create("esc_mil9_def",xyz(-133.7991027832,-25.811548233032,-354.52139282227),117354,19)
create("esc_mil10_def",xyz(-133.7991027832,-25.811548233032,-354.52139282227),117354,19)
create("esc_mil11_def",xyz(-133.21928405762,-29.690362930298,-354.28179931641),118113,19)
create("esc_mil12_def",xyz(-133.7991027832,-25.811548233032,-354.52139282227),117354,19)
create("esc_mil13_def",xyz(-139.49812316895,-29.691171646118,-353.13653564453),111254,19)
create("esc_mil14_def",xyz(-139.49812316895,-29.691171646118,-353.13653564453),111254,19)
end

function add_zver()
create("esc_snip_atak",xyz(-130.93258666992,-17.900747299194,-187.99856567383),120643,42)
create("esc_snip2_atak",xyz(-130.93258666992,-17.900747299194,-187.9985656738),120643,42)
create("esc_snip3_atak",xyz(-130.93258666992,-17.900747299194,-187.9985656738),120643,42)
create("esc_snip4_atak",xyz(-130.4655456543,-10.02149772644,-126.00447845459),121547,44)
create("esc_snip5_atak",xyz(-130.4655456543,-10.02149772644,-126.00447845459),121547,44)
create("esc_snip6_atak",xyz(-130.4655456543,-10.02149772644,-126.00447845459),121547,44)
create("esc_snip7_atak",xyz(-238.85079956055,-19.541189193726,-118.84622192383),16851,8)
create("esc_snip8_atak",xyz(-238.85079956055,-19.541189193726,-118.84622192383),16851,8)
create("esc_snip9_atak",xyz(-238.85079956055,-19.541189193726,-118.84622192383),16851,8)
end

function chern_dell()
local obj = create("chernomor_zombi1",xyz(11.4238529205322,0.279962688684464,15.8728618621826),44664,1501)
ai:assign_story_id(obj.id,9626)
end

-- Hand Teleport
function esc_kostya_ammo()
	got("ammo_12x70_buck", 3)
end

function new_inventory12()
	local obj = create("m_inventory_box12",xyz(7.7449460029602,-22.623861312866,7.6079015731812),7689,2703)
	map_spot(obj.id, "treasure", "Cache")
	sms("Received a tip on the cache", nil, nil, 10000)
	give_info("new_inventory12")
end

function new_inventory13()
	local obj = create("m_inventory_box13",xyz(-295.2509765625,25.836132049561,-119.17073059082),42457,303)
	map_spot(obj.id, "treasure", "Cache")
	sms("Received a tip on the cache", nil, nil, 10000)
	give_info("kostya_documents_have")
end

function pda_vasilyev()
	create("pda_vasilyev",xyz(-42.24186706543,12.60915851593,7.8064550590515),2388,1532)
	yantar_tasks.x16_mutant_spawn()
end
function spawn_art()
	create("kostya_af_gold_fish",xyz(8.8234663009644,2.8059701919556,90.253837585449),285376,92)
end

-- Запускаем таракашку при открытии холодильника
function tarakan_freezer_spawn()
        create("tarakan_normal",xyz(289.23,-2.096,321.97),637501,4082)
end

--' Удаляем мины на Складах (при сдаче РГ-6 Воронину)
function mil_arhara_mine_delete()
	local se_obj = server_object("mil_arhara_mine1")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("mil_arhara_mine2")
	if se_obj then
		release(se_obj, true)
	end
end

function sms_voronin_mechenyi_fail()
if not has_info("naemn_shturm_poluch_fail") then
	sms("%c[sender]"..translate("name_general_voronin")..":\\n%c[sms_red]"..translate("sms_voronin_mechenyi_fail"), 4, "general_voronin", 8000, nil, [[sms\voronin\sms_voronin_mechenyi_fail]])
	timer("run", 14.0, "new_spawn.voronin_mechenyi_fail()")
 end
end

function voronin_mechenyi_fail()
	give_info("naemn_shturm_poluch_fail")
end

-- Спавним 3 бутылки Боцману в подвал на Болотах
function bocman_vodyaru_spawn()
	local obj = story_object(900089)
	if not obj then
		obj=create(ai:spawn_id(900089))
	end
	local obj = story_object(900090)
	if not obj then
		obj=create(ai:spawn_id(900090))
	end
	local obj = story_object(900091)
	if not obj then
		obj=create(ai:spawn_id(900091))
	end
end

-- Убираем мусор в подвале у Боцмана
function bocman_vodyaru_delete()
	release(story_object(900089))
	release(story_object(900090))
	release(story_object(900091))
 end

-- Спавним зону мух в подвале у Боцмана
function udav_roy_fly_spawn()
        create("zone_roy_fly",xyz(-43.00,-1.30,268.63),118303,3402)
end

-- Спавним телевизор на базе Борова после разговора с Кариной Лютой
function televizor_esc_spawn()
	local obj = story_object(900092)
	if not obj then
		obj=create(ai:spawn_id(900092))
	end
end

-- Спавним охранника телевизора
function telek_bandit_spawn()
        create("val_telek_bandit",xyz(-6.48,0.12,-53.38),166811,1043)
end

-- Спавним дублёра охранника телевизора (в случае его гибели)
function telek_bandit_spawn1()
        create("val_telek_bandit",xyz(13.26,1.21,-75.63),189842,1103)
end

-- проверим наличие экзика бандитов для охранника
function exo_bandit_have()
return has_good("exo_bandit_outfit",1) 
end

-- отдадим экзу охраннику
function exo_bandit_otdal()
	lost("exo_bandit_outfit",1)
end

-- Заспавним 2 телепорта на Стройплощадке, от залокационных клоунов
function stroyploshadka_tele_spawn()
	create("stroyploshadka_tele",xyz(-246.66,19.14,107.47),7172,9271)
	create("stroyploshadka_tele1",xyz(-249.43,20.25,97.16),3492,9271)
end

-- Удаляем любой тайник на определённой локации
function delete_inventory_box()
	local obj
	if not level.name()=="atp_for_test22" then
		return
	end
	for a=1,65534,1 do
		obj=server_object(a)
if obj 
   and db.actor:position():distance_to(obj.position) < 250 
   and string.find(obj:name(),"m_inventory_box") 
   and object_level_name(obj)=="atp_for_test22"
   then
			release(obj,true)
		end
	end
end

function atp_presled_last()
create("atp_presled_last_1",xyz(-92.47,-2.90,-345.57),243791,2807)
create("atp_presled_last_2",xyz(-90.45,-4.37,-298.09),246916,2807)
create("atp_presled_last_3",xyz(-86.79,-8.05,-262.44),252006,2803)
create("atp_presled_last_7",xyz(77.38,-5.58,-221.41),490499,2824)
		timer("run", 1.75, "new_spawn.atp_presled_last1()")
		timer("run", 1.0, "new_spawn.level_changer_na_kordon_delete()")
end

function atp_presled_last1()
create("atp_presled_last_4",xyz(-63.87,-9.39,-214.19),285700,2810)
create("atp_presled_last_1",xyz(66.19,-5.42,-198.27),474501,2817)
create("atp_presled_last_5",xyz(139.26,-5.73,-251.74),576927,2824)
create("atp_presled_last_6",xyz(-92.47,-2.90,-345.57),243791,2807)
end

--' Удаляем переход АТП-Кордон
function level_changer_na_kordon_delete()
release(story_object(97092))
end

-- Спавним переход АТП-Кордон
function level_changer_na_kordon_spawn()
	local obj = story_object(97092)
	if not obj then
		obj=create(ai:spawn_id(97092))
	end
	map_spot(obj.id, "level_changer3", "to_escape")
end

-- Подспавним 6 наёмников в смарт в Кр. Лесу
function killer_forest_most_spawn()
create("killer_forest_most_1",xyz(-112.53,-0.01,-263.58),10220,3241)
create("killer_forest_most_2",xyz(-112.53,-0.01,-263.58),10220,3241)
create("killer_forest_most_3",xyz(-112.53,-0.01,-263.58),10220,3241)
create("killer_forest_most_1",xyz(-112.53,-0.01,-263.58),10220,3241)
create("killer_forest_most_2",xyz(-112.53,-0.01,-263.58),10220,3241)
create("killer_forest_most_3",xyz(-112.53,-0.01,-263.58),10220,3241)
end

-- Рандомно спавним зомби вокруг ГГ в МГ при убийстве снайперов на крышах
function around_mutants_spawn()
	snd_obj = sound_object("characters_voice\\human_02\\lastday\\fight\\tolls\\tolls_"..tostring(math.random(1,5)))  
        snd_obj:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
local monsters={
"zombie_normal",
"zombie_ghost",
"bomzh2",
"zombie_hell",
"zombie_beee",
"zombie_blow",
"carlic_weak",
"zombie_trup",
"zombie_trup2",
"bomzh3",
"zombie_hell1",
"zombie_hell2",
"zombie_hell3",
"zombie_hell4",
"zombie_hell5",
"zombie_hell6",
"zombie_hell7",
"zombie_hell8",
"zombie_hell9",
"zombie_hell10",
"zombie_hell11",
"zombie_hell12",
"zombie_hell13",
"zombie_hell14",
"zombie_hell16",
"bomzh",
"carlic",
"fly_plague",
"zombie_babka_weak",
"zombie_babka_normal",
"zombie_babka_strong",
"ghoul_strong",
"scelet_strong",
"zombie_parazit",
"bomzh4",
"zombie_immortal",
"carlic_strong",
"vodjanoj",
"zombie_trup_fc"
} 
	local ap = db.actor:position()
	local lv = db.actor:level_vertex_id()
	local gv = db.actor:game_vertex_id()
        for c=1,math.random(2,4) do
	create(table.random(monsters), xyz(ap.x+math.random(-7,7), ap.y, ap.z+math.random(-7,7)), lv, gv)
end
end

-- Заспавним антителепорт на Кордоне, у тоннеля
function valerich_antiteleport_spawn()
	create("valerich_antiteleport",xyz(346.07,17.37,-15.80),587563,2)
	create("valerich_antiteleport1",xyz(345.00,16.78,-15.96),587244,2)
	create("valerich_antiteleport2",xyz(346.981,18.106,-15.256),587878,2)
		timer("run", 80.0, "new_spawn.no_teleport_delete()")
end

function no_teleport_delete()
        disable_info("no_teleport_near_heli_btr")
end

-- Удаляем антителепорт на Кордоне, у тоннеля
function delete_valerich_antiteleport()
for a=1,65534,1 do
local obj=server_object(a)
if obj and string.find(obj:name(),"valerich_antiteleport") then
release(obj,true)
end
end
end

--' Удаляем рестриктор в Саркофаге, через который белесоватый фон вешается
function sar_space_restrictor_delete()
local se_obj = server_object("sar_space_restrictor")
  if se_obj then
    release(se_obj, true)
  end
end

-- проверка Фотика в инвентаре для апгрейда Долговязого
function fot_upgrade_have()
return has("wpn_fot") 
end

-- получим Фотик после апгрейда
function fot_upgrade_poluchil()
	got("wpn_fot")
	del_value("fot_upgrade")
end

-- отдадим Фотик для апгрейда и запустим таймер
function fot_upgrade_otdal()
	lost("wpn_fot")
	local gtime = game.minutes()
	set_value("fot_upgrade", gtime + math.random(1,2) * 60)
end

function fot_upgrade_ready()
	local gtime = game.minutes()
	local ftime = get_value("fot_upgrade", 0)
	if ftime~=0 and gtime >= ftime then
		return true
	else
		return false
	end
end

-- Переспавниваем Петруху
function new_petruha_spawn()
find_and_release("esc_novice_attacker1")
	local obj = create("esc_ranger1",xyz(315.09,3.90,118.72),572772,143)
	ai:assign_story_id(obj.id,9)
		timer("run", 1.0, "new_spawn.petruha_stvol_spawn()")
end

-- Спавним ТОЗ Петрухе, если приносили его ранее
function petruha_stvol_spawn()
if has_info("esc_petruha_toz_done") then
	local npc=level_story_object(9)
        if npc then
	create("wpn_toz34",npc:position(),npc:level_vertex_id(),npc:game_vertex_id(),npc:id())
     end
  end
end

function wrong_shoot()
		sms("%c[sender]"..translate("name_volazar")..":\\n%c[sms_red]"..translate("sms_volazar_wrong_shoot_0"), nil, nil, 8000, nil, [[sms\volazar\wrong_shoot]]) 
		timer("zonedocs_gg_kill",10.0,"kostya_dialog.zonedocs_gg_kill()")
		level.add_cam_effector("camera_effects\\radar_stop.anm", 2507, false, "")
	end

function svd_atp_btr_ataka()
say([[weapons\svd\svd_shot]])
db.actor.health = -0.89
db.actor.power = -0.98
		timer("zonedocs_gg_kill",11.5,"kostya_dialog.zonedocs_gg_kill()")
		level.add_cam_effector("camera_effects\\radar_stop.anm", 2507, false, "")
		timer("run", 2.5, "new_spawn.svd_atp_btr_ataka1()")
end

function svd_atp_btr_ataka1()
say([[characters_voice\scenario\buusty\punch\punch_8]])
end

--' убираем Звездочёта с Кордона, когда ГГ отбежал от него более, чем на 100 метров
function esc_zvezdochet_delete()
local se_obj = server_object("esc_zvezdochet")
  if se_obj then
    release(se_obj, true)
  end
end

-- Переспавниваем Призрака
function new_prizrak_spawn()
find_and_release("new_prizrak")
	local obj = create("forg_new_prizrak",xyz(41.40,3.70,-153.96),264180,9324)
	ai:assign_story_id(obj.id,9652)
	map_spot(server_object("forg_free_lager_respawn").id,"crlc_big","yan_ghost_name")
end

-- Убираем Джеймса с компашкой, если разошлись миром
function james_bodyguard_delete()
	release(story_object(9608))
	release(story_object(22067))
	release(story_object(22068))
	release(story_object(22069))
	release(story_object(22070))
	timer("run", 2.0, "new_spawn.rostok_halyava_stop_mosquito_bald_spawn()")
end

-- Спавним огненного элтуша в огненной пещере на НЗ
function eltush_strong_spawn()
	create("eltush_strong",db.actor:position(),db.actor:level_vertex_id(),db.actor:game_vertex_id())
end

function esc_fabrika_atp_restrictor()
	local a = vector()
        a.x = -211.57
        a.y = -19.95
        a.z = -140.32
        db.actor:set_actor_position(a)
end

function esc_psi_space2_sr()
	local a = vector()
        a.x = 99.62
        a.y = 0.80
        a.z = 476.64
        db.actor:set_actor_position(a)
end

function ros_otbros_restrictor()
	local a = vector()
        a.x = -218.45
        a.y = 0.08
        a.z = -54.31
        db.actor:set_actor_position(a)
end

function aes1_zalocation_restrictor()
	local a = vector()
        a.x = 919.30
        a.y = -0.10
        a.z = -384.48
        db.actor:set_actor_position(a)
end

--' удаляем рестриктор с атп, который откидывает игрока к подвалу в ДН
function esc_fabrika_atp_restrictor_delete()
local se_obj = server_object("esc_fabrika_atp_restrictor")
  if se_obj then
    release(se_obj, true)
  end
end

--' Удаляем водку и прочие объекты, после подъёма которых бьют в морду
function vsaykoe_raznoe_delete()
	local se_obj = server_object("esc_conserva_0000")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("bar_vodka_0001")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("bar_bread_0000")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("bar_conserva")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("bar_vodka_0000")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("bar_vodka")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("esc_vodka")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("esc_bread")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("esc_energy_drink_0000")
	if se_obj then
		release(se_obj, true)
	end
end

-- Спавним видеокассету на ДТ скриптом в диалоге с Сахаром, рандомно в 8ми местах
function video_kasseta_spawn()
local b = {
	{position={x=-253.37,y=0.10,z=179.81},gv=1337,lv=8648},
	{position={x=-173.54,y=1.80,z=179.92},gv=1330,lv=30771},
	{position={x=-144.47,y=7.51,z=159.66},gv=1327,lv=39736}, 
	{position={x=-188.81,y=7.05,z=128.16},gv=1326,lv=28587},
	{position={x=-116.28,y=1.33,z=135.71},gv=1312,lv=43460},
	{position={x=-277.85,y=4.55,z=85.15},gv=1411,lv=1317},
	{position={x=-240.21,y=9.36,z=58.23},gv=1391,lv=13901},
	{position={x=-200.96,y=3.04,z=65.84},gv=1375,lv=24929}
}
	local a = table.random(b)
	create("video_kasseta", xyz(a.position.x,a.position.y,a.position.z), a.lv, a.gv)
	local se_obj = create("space_restrictor", xyz(a.position.x,a.position.y,a.position.z), a.lv, a.gv) --, xyz(main_pos.position.x,main_pos.position.y,main_pos.position.z), main_pos.lv, main_pos.gv)
		se_obj:set_ini_lua_string("[logic]\ncfg = scripts\\ros\\dt_zone_zvuk_restrictor.ltx")
		se_obj:add_shape(7.5)
end

function lechite_bandito_sms()
	sms("%c[sender]"..translate("name_bandito_lechite")..":\\n%c[sms_red]"..translate("sms_lechite_bandito"), 12, "uniq", 35000, nil, [[characters_voice\scenario\val\sms_lechite_bandito]])
end


function zasada_back_d62()
if not has_info("go_kteleportu") then
	create("lastday_d6kamp_1",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d6kamp_2",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d61",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d62",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d63",xyz(-406.40,-43.06,-145.46),238,10468)
say([[anomaly\teleport_work_2]])
	timer("run", 120.0, "new_spawn.zasada_back_d63()")
 end
end

function zasada_back_d63()
if not has_info("go_kteleportu") then
	create("lastday_d64",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d6kamp_1",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d65",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d66",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d6kamp_2",xyz(-406.40,-43.06,-145.46),238,10468)
say([[anomaly\teleport_work_2]])
	timer("run", 120.0, "new_spawn.zasada_back_d64()")
 end
end

function zasada_back_d64()
if not has_info("go_kteleportu") then
	create("lastday_d68",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d6kamp_3",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d67",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d69",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d64",xyz(-406.40,-43.06,-145.46),238,10468)
say([[anomaly\teleport_work_2]])
	timer("run", 120.0, "new_spawn.zasada_back_d65()")
 end
end

function zasada_back_d65()
if not has_info("go_kteleportu") then
	create("lastday_d610",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d6kamp_3",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d616",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d611",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d64",xyz(-406.40,-43.06,-145.46),238,10468)
say([[anomaly\teleport_work_2]])
	timer("run", 120.0, "new_spawn.zasada_back_d66()")
 end
end

function zasada_back_d66()
if not has_info("go_kteleportu") then
	create("lastday_d612",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d6kamp_2",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d613",xyz(-406.40,-43.06,-145.46),238,10468)
	create("lastday_d614",xyz(-406.41,-43.06,-131.15),280,10468)
	create("lastday_d615",xyz(-406.40,-43.06,-145.46),238,10468)
say([[anomaly\teleport_work_2]])
--	timer("run", 120.0, "new_spawn.zasada_back_d62()")
 end
end

-- Рандомно спавним вместо контрика в подземке Агро монстров
function agr_u_controller_start_spawn()
local monsters={
"zombie_normal",
"zombie_ghost",
"zombie_hell",
"zombie_beee",
"zombie_blow",
"carlic_weak",
"zombie_trup",
"zombie_trup2",
"zombie_hell1",
"zombie_hell2",
"zombie_hell3",
"zombie_hell4",
"zombie_hell5",
"zombie_hell6",
"zombie_hell7",
"zombie_hell8",
"zombie_hell9",
"zombie_hell10",
"zombie_hell11",
"zombie_hell12",
"zombie_hell13",
"zombie_hell14",
"zombie_hell16",
"zombie_babka_weak",
"zombie_babka_normal",
"zombie_babka_strong",
"ghoul_strong",
"scelet_strong",
"zombie_parazit",
"zombie_immortal",
"carlic_strong",
"vodjanoj",
"zombie_trup_fc",
"burer_weak",
"fracture_weak",
"bibliotekar"
} 
	create(table.random(monsters), xyz(-68.609,-3.925,-140.453),3528,704)
end

--' Удаляем аномалии на Ростоке (по Джеймсу)
function rostok_halyava_stop_mosquito_bald_delete()
    release("rostok_halyava_stop_mosquito_bald")
    release("rostok_halyava_stop_mosquito_bald2")
    release("rostok_halyava_stop_zone_buzz")
end

--' Спавним аномалии на Ростоке (по Джеймсу)
function rostok_halyava_stop_mosquito_bald_spawn()
    create(ai:spawn_id(900094))
    create(ai:spawn_id(900095))
    create(ai:spawn_id(900096))
end

-- Апгрейд бинокля у Долговязого на турели
-- проверка бинокля в инвентаре для апгрейда Долговязого
function binoc_upgrade_have()
return has("wpn_binoc_m1") 
end

-- получим бинокль после апгрейда
function binoc_upgrade_poluchil()
	got("wpn_binoc_m2")
	del_value("binoc_upgrade")
end

-- отдадим бинокль для апгрейда и запустим таймер
function binoc_upgrade_otdal()
	lost("wpn_binoc_m1")
	local gtime = game.minutes()
	set_value("binoc_upgrade", gtime + math.random(1,2) * 60)
end

function binoc_upgrade_ready()
	local gtime = game.minutes()
	local ftime = get_value("binoc_upgrade", 0)
	if ftime~=0 and gtime >= ftime then
		return true
	else
		return false
	end
end

function otbilis_mozhno_peredohnut()
	snd_obj = sound_object("characters_voice\\scenario\\buusty\\post_combat_wait\\relax_"..tostring(math.random(1,12)))  
        snd_obj:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
		timer("run", 5, "new_spawn.otbilis_mozhno_peredohnut1()")
end

function otbilis_mozhno_peredohnut1()
	snd_obj = sound_object("characters_voice\\scenario\\buusty\\post_combat_wait\\wait_"..tostring(math.random(1,10)))  
        snd_obj:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
end

-- Спавним телепорт на ДТ по Сивому
function dt_tele_siviy_spawn()
	create("dt_tele_siviy",xyz(-243.87,-0.00,-40.28),12081,1400)
end

function dt_tele_siviy_delete()
find_and_release("dt_tele_siviy")
end

-- Химик и его таймер
function start_himik()
	local delta= math.random(40, 48) * 60
	local ftime=game.minutes()+delta
        Timer:start_game("himik_timer",0,0,delta,"new_spawn.himik_sms()")
	set_value("start_himik", ftime)
        spawn_restrictor.himik_start_sr()
end

function himik_sms()
	give_info("himik_speak")
	del_value("start_himik")
end

function sarco_monolith_zasada()
create("sarco_monolith_zasada_1",xyz(2.94,53.70,41.58),2519,2417)
create("sarco_monolith_zasada_2",xyz(-0.95,51.40,32.49),1675,2417)
create("sarco_monolith_zasada_3",xyz(-7.64,49.96,30.80),474,2417)
create("sarco_monolith_zasada_4",xyz(-0.88,53.14,23.63),1656,2417)
--	create_car("auto_turret_2",xyz(-18.75,52.62,24.78),308,2417, "scripts\\technics\\turret.ltx")
--	create_car("auto_turret_2",xyz(-4.76,49.56,9.23),716,2417, "scripts\\technics\\turret.ltx")
end

-- Удаляем засаду в Саркофаге, иначе вылет
function sarco_monolith_zasada_delete()
local fnpc_section={ --список того, кого надо прибить по точным секциям
        ["sarco_monolith_zasada_1"]=true,
        ["sarco_monolith_zasada_2"]=true,
        ["sarco_monolith_zasada_3"]=true,
        ["sarco_monolith_zasada_4"]=true
    }
    local cnt=0
    for a=1,65534,1 do
        local obj=server_object(a)
        if obj and fnpc_section[obj:section_name()] then --если есть в нашей табличке
            release(obj,true) --удаляем
            cnt=cnt+1
        end
        if cnt==4 then --их всего четыре - смысла проверять остальное нету
            return
        end
    end
end

function gauss_aes2_krysha_kill()
	snd_obj = sound_object("characters_voice\\human_02\\monolith\\fight\\enemy\\enemy_"..tostring(math.random(1,10)))  
        snd_obj:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
		timer("run", 12, "new_spawn.gauss_aes2_krysha_kill1()")
end

function gauss_aes2_krysha_kill1()
say([[weapons\gauss\gauss_shot]])
db.actor.health = -0.89
db.actor.power = -0.98
		timer("zonedocs_gg_kill",11.5,"kostya_dialog.zonedocs_gg_kill()")
		level.add_cam_effector("camera_effects\\radar_stop.anm", 2507, false, "")
		timer("run", 12, "new_spawn.gauss_aes2_krysha_kill2()")
end

function gauss_aes2_krysha_kill2()
	snd_obj = sound_object("characters_voice\\human_02\\monolith\\fight\\enemy_down\\enemy_down_"..tostring(math.random(1,7)))  
        snd_obj:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
end

--' Удаляем рестриктор на ЧАЭС-2 после уничтожения О-сознания
function aes2_krysha_kill_restrictor_delete()
local se_obj = server_object("aes2_krysha_kill_restrictor")
  if se_obj then
    release(se_obj, true)
  end
end

--' Удаляем рестриктор в Припяти, который проносит нас над стадионом
function pri_space_restrictor_0011_delete()
	release(story_object(830))
end

--' Удаляем рестриктор на ДТ, который выносит на катсцену
function rosros_cutscene_restrictor_delete()
local se_obj = server_object("rosros_cutscene")
  if se_obj then
    release(se_obj, true)
  end
end

function mil_blockpost_free()
	sms("%c[sender]"..translate("name_svoboda")..":\\n%c[sms_red]"..translate("mil_actor_blockpost"), nil, "freedom", 7000, nil, [[characters_voice\scenario\military\pda\mil_pda_7]])
end

function sivii_rostok_ugroza()
sms("%c[sender]"..translate("name_sivii")..":\\n%c[sms_red]"..translate("sms_sivii_rostok_ugroza"), 4, "sivyi", 9000, nil, [[sms\sivyi_joker\pda_kruglov_stop_enemy_2]])
end

-- Подспавним немного наёмников, если играем на Реализме
function rostok_spawn_naemniki_bonus()
	if level.get_game_difficulty() > 2 then
create("sniper_james_5",xyz(-189.60,-5.97,-66.76),28830,1403)
create("sniper_james_8",xyz(-213.66,0.14,-47.20),23676,1401)
create("sniper_james_7",xyz(-232.27,-0.00,34.51),17189,1394)
--create("ros_killer_respawn_4",xyz(-236.57,-0.00,29.57),15458,1394)
create("ros_killer_respawn_4",xyz(-226.96,-0.00,15.28),19435,1398)
create("sniper_james_9",xyz(-227.54,-0.00,-59.67),19108,1401)
 end
end


-- Направим игрока в подсобку (переход в Ц.Припять)
function pri_perebros_podsobka()
	local a = vector()
        a.x = 128.57
        a.y = -4.82
        a.z = 14.84
        db.actor:set_actor_position(a)
	timer("run", 0.01, "new_spawn.pri_perebros_podsobka1()")
end

function pri_perebros_podsobka1()
        db.actor:set_actor_direction(3.25)
end

-- Направим игрока в подсобку (переход на Кордон)
function kor_perebros_podsobka()
	local a = vector()
        a.x = 126.04
        a.y = -4.82
        a.z = 10.25
        db.actor:set_actor_position(a)
	timer("run", 0.02, "new_spawn.kor_perebros_podsobka1()")
end

function kor_perebros_podsobka1()
        db.actor:set_actor_direction(1.65)
end

-- Направим игрока в подсобку к Сидору (переход в Бар)
function bar_perebros_podsobka()
	local a = vector()
        a.x = -242.30
        a.y = -24.79
        a.z = -134.35
        db.actor:set_actor_position(a)
	timer("run", 0.02, "new_spawn.bar_perebros_podsobka1()")
end

function bar_perebros_podsobka1()
        db.actor:set_actor_direction(1.22)
end

function blokpost_kuzya_agritsya()
	snd_obj = sound_object("characters_voice\\human_03\\military\\fight\\enemy\\enemy_"..tostring(math.random(1,6)))  
        snd_obj:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
end

-- Удаляем переход Ц.Припять-Бар
function pri_bar_delete()
	release(story_object(130040))
 disable_info("doktor_perehod_dostup_info")
end

-- Удаляем переход Кордон-Бар
function kor_bar_delete()
	release(story_object(130037))
 disable_info("sidor_perehod_dostup_info")
end

function pri_bar_door_locked()
say([[device\metal_door_locked]])
end

-- Запускаем таймер на 24 часа, в течении которых ГГ должен успеть выкрасть чумодан с компроматом
function start_sralomazalskiy()
	local delta= math.random(24, 25) * 60
	local ftime=game.minutes()+delta
        Timer:start_game("sralomazalskiy_timer",0,0,delta,"new_spawn.sralomazalskiy_sms()")
--	set_value("start_sralomazalskiy", ftime)
end

function sralomazalskiy_sms()
if not has_info("chasovoy_trezv_say_stop") then
sms("%c[sender]"..translate("piyan_kapitan_name")..":\\n%c[sms_red]"..translate("sms_piyan_kapitan"), 4, "piyan_kapitan", 11000, nil, [[sms\piyan_kapitan\suchi_suhari]])
	give_info("zadanie_kuzy_proval")
--	del_value("start_sralomazalskiy")
arhara_dialog.delete_agro_musor()
 end
end

-- Спавним охранника Борова в дверях
function bodyguard_borov_spawn()
        create("val_bandit_bodyguard_borov",xyz(34.89,4.54,-82.84),217598,1100)
end

-- Спавним охранника дублёра Борова в дверях (в случае его гибели)
function bodyguard_borov_spawn1()
        create("val_bandit_bodyguard_borov",xyz(13.26,1.21,-75.63),189842,1103)
end

-- Удаляем телепорты с Болот, по квесту Падшие
function delete_marsh_tele_padshie()
for a=1,65534,1 do
local obj=server_object(a)
if obj and string.find(obj:name(),"marsh_tele_padshie") then
release(obj,true)
end
end
end

function radar_tele_otbros_spawn()
        create("radar_tele_otbros",xyz(147.22,-9.27,-25.59),52687,1976)
end

function delete_radar_tele_otbros()
for a=1,65534,1 do
local obj=server_object(a)
if obj and string.find(obj:name(),"radar_tele_otbros") then
release(obj,true)
end
end
end

function morphin_end()
level.add_pp_effector("dead_zone.ppe", 1002, true)
	local snd = voice("ambient\\random\\rnd_respawn")
	snd:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
	timer("run", 0.5, "new_spawn.morphin_end1()")
	timer("run", 40.0, "new_spawn.morphin_end2()")
 end
function morphin_end1()
	local snd = voice("heart\\3")
	snd:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
	timer("run", 8.0, "new_spawn.morphin_end3()")
 end
function morphin_end3()
	local snd = voice("heart\\4")
	snd:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
	timer("run", 8.0, "new_spawn.morphin_end4()")
 end
function morphin_end4()
	local snd = voice("heart\\3")
	snd:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
	timer("run", 8.0, "new_spawn.morphin_end5()")
 end
function morphin_end5()
	local snd = voice("heart\\4")
	snd:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
	timer("run", 8.0, "new_spawn.morphin_end6()")
 end
function morphin_end6()
	local snd = voice("heart\\3")
	snd:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
 end

function morphin_end2()
say([[characters_voice\human_01\stalker\states\idle\idle_27]])
		level.remove_pp_effector(1002)
snp.invul_off()
 end


function dt_zalokoy_kill()
say([[characters_voice\scenario\buusty\merc_leader_regret]])
		timer("run", 10, "new_spawn.dt_zalokoy_kill1()")
end

function dt_zalokoy_kill1()
say([[weapons\sr25\shot]])
db.actor.health = -0.89
db.actor.power = -0.98
		timer("zonedocs_gg_kill",11.5,"kostya_dialog.zonedocs_gg_kill()")
		level.add_cam_effector("camera_effects\\radar_stop.anm", 2507, false, "")
		timer("run", 12, "new_spawn.dt_zalokoy_kill2()")
end

function dt_zalokoy_kill2()
	snd_obj = sound_object("characters_voice\\scenario\\buusty\\doprygalsya\\doprygalsya_"..tostring(math.random(1,3)))  
        snd_obj:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
end


--' Удаляем мину на лестнице в Лабиринте (при подборе сейфа)
function av_bunker_lestn_mina_delete()
	local se_obj = server_object("av_bunker_lestn_mina")
	if se_obj then
		release(se_obj, true)
	end
end


-- Спавним разбиваемый синий ящик с Д-Пантенолом
function pantenol_box_spawn()
local b = {
		{position={x=171.21,y=5.26,z=16.05},gv=3768,lv=399594},
		{position={x=173.96,y=6.025,z=21.46},gv=3768,lv=404027},
	        {position={x=183.00,y=5.36,z=41.99},gv=3768,lv=413570},
	        {position={x=192.365,y=6.035,z=56.167},gv=3770,lv=422312},
	        {position={x=191.02,y=2.12,z=71.55},gv=3770,lv=421155},
	        {position={x=171.79,y=0.756,z=35.24},gv=3768,lv=400321},
	        {position={x=181.21,y=1.81,z=35.635},gv=3768,lv=410830},
	        {position={x=205.53,y=1.00,z=66.28},gv=3770,lv=432246},
	        {position={x=231.81,y=0.75,z=16.30},gv=3768,lv=451503},
	        {position={x=239.66,y=-0.43,z=17.20},gv=3768,lv=456209},
	        {position={x=229.09,y=1.36,z=5.07},gv=3768,lv=448925},
	        {position={x=213.12,y=0.545,z=-10.41},gv=3768,lv=438498},
	        {position={x=201.94,y=-0.43,z=-12.73},gv=3768,lv=429902},
	        {position={x=210.53,y=0.54,z=-16.41},gv=3768,lv=436958},
	        {position={x=215.82,y=4.454,z=5.45},gv=3768,lv=440840},
	        {position={x=219.75,y=4.684,z=-12.76},gv=3768,lv=443191},
	        {position={x=196.67,y=4.684,z=-20.17},gv=3768,lv=426320},
	        {position={x=206.27,y=11.564,z=-14.34},gv=3768,lv=433813}
	}
	local a = table.random(b)
	local se_obj = create("d_pantenol_box", xyz(a.position.x,a.position.y,a.position.z), a.lv, a.gv)
end

--' тайник с Супер-Шоти для Лентяя заспавним в ВарЛабе рандомно в 10ти местах
function box_lentay_spawn()
local b = {
	{position={x=7.256,y=-6.525,z=-12.801},gv=3202,lv=5624},
	{position={x=4.37,y=2.17,z=-6.43},gv=3210,lv=5209},
        {position={x=16.50,y=3.180,z=-7.71},gv=3216,lv=7049}, 
	{position={x=2.64,y=-3.125,z=-11.46},gv=3187,lv=4857},
	{position={x=-19.145,y=-7.655,z=-16.37},gv=3167,lv=957},
	{position={x=-23.40,y=-12.12,z=-50.775},gv=3161,lv=562},
	{position={x=1.15,y=-11.30,z=13.682},gv=3189,lv=5419},
	{position={x=1.38,y=2.834,z=4.64},gv=3187,lv=4548},
	{position={x=-8.85,y=5.44,z=20.49},gv=3173,lv=2579},
	{position={x=-14.82,y=-1.42,z=-34.38},gv=3164,lv=1512}
}
	local a = table.random(b)
	local se_obj = create("m_inventory_box_lentay", xyz(a.position.x,a.position.y,a.position.z), a.lv, a.gv)
end

-- Удаляем любую взрывчатку на определённой локации
function delete_vzryvchata_kanistren()
local rem_sections={
	["bomba"]=true,
	["bomba_big"]=true,
	["quest_mina"]=true,
	["bomba_small"]=true,
	["smoke_bomba"]=true,
	["bomba_mina_n"]=true,
	["bomba_mina_b"]=true,
	["amk_kanistra"]=true,
	["amk_ballon"]=true,
	["caps_mosquito_bald_average"]=true,
	["caps_gravi_zone_average"]=true,
	["caps_mincer_average"]=true,
	["caps_witches_galantine_average"]=true,
	["caps_zharka_static_average"]=true,
	["caps_buzz_average"]=true,
	["caps_ice_average"]=true	
}
	if not level.name():lower()=="l03_agroprom" then
		return
	end
	local actor_pos=db.actor:position()
          ai:iterate_alife_objects(function(sobj)
		if sobj 
			and sobj.parent_id~=db.actor:id()
			and rem_sections[sobj:section_name()]
			and object_level_name(sobj):lower()=="l03_agroprom"
		then
			local s_dist=actor_pos:distance_to(sobj.position)
			if s_dist >65 and s_dist < 95 then
				release(sobj)
			end
		end
	end) 
end

-- Запускаем таймер на 24 часа, в течении которых, ГГ должен успеть посетить Курчатов-37 и помочь Катане отбиться от наймов
function start_katana_timer()
	local delta= math.random(24, 25) * 60
	local ftime=game.minutes()+delta
        Timer:start_game("katana_timer",0,0,delta,"new_spawn.sms_katana_mechenyi_goodbye()")
end

function sms_katana_mechenyi_goodbye()
if level.name()=="l37_kurchatov" or has_info("katana_find_done") then return end
sms("%c[sender]"..translate("name_kuzkina_mat")..":\\n%c[sms_red]"..translate("sms_katana_mechenyi_goodbye"), nil, "kuzmat", 35000, nil, [[sms\kuzmat\sms_katana_mechenyi_goodbye]])
timer("run", 1.0, "new_spawn.delete_value_katana_timer()")
--say([[device\pda\pda_sos]])
	give_info("katana_find_proval")
end

function delete_value_katana_timer()
	release(story_object(130051))
	release(story_object(30173))
 find_and_release("vanga_npc")
end

-- Новый квест за монолит
-- Запускаем таймер на час, в течении которых, ГГ должен успеть посетить Подземку Припяти и помочь монолитовцам
function start_btm_timer()
	local delta= math.random(1, 1) * 60
	local ftime=game.minutes()+delta
        Timer:start_game("btm_timer",0,0,delta,"new_spawn.sms_btm_mechenyi_goodbye()")
end

function sms_btm_mechenyi_goodbye()
if level.name()=="l49u_damned" or has_info("stop_timer_monolita") then return end
sms("%c[sender]"..translate("name_tm_brother")..":\\n%c[sms_red]"..translate("sms_tm_brother_goodbye"), nil, "tm_brother_2chaes", 35000, nil, [[sms\shadow_monolit\tm_brother_goodbye]])
timer("run", 2.0, "new_spawn.delete_value_btm_timer()")
end

function delete_value_btm_timer()
	release(story_object(130068))
	release(story_object(22046))
	give_info("vernut_maps_proval")
timer("run", 1.0, "new_spawn.delete_dam_mono_podmoga()")
end

function delete_dam_mono_podmoga()
for a=1,65534,1 do
local obj=server_object(a)
if obj and string.find(obj:name(),"dam_mono_podmoga") then
release(obj,true)
end
end
end

-- Спавним группу поддержки монолитовцев в Подземелье Припяти
function mono_podmoga_spawn()
	local obj = amk.spawn_item("dam_mono_podmoga",xyz(65.37,-0.00,-115.93),5782,65934)
	netpacket:modify(obj, "story_id", 22046)
        create("dam_mono_podmoga1",xyz(62.25,-0.00,-122.09),65355,5782)
        create("dam_mono_podmoga2",xyz(63.53,0.15,-120.55),65645,5782)
        create("dam_mono_podmoga3",xyz(68.59,0.15,-115.34),66535,5782)
        create("dam_mono_podmoga4",xyz(70.55,0.02,-112.89),66746,5783)
timer("run", 1.0, "spawn_restrictor.nebegi_vperedi_paravoza_sr()")
timer("run", 1.5, "new_spawn.start_btm_timer()")
timer("run", 1.7, "new_spawn.spawn_bonus_tayniki()")
end

-- Заспавним бонусные тайнички в Подземке Припяти
function spawn_bonus_tayniki()
        create("m_inventory_box87",xyz(20.04,41.20,375.16),46727,5858)
        create("m_inventory_box88",xyz(22.84,40.09,397.35),48770,5864)
        create("m_inventory_box89",xyz(-17.39,33.59,356.76),34477,5843)
        create("m_inventory_box90",xyz(-79.89,24.23,540.26),12736,5833)
        create("ammo_23x76_shrap",xyz(-43.39,27.13,538.10),22190,5957)
end

-- Спавним капитана Казанцева из рестриктора
function kapitan_kazancev_spawn()
	local obj = amk.spawn_item("dam_kapitan_kazancev",xyz(-101.71,38.13,478.46),5817,2884) -- Спавним капитана подальше, сложнее
--	local obj = amk.spawn_item("dam_kapitan_kazancev",xyz(-102.11,37.59,475.48),5818,2814) -- Спавним капитана поближе, легче
	netpacket:modify(obj, "story_id", 22047)
        create("kazancev_bodyguard1",xyz(-103.82,38.13,479.11),2573,5818)
        create("kazancev_bodyguard2",xyz(-113.91,38.14,459.48),1777,5818)
        create("kazancev_bodyguard3",xyz(-115.90,38.23,461.50),1647,5818)
        create("zasada_blockpost_3",xyz(-101.03,37.92,470.88),3020,5818)
	timer("run", 1.0, "new_spawn.kapitan_kazancev_spawn1()")
end

function kapitan_kazancev_spawn1()
	sms("%c[sender]"..translate("name_lokalnaya_set")..":\\n%c[sms_red]"..translate("sms_kapitan_kazancev_begite_0"), nil, "morozko", 5000, nil, [[sms\kapitan_kazancev\kapitan_kazancev_begite]])
end

function kapitan_kazancev_delete()
find_and_release("dam_kapitan_kazancev")
	sms("%c[sender]"..translate("capitan_kazancev_name")..":\\n%c[sms_red]"..translate("sms_kapitan_kazancev_proval_0"), nil, "dam_kapitan_kazancev", 7000, nil, [[sms\kapitan_kazancev\kapitan_kazancev_proval]])
	timer("run", 7.0, "new_spawn.kapitan_kazancev_proval()")
end

function kapitan_kazancev_proval()
	give_info("vernut_maps_proval")
end

-- Спавним засланных казачков типа, монолитовцев, снайперов, трупы
function monolith_kazachoks_spawn()
        create("monolith_kazachok1",xyz(-7.26,0.01,66.23),37252,5814)
        create("monolith_kazachok2",xyz(1.04,-0.00,40.30),39811,5812)
        create("podzemka_sniper1",xyz(26.12,26.46,27.85),49667,5800)
        create("podzemka_sniper2",xyz(19.88,26.46,34.75),46622,5800)
        create("podzemka_sniper3",xyz(6.90,26.47,39.58),41804,5800)
        create("podzemka_sniper4",xyz(-22.14,26.47,33.72),29708,5799)
        create("podzemka_sniper5",xyz(-9.42,20.32,-23.12),36577,5969)
	create_car("auto_turret_2",xyz(-12.14,20.34,-24.71),35880,5969, "scripts\\technics\\turret.ltx")
 snp.dam_mono_spawn_trups()
timer("run", 2.0, "new_spawn.spawn_bonus_zasada()")
timer("run", 1.25, "new_spawn.iskorenim_vragov()")
end

function spawn_bonus_zasada()
        create("podzemka_zasada1",xyz(-21.86,8.94,-37.91),30063,5973)
        create("podzemka_zasada2",xyz(-29.17,11.26,-24.21),26455,5973)
        create("podzemka_zasada3",xyz(-33.28,12.38,-10.51),24689,5975)
        create("podzemka_zasada4",xyz(-2.73,0.00,5.64),38506,5777)
        create("podzemka_zasada5",xyz(4.13,0.04,4.08),40941,5772)
        create("podzemka_zasada6",xyz(14.49,0.37,5.79),44478,5772)
        create("podzemka_zasada7",xyz(25.81,-0.00,1.11),49635,5775)
        create("podzemka_zasada8",xyz(31.26,1.59,-4.83),52903,5790)
        create("podzemka_zasada9",xyz(17.25,0.37,-11.44),45588,5775)
        create("podzemka_zasada10",xyz(22.13,0.37,25.87),48000,5759)
        create("podzemka_zasada11",xyz(28.12,0.37,-19.46),50756,5787)
        create("zasada_blockpost_1",xyz(26.09,-0.00,43.51),49716,5760)
        create("zasada_blockpost_2",xyz(42.46,-0.50,21.15),59158,5762)
        create("zasada_blockpost_3",xyz(5.94,-0.00,43.63),41385,5812)
end

-- Спавним засаду за дверями
function kazancev_bodyguard_spawn()
        create("kazancev_bodyguard4",xyz(-16.72,-0.03,87.72),32976,5890)
        create("kazancev_bodyguard5",xyz(0.30,-0.52,71.29),39573,5890)
        create("kazancev_bodyguard6",xyz(9.03,-0.52,85.24),42530,5889)
end

-- Спавним сержанта Сидоренко с прикрытием
function sergant_sidorenko_spawn()
        create("sergant_sidorenko",xyz(0.79,26.46,-38.53),39692,5811)
        create("sidorenko_prikrytie",xyz(18.20,26.54,-37.23),45880,5810)
        create("sidorenko_prikrytie1",xyz(27.77,26.47,-26.77),50746,5810)
        create("sidorenko_prikrytie2",xyz(6.47,0.38,2.33),41530,5772)
end

function delete_vzryvchata_podzemka()
local rem_sections={
	["bomba"]=true,
	["bomba_big"]=true,
	["quest_mina"]=true,
	["smoke_bomba"]=true,
	["bomba_small"]=true,
	["bomba_mina_n"]=true,
	["bomba_mina_b"]=true,
	["amk_kanistra"]=true,
	["amk_ballon"]=true	
}
	if not level.name():lower()=="l49u_damned" then
		return
	end
	local actor_pos=db.actor:position()
          ai:iterate_alife_objects(function(sobj)
		if sobj 
			and sobj.parent_id~=db.actor:id()
			and rem_sections[sobj:section_name()]
			and object_level_name(sobj):lower()=="l49u_damned"
		then
			local s_dist=actor_pos:distance_to(sobj.position)
			if s_dist >67 and s_dist < 95 then
				release(sobj)
			end
		end
	end) 
end

-- Прверим наличие карт для БТМ и 2х КПК
function btm_prichindaly_have()
return has("chemodan_monolita",1) and
has("pda_mono_voen",1) and
has("pda_sniper_voen",1)
end

-- отдадим карты и 2 КПК
function btm_prichindaly_otdal()
	lost("chemodan_monolita",1)
	lost("pda_mono_voen",1)
	lost("pda_sniper_voen",1)
	got("af_teleport")
end

function iskorenim_vragov()
        say([[characters_voice\human_01\monolith\fight\attack\script_attack_8]])
timer("run", 2.8, "new_spawn.iskorenim_vragov1()")
end

function iskorenim_vragov1()
        say([[characters_voice\human_01\monolith\fight\attack\script_attack_7]])
timer("run", 3.0, "new_spawn.iskorenim_vragov2()")
end

function iskorenim_vragov2()
        say([[characters_voice\human_01\monolith\fight\attack\script_attack_9]])
timer("run", 2.8, "new_spawn.iskorenim_vragov3()")
end

function iskorenim_vragov3()
        say([[characters_voice\human_01\monolith\fight\attack\script_attack_10]])
end

function bar_posadili_vkletku()
	snd_obj = sound_object("characters_voice\\human_01\\dolg\\states\\panic_human\\panic_human_"..tostring(math.random(1,8)))  
        snd_obj:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
end

function kupol_sin_spawn()
for i=1, 3 do
	create("dam_kupol_sin_general",xyz(44.06,-0.00,48.02),59800,5765)
	create("dam_kupol_sin_veteran",xyz(44.06,-0.00,48.02),59800,5765)
	create("dam_kupol_sin_novice",xyz(44.06,-0.00,48.02),59800,5765)
 end
end

function zashit_penrenko_teleport_spawn()
	create("zashit_penrenko_teleport",xyz(201.69,1.05,58.86),48192,1201)
end

--' Удаляем рестрикторы на Болотах, при прохождении островов
function marsh_cheated_zone_delete()
	local se_obj = server_object("restr_marsh_cheated_zone")
	if se_obj then
		release(se_obj, true)
	end
	local se_obj = server_object("restr_marsh_cheated_zone2")
	if se_obj then
		release(se_obj, true)
	end
end

function delete_kamen_udachy()
	give_info("no_teleport_near_heli_btr")
find_and_release("m_teleport_hospital")
timer("run", 600, "new_spawn.delete_kamen_udachy1()")
end

function delete_kamen_udachy1()
if has_info("spawn_hospit_live") then return end
find_and_release("af_kamen_udachy")
find_and_release("caps_mincer_average")
give_info("say_dok_after_varka_start")
--say([[device\pda\pda_sos]])
end

function teleport_hospital_spawn()
create("m_teleport_hospital",xyz(-74.60,23.71,562.00),7350,3075)
end

-- Запускаем таймер на 7 часов, в течении которых, ГГ должен успеть принести Фенриру КУ для лечения
function start_snp_kamen_timer()
	local delta= math.random(7, 8) * 60
	local ftime=game.minutes()+delta
        Timer:start_game("btm_timer",0,0,delta,"new_spawn.sms_snp_kamen_mechenyi_goodbye()")
end

function sms_snp_kamen_mechenyi_goodbye()
if has_info("snp_kamen_udachy_done") then return end
give_info("snp_kamen_udachy_fail")
end

function mutants_around_spawn()
if has_info("agroprom_military_case_have") then
local monsters={
"rat_weak",
"rat_normal",
"rat_strong",
"rat_plague",
"komar",
"fly_micro",
"fly_plague",
"bee_micro",
"tarakan_strong",
"tarakan_normal"
} 
	local ap = db.actor:position()
	local lv = db.actor:level_vertex_id()
	local gv = db.actor:game_vertex_id()
        for c=1,math.random(10,14) do
	create(table.random(monsters), xyz(ap.x+math.random(-2,2), ap.y, ap.z+math.random(-2,2)), lv, gv)
end
end
end

-- Спавним переход Свалка-ТД
function exit_garbage_darkvalley_spawn()
	local obj = story_object(196)
	if not obj then
		obj=create(ai:spawn_id(196))
	end
	map_spot(obj.id, "level_changer2", "to_darkvalley")
end

-- Смарт, который надо выкосить
function clear_smart(id_smart)
	local smart=server_object("dshor_stalki11") --объект смарта
	local remove_request={}
	if smart and smart:clsid()==clsid.smart_terrain and smart.gulag:get_population()>0 then --проверим что смарт подходит для очистки
		for id,data in pairs(smart.npc_info) do 
			if data.se_obj and isStalker(data.se_obj) and data.se_obj:alive()  then
				table.insert(remove_request,data.se_obj) --список только живых сталкеров, тут удалять не рекомендую, поэтому в табличку
			end
		end
	else
		return --тут бы можно и по ошибке вылететь
	end
	if table.size(remove_request) >0 then --если есть кого очищать
		for __,sobj in ipairs(remove_request) do
			smart:unregister_npc(sobj) --уберем его из смарта
			release(sobj) --уберем из алайфа
		end
	end
end

-- Делаем Муху невидимой в контактах
function fix_so(story_id)
	if not story_id then
		log("! ERROR invalid input name for fix_so!!!")
		return
	end
	local sobj=story_object(story_id)			
	if sobj then
		level.client_spawn_manager():add(sobj.id, 0, function (dummy, id, obj) 
			local pda=obj:item_in_slot(inventory_slots.PDA)
			if pda then
				release(pda)
			end
		end,nil)
	end
end

function fix_foto_muzhiki(muzik_name)
	if not muzik_name then
		log("! ERROR invalid input name for fix_foto_muzhiki!!!")
		return
	end
	local sobj=server_object(muzik_name)
	if sobj then
		level.client_spawn_manager():add(sobj.id, 0, function (dummy, id, obj) 
			local pda=obj:item_in_slot(inventory_slots.PDA)
			if pda then
				release(pda)
			end
		end,nil)
	else
		log("! ERROR invalid sobj name for fix_foto_muzhiki!!!")
	end	
end

-- Удаляем любую аномалию на определённой локации
function delete_caps_anoms()
local rem_sections={
	["caps_mosquito_bald_average"]=true,
	["caps_gravi_zone_average"]=true,
	["caps_mincer_average"]=true,
	["caps_witches_galantine_average"]=true,
	["caps_zharka_static_average"]=true,
	["caps_buzz_average"]=true,
	["caps_ice_average"]=true
}
	if not level.name():lower()=="l03_agroprom" then
		return
	end
	local actor_pos=db.actor:position()
          ai:iterate_alife_objects(function(sobj)
		if sobj 
			and sobj.parent_id~=db.actor:id()
			and rem_sections[sobj:section_name()]
			and object_level_name(sobj):lower()=="jupiter"
		then
			local s_dist=actor_pos:distance_to(sobj.position)
			if s_dist >1 and s_dist < 60 then
				release(sobj)
			end
		end
	end) 
end

-- Спавним буханку на АТП
function veh_car_uazik_spawn()
	local obj = story_object(22048)
	if not obj then
		obj=create(ai:spawn_id(22048))
	end
end

function disable_escape_razvod()
timer("run", 6, "new_spawn.disable_escape_razvod1()")
end

function disable_escape_razvod1()
        disable_info("escape_razvod_sey_done")
end

function enemy_aliver_release()
	for id,obj in pairs(db.creatures) do
		if obj and isAliveEntity(obj) and obj:id()~=0 and 
			(db.actor:relation(obj) == game_object.enemy or obj:relation(db.actor) == game_object.enemy) 
		then
			release(obj)
		end
	    end
	end

--function land_arhara_sniper_drug(actor, npc)
--    xr_gulag.setGulagGoodwill("land_arhara_sniper", actor)
--end

