function start_timer_final()
    amk.g_start_timer("final",0,0,7)
end

function varjag_anna_offline()
	local npc = alife():story_object(1857)
		if npc then
			alife():set_switch_offline (npc.id, true)
			alife():set_switch_online (npc.id, false)
			alife():set_interactive (npc.id, false)
		end
	local npc = alife():story_object(1817)
		if npc then
			alife():set_switch_offline (npc.id, true)
			alife():set_switch_online (npc.id, false)
			alife():set_interactive (npc.id, false)
		end	
end

function final_relocate_item(gg,npc)
	dialogs.relocate_item_section(npc, "af_dusha_zony", "out")
	dialogs.relocate_item_section(npc, "doc_shram", "out")
	dialogs.relocate_item_section(npc, "doc_shram_2", "out")
end

function blokpost()
	db.actor:give_info_portion("pred_proriv_complete")
	if not has_alife_info("open_vorota")then
	db.actor:give_info_portion("vorota")
	db.actor:give_info_portion("pre_soldier_dead")
	end
	if db.actor:has_info("open_vorota")then
	db.actor:disable_info_portion("open_vorota")
	amk.g_start_timer("spawn_major",1,0,0)
	end	
end

function spawner_major()
	db.actor:give_info_portion("spawner_major")
	local npc = alife():story_object(1821)
	if npc then
		alife():set_switch_offline (npc.id, true)
		alife():set_switch_online (npc.id, false)
		alife():set_interactive (npc.id, false)
	end
end
	
function realwolf_quest_vod()
	if level.name()=="garbage_old" then
	db.actor:give_info_portion("pre_realwolf_quest_vod_end")
	end 	
end

function relocate_money_to_actor(first_speaker, second_speaker)
    dialogs.relocate_money(second_speaker, 10000, "in")
end

function moe_pda()	
	alife():create("moe_pda",db.actor:position(),db.actor:level_vertex_id(),db.actor:game_vertex_id(),db.actor:id())
end


function start_timer_offline()
    amk.g_start_timer("offline",0,0,10)
end

function start_timer_offline_2()
    amk.g_start_timer("offline_2",0,0,3)
end

function return_zona()
    amk.g_start_timer("return_zona",0,0,5)
end

 function spawn_val()
	local obj = alife():create("val",vector():set(-40.072,-0.545,332.599),880845,3985)
	local params = amk.read_stalker_params(obj)
	params.custom="[logic]\ncfg = scripts\\predbannik\\pre_val.ltx"
	params.sid = 15050
	amk.write_stalker_params(params,obj)
end
	
function relocate_jeton(gg, npc)
	dialogs.relocate_item_section(gg,"jeton_arm","in")
end

function spawn_trup()
	local obj = alife():create("valet",vector():set(-167.736,-2.626,-55.055),2186,2863)
	local tbl = amk.read_stalker_params(obj)
	tbl.health = 0
	tbl.updhealth = 0
	amk.write_stalker_params(tbl, obj)
end

function spawn_podsumok()  
	alife():create("podsumok",vector():set(-117.669,0.200,-253.116),9335,3241) 
end

function podsumok_have()
	if db.actor:object("podsumok") then
	local obj=alife():create("jeton_arm", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
	news_manager.send_tip(db.actor, "В найденном подсумке обнаружены именные армейские жетоны.", nil, nil, 20000)
		return true
	end
	return false
end


function sheph_offline()
	local npc = alife():story_object(1610)
	if npc then
		alife():set_switch_offline (npc.id, true)
		alife():set_switch_online (npc.id, false)
		alife():set_interactive (npc.id, false)
	end
end
	
function sheph_delete()
	local npc = alife():story_object(1610)
		if npc then
			alife():set_switch_offline (npc.id, true)
			alife():set_switch_online (npc.id, false)
			alife():set_interactive (npc.id, false)
		end
	end	
		
function sheph_online()
	local npc = alife():story_object(1610)
		if npc then
			alife():set_switch_offline (npc.id, false)
			alife():set_switch_online (npc.id, true)
			alife():set_interactive (npc.id, true)
		end
	for a=1823,1828 do	
	local npc = alife():story_object(a)
		if npc then
			alife():set_switch_offline (npc.id, true)
			alife():set_switch_online (npc.id, false)
			alife():set_interactive (npc.id, false)
		end
	end		
end		

function pda_pda(npc,gg)
	dialogs.relocate_item_section(gg,"moe_pda","in")
end
	

function night_star_1(npc,gg)
	db.actor:give_info_portion("pre_night_star_quest_start")
	dialogs.relocate_money(npc, 1000, "in")
	dialogs.relocate_item_section(npc, "det_artefact_indy", "in")
end

function night_star_2(npc,gg)
	db.actor:give_info_portion("pre_night_star_quest_start")
	dialogs.relocate_item_section(npc, "medkit", "in")
	dialogs.relocate_item_section(npc, "antirad", "in")
	dialogs.relocate_item_section(npc, "ammo_9x18_fmj", "in")
	dialogs.relocate_item_section(npc, "det_artefact_indy", "in")
end

function night_star_have()
	if db.actor:object("af_night_star") then
		return true
	end
	return false
end

function night_star_not_have()
	if not db.actor:object("af_night_star") then
		return true
	end
	return false
end

function give_night_star_reward_1(npc,gg)
	dialogs.relocate_item_section(npc,"af_night_star","out")
	dialogs.relocate_money(npc,2500,"in")
end

function give_night_star_reward(npc,gg)
	dialogs.relocate_item_section(npc,"af_night_star","out")
	dialogs.relocate_money(npc,2000,"in")
	dialogs.relocate_item_section(npc,"vodka","in")
end

function night_star_dialog_precond(npc,gg)
	if has_alife_info("pre_night_star_quest_end") or has_alife_info("pre_night_star_cancel")
	or not has_alife_info("pre_talk_with_krohobor_start") then
		return true
	end
	return false
end

function box_quest_have() 
	return     
	items.item_much("wpn_rpg7",2) ~= false and                                                        
	items.item_much("wpn_svd",1) ~= false and
	items.item_much("wpn_svu",1) ~= false and
	items.item_much("wpn_sr3t",3) ~= false and
	items.item_much("ammo_og-7b",4) ~= false and
	items.item_much("af_electra_moonlight",3) ~= false and
	items.item_much("af_fuzz_kolobok",2) ~= false and
	items.item_much("af_night_star",3) ~= false and
	items.item_much("af_gold_fish",2) ~= false and
	items.item_much("af_cristall",3) ~= false
end



function krohobor_relocate_item(gg, npc)
	items.relocate_n_items_section(npc, "wpn_rpg7", "out", 2)
	items.relocate_n_items_section(npc, "wpn_svd", "out", 1)
	items.relocate_n_items_section(npc, "wpn_svu", "out", 1)
	items.relocate_n_items_section(npc, "wpn_sr3t", "out", 3)
	items.relocate_n_items_section(npc, "ammo_og-7b", "out", 4)
	items.relocate_n_items_section(npc, "af_electra_moonlight", "out", 3)
	items.relocate_n_items_section(npc, "af_fuzz_kolobok", "out", 2)
	items.relocate_n_items_section(npc, "af_night_star", "out", 3)
	items.relocate_n_items_section(npc, "af_gold_fish", "out", 2)
	items.relocate_n_items_section(npc, "af_cristall", "out", 3)
end


function morder_dialog_precond(npc,gg)
	if has_alife_info("pre_morder_quest_end") or not has_alife_info("pre_morder_quest_start") then
		return true
	end
	return false
end

function pda_have()
	if db.actor:object("pre_pda_quest") then
		return true
	end
	return false
end

function morder_quest_with_matvei(gg, npc)
	local obj = level_object_by_sid (1601)
	if obj ~= nil then
		dialogs.companion_start_following(obj, gg)
		dialogs.companion_beh_walk_low_aggr(db.actor, obj)
	end
end

function morder_quest_reward(gg,npc)
	dialogs.relocate_item_section(gg,"pre_pda_quest","out")
	dialogs.relocate_item_section(gg,"medkit","in")
	dialogs.relocate_item_section(gg,"bandage","in")
	db.actor:give_info_portion("pre_morder_quest_end")
	local obj = level_object_by_sid (1601)
	if obj ~= nil and dialogs.is_companion(gg, obj) == true then
		dialogs.companion_stop_following(obj, gg)
	end
end

function morder_spot_remove(gg,npc)
	local sobj = alife():story_object(1602)
	if sobj then 
		amk.remove_spot_from_map(sobj.id,"blue_location") 
	end
end

function morder_peshera_quest_items_precond()
	if db.actor:object("bomba_big") then
		if not has_alife_info("pre_morder_peshera_quest_items") then
			db.actor:give_info_portion("pre_morder_peshera_quest_items")
		end
		return true
	end
	return false
end
	
function morder_quest_peshera_with_morder(gg, npc)
	local obj = level_object_by_sid (1602)
	if obj ~= nil then
		dialogs.companion_start_following(obj, db.actor)
		dialogs.companion_beh_walk_low_aggr(obj, db.actor)
	end
end

function morder_quest_peshera_reward_1(gg, npc)
	dialogs.relocate_item_section(npc,"bomba_big","out")
	dialogs.relocate_item_section(npc,"af_blood","in",2)
	dialogs.relocate_item_section(npc,"medkit","in",3)
	dialogs.relocate_item_section(npc,"bandage","in",8)
	dialogs.relocate_item_section(npc,"ammo_5.45x39_fmj","in",7)
	dialogs.relocate_item_section(npc,"antirad","in",5)
	local obj = level_object_by_sid (1602)
	if obj ~= nil and dialogs.is_companion(gg, obj) == true then
		dialogs.companion_stop_following(obj, gg)
	end
end

function morder_quest_peshera_reward_2(gg, npc)
	dialogs.relocate_item_section(npc,"bomba_big","out")	
	dialogs.relocate_item_section(npc,"af_blood","in",2)	
	dialogs.relocate_item_section(npc,"medkit","in",3)	
	dialogs.relocate_item_section(npc,"bandage","in",8)
	dialogs.relocate_item_section(npc,"ammo_5.45x39_fmj","in",7)	dialogs.relocate_item_section(npc,"antirad","in",5)	
	dialogs.relocate_item_section(npc,"medkit_army","in")	
	dialogs.relocate_item_section(npc,"repair_kit","in")
	local obj = level_object_by_sid (1602)
	if obj ~= nil and dialogs.is_companion(gg, obj) == true then
		dialogs.companion_stop_following(obj, gg)
	end
end	

function morder_quest_fail()
	local npc = level_object_by_sid (1602)
	if npc ~= nil and not npc:alive() then
		return true
	end
	return false
end

function chemodan_have()
	if db.actor:object("pre_borman_chemodan") then
		return true
	end
	return false
end

function chemodan_transfer(npc,gg)
	dialogs.relocate_item_section(npc,"pre_borman_chemodan","in")
end

function borman_quest_reward(gg,npc)
	dialogs.relocate_item_section(npc,"pre_borman_chemodan","out")
	dialogs.relocate_money(npc,10000,"in")
end


function kaps_transfer_gg(gg,npc)
	dialogs.relocate_item_section(npc,"pre_polubor_kaps","in")
end

function kaps_have()
	if db.actor:object("pre_polubor_kaps_full") then
		return true
	end
	return false
end

function kaps_reward(npc,gg)
	dialogs.relocate_item_section(npc,"pre_polubor_kaps_full","out")
	dialogs.relocate_item_section(npc,"medkit_scientic","in")
	dialogs.relocate_money(npc,1500,"in")
end


function has_money_odin(first_speaker, second_speaker)
	return first_speaker:money() >= 10000
end

function has_money_odin_2(first_speaker, second_speaker)
	return first_speaker:money() < 10000
end

function has_money_return_zona(first_speaker, second_speaker)
	return first_speaker:money() >= 40000
end

function has_money_return_zona_2(first_speaker, second_speaker)
	return first_speaker:money() < 40000
end

function has_money_dva(first_speaker, second_speaker)
	return first_speaker:money() >= 20000
end

function has_money_tri(first_speaker, second_speaker)
	return first_speaker:money() >= 1000
end

function has_money_net(first_speaker, second_speaker)
	return first_speaker:money() < 1000
end

function has_money_4etyre(first_speaker, second_speaker)
	return first_speaker:money() >= 700
end

function has_money_netu(first_speaker, second_speaker)
	return first_speaker:money() < 700
end

 function relocate_money_to_major_2(first_speaker, second_speaker)
    dialogs.relocate_money(first_speaker, 20000, "out")   
end

function relocate_money_to_major(first_speaker, second_speaker)
    dialogs.relocate_money(first_speaker, 10000, "out")   
end

 function relocate_money_major_2(first_speaker, second_speaker)
    dialogs.relocate_money(first_speaker, 40000, "out")   
end

function relocate_money_major(first_speaker, second_speaker)
    dialogs.relocate_money(first_speaker, 10000, "out")   
end

function relocate_money_to_borman(first_speaker, second_speaker)
    dialogs.relocate_money(second_speaker, 300, "out")   
end


function relocate_money_to_borman_2(first_speaker, second_speaker)
    dialogs.relocate_money(second_speaker, 500, "out")   
end

function relocate_money_to_borman_3(first_speaker, second_speaker)
    dialogs.relocate_money(second_speaker, 700, "out")   
end

function relocate_money_to_borman_4(first_speaker, second_speaker)
    dialogs.relocate_money(second_speaker, 1000, "out")   
end

function relocate_money_major(gg,npc)
	dialogs.relocate_money(npc,10000,"out")
end

function relocate_money_major_2(gg,npc)
	dialogs.relocate_money(npc,40000,"out")
end

function pred_bronnik()
   if db.actor:object("specops_outfit") then
       return true
   end
   return false
end

function pred_bronnik_net()
   if db.actor:object("specops_outfit") then
       return false
   end
   return true 
end

function seriy_kaidan(npc,gg)	
	dialogs.relocate_item_section(npc,"ammo_12x70_buck","in",2)
end

function pre_disk_for_aleks_have()
	if db.actor:object("pre_aleks_disk") then
		return true
	end
	return false
end

function disk_out(gg,npc)	
	dialogs.relocate_item_section(npc,"pre_aleks_disk","out")
end

function disk_in(npc,gg)	
	dialogs.relocate_item_section(gg,"pre_aleks_disk","in")
end

function aleks_quest_2(gg, npc)
	dialogs.relocate_item_section(npc,"medkit","in",2)
	dialogs.relocate_item_section(npc,"bandage","in",5)
	dialogs.relocate_item_section(npc,"ammo_12x70_buck","in",3)	dialogs.relocate_item_section(npc,"grenade_f1","in",2)
	dialogs.relocate_item_section(npc,"antirad","in",3)	
	dialogs.relocate_item_section(npc,"conserva","in",2)	
end	

function aver_joker_quest_end(gg, npc)
	dialogs.relocate_item_section(npc,"af_4","out")
end

function tushkano()	
	amk.spawn_item("tushkano_normal",vector():set(-269.796,11.013,219.247), 524434, 3930, 15)
end

function snork()	
	amk.spawn_item("snork_normal",vector():set(-269.796,11.013,219.247), 524434, 3930, 7)
end	
