function run_scripts_npc(binder)
	--if imm.start_game then
		npc_update(binder) 
	--end
end
function run_scripts_actor(binder)
	--if imm.start_game then
		change_outfit()
		change_helmet()
		imm.convert_npcs()
	--end
end

local excluded_npcs={
"zat_a2_stalker_nimble", -- Шустрый
"mechanic",
"trader",
"medic",
"barmen",
"guide",
"zat_b7_bandit_boss_sultan",
"zat_b106_stalker_crab", -- раненый в Скадовске
"tech",
"jup_b10_stalker_drunk",
"leader",
"jup_b220_trapper",
"jup_b15_zulus",
"jup_b6_scientist_nuclear_physicist",
"jup_b6_scientist_biochemist",
"pri_a15_sokolov",
"pri_a17_military_colonel_kovalski",
"pri_a17_military_captain_tarasov",
"pri_a17_military_prapor_valentyr",
"pri_a17_military_sergeant_morozov",
"pri_a17_military_lieutenant_podorojniy",
"pri_a15_military_recon_leader",
"pri_a15_sokolov",
"pri_a21_chasovoi_target",
"pri_a22_military_yarmoshuk",
"pri_a22_military_skelja",
"pri_a22_military_merkulov",
"pri_a15_vano",
"pri_a15_sokolov_scene",
"pri_a15_zulus",
"pri_a15_wanderer",
"pri_a15_military_tarasov",
"pri_a22_army_signaller",
"pri_b35_merc_leader",
"pri_b305_strelok",
"pri_b305_signal_man"
}
function excluded(npc_name)
	for i=1,#excluded_npcs do
		if string.find(npc_name, excluded_npcs[i]) then
			return true
		end
	end
	return false
end
	
local armor_levels={
	novice_outfit = 0,
	bandit_outfit = 0,
	bandit_blackrain_outfit = 1,
	bandit_brownrain_outfit = 1,
	bandit_light_outfit = 2,
	cs_light_outfit = 2,
	svoboda_light_outfit = 2,
	soldier_outfit = 2,
	stalker_outfit = 3,
	dolg_outfit = 3,
	svoboda_outfit =3,
	merc_outfit = 3,
	cs_outfit = 3,
	specops_outfit = 3,
	specops_outfit_2 = 3,
	dolg_heavy_outfit = 4,
	cs_heavy_outfit = 4,
	svoboda_heavy_outfit = 4,
	monolith_outfit = 4,
	military_outfit = 4,
	scientific_outfit = 5,
	dolg_scientific_outfit = 5,
	monolith_scientific_outfit = 5,
	svoboda_scientific_outfit = 5,
	ecolog_outfit = 6,	
	neutral_assault_outfit = 7,
	monolith_assault_outfit = 7,
	monolith_exo_outfit = 8,
	merc_exo_outfit = 8,
	dolg_exo_outfit = 8,
	svoboda_exo_outfit = 8,	
	exo_outfit = 8 
}

local suits_to_visuals = {
	stalker={
		novice_outfit = {
			[[stalker_neutral\stalker_neutral_1]]
		},
		bandit_outfit = {
			[[stalker_bandit\stalker_bandit_1]]
		},
		bandit_brownrain_outfit = {
			[[stalker_bandit\stalker_bandit_3]]
		},
		bandit_blackrain_outfit = {
			[[stalker_bandit\stalker_bandit_4]]
		},
		bandit_light_outfit = {
			[[stalker_bandit\stalker_bandit_2]]
		},
		cs_light_outfit = {
			[[stalker_nebo\stalker_nebo_1]]
		},
		svoboda_light_outfit = {
			[[stalker_freedom\stalker_freedom_1]]
		},
		soldier_outfit = {
			[[stalker_soldier\stalker_soldier_2_face_1_mask]]
		},
		stalker_outfit = {
			[[stalker_neutral\stalker_neutral_2_mask]]
		},
		dolg_outfit = {
			[[stalker_dolg\stalker_dolg_2_mask]]
		},
		svoboda_outfit = {
			[[stalker_freedom\stalker_freedom_2_mask]]
		},
		merc_outfit = {
			[[stalker_merc\stalker_merc_2_mask]]
		},
		cs_outfit = {
			[[stalker_nebo\stalker_nebo_3]]
		},
		monolith_outfit = {
			[[stalker_monolith\stalker_monolith_2]]
		},
		specops_outfit = {
			[[stalker_soldier\stalker_soldier_3]]
		},
		specops_outfit_2 = {
			[[stalker_soldier\stalker_soldier_2]]
		},
		cs_heavy_outfit = {
			[[stalker_nebo\stalker_nebo_2]]
		},
		svoboda_heavy_outfit = {
			[[stalker_freedom\stalker_freedom_3]]
		},
		dolg_heavy_outfit = {
			[[stalker_dolg\stalker_dolg_3]]
		},
		military_outfit = {
			[[stalker_soldier\stalker_soldier_4]]
		},
		scientific_outfit = {
			[[stalker_neutral\stalker_neutral_nauchniy]]
		},
		dolg_scientific_outfit = {
			[[stalker_dolg\stalker_dolg_1]]
		},
		monolith_scientific_outfit = {
			[[stalker_monolith\stalker_monolith_1]]
		},
		svoboda_scientific_outfit = {
			[[stalker_freedom\stalker_freedom_5]]
		},
		ecolog_outfit = {
			[[stalker_soldier\stalker_ecolog_military]]
		},
		monolith_assault_outfit = {
			[[stalker_monolith\stalker_monolith_3]]
		},
		neutral_assault_outfit = {
			[[stalker_neutral\stalker_neutral_3]]
		},
		monolith_exo_outfit = {
			[[stalker_monolith\stalker_monolith_4]]
		},
		merc_exo_outfit = {
			[[stalker_merc\stalker_merc_4]]
		},
		dolg_exo_outfit = {
			[[stalker_dolg\stalker_dolg_4]]
		},
		svoboda_exo_outfit = {
			[[stalker_freedom\stalker_freedom_4]]
		},
		exo_outfit = {
			[[stalker_neutral\stalker_neutral_4]]
		}
	},
	monolith={
		novice_outfit = {

		},
		bandit_outfit = {

		},
		bandit_brownrain_outfit = {

		},
		bandit_blackrain_outfit = {

		},
		bandit_light_outfit = {

		},
		cs_light_outfit = {

		},
		svoboda_light_outfit = {

		},
		soldier_outfit = {

		},
		stalker_outfit = {

		},
		dolg_outfit = {

		},
		svoboda_outfit = {

		},
		merc_outfit = {

		},
		cs_outfit = {

		},
		monolith_outfit = {
			[[stalker_monolith\stalker_monolith_2]]
		},
		specops_outfit = {

		},
		cs_heavy_outfit = {

		},
		svoboda_heavy_outfit = {

		},
		dolg_heavy_outfit = {

		},
		military_outfit = {

		},
		scientific_outfit = {

		},
		dolg_scientific_outfit = {

		},
		monolith_scientific_outfit = {
			[[stalker_monolith\stalker_monolith_1]]
		},
		svoboda_scientific_outfit = {

		},
		monolith_assault_outfit = {
			[[stalker_monolith\stalker_monolith_3]]
		},
		neutral_assault_outfit = {

		},
		monolith_exo_outfit = {
			[[stalker_monolith\stalker_monolith_4]]
		},
		merc_exo_outfit = {

		},
		dolg_exo_outfit = {

		},
		svoboda_exo_outfit = {

		},
		exo_outfit = {

		}
	},
	killer={
		novice_outfit = {
			[[stalker_neutral\stalker_neutral_1]]
		},
		bandit_outfit = {
			[[stalker_bandit\stalker_bandit_1]]
		},
		bandit_brownrain_outfit = {
			[[stalker_bandit\stalker_bandit_3]]
		},
		bandit_blackrain_outfit = {
			[[stalker_bandit\stalker_bandit_4]]
		},
		bandit_light_outfit = {
			[[stalker_bandit\stalker_bandit_2]]
		},
		cs_light_outfit = {
			[[stalker_nebo\stalker_nebo_1]]
		},
		svoboda_light_outfit = {
			[[stalker_freedom\stalker_freedom_1]]
		},
		soldier_outfit = {
			[[stalker_soldier\stalker_soldier_2_face_1_mask]]
		},
		stalker_outfit = {
			[[stalker_neutral\stalker_neutral_2_mask]]
		},
		dolg_outfit = {
			[[stalker_dolg\stalker_dolg_2_mask]]
		},
		svoboda_outfit = {
			[[stalker_freedom\stalker_freedom_2_mask]]
		},
		merc_outfit = {
			[[stalker_merc\stalker_merc_2_mask]]
		},
		cs_outfit = {
			[[stalker_nebo\stalker_nebo_3]]
		},
		monolith_outfit = {
			[[stalker_monolith\stalker_monolith_2]]
		},
		specops_outfit = {
			[[stalker_soldier\stalker_soldier_3]]
		},
		specops_outfit_2 = {
			[[stalker_soldier\stalker_soldier_2]]
		},
		cs_heavy_outfit = {
			[[stalker_nebo\stalker_nebo_2]]
		},
		svoboda_heavy_outfit = {
			[[stalker_freedom\stalker_freedom_3]]
		},
		dolg_heavy_outfit = {
			[[stalker_dolg\stalker_dolg_3]]
		},
		military_outfit = {
			[[stalker_soldier\stalker_soldier_4]]
		},
		scientific_outfit = {
			[[stalker_neutral\stalker_neutral_nauchniy]]
		},
		dolg_scientific_outfit = {
			[[stalker_dolg\stalker_dolg_1]]
		},
		monolith_scientific_outfit = {
			[[stalker_monolith\stalker_monolith_1]]
		},
		svoboda_scientific_outfit = {
			[[stalker_freedom\stalker_freedom_5]]
		},
		ecolog_outfit = {
			[[stalker_soldier\stalker_ecolog_military]]
		},
		monolith_assault_outfit = {
			[[stalker_monolith\stalker_monolith_3]]
		},
		neutral_assault_outfit = {
			[[stalker_neutral\stalker_neutral_3]]
		},
		monolith_exo_outfit = {
			[[stalker_monolith\stalker_monolith_4]]
		},
		merc_exo_outfit = {
			[[stalker_merc\stalker_merc_4]]
		},
		dolg_exo_outfit = {
			[[stalker_dolg\stalker_dolg_4]]
		},
		svoboda_exo_outfit = {
			[[stalker_freedom\stalker_freedom_4]]
		},
		exo_outfit = {
			[[stalker_neutral\stalker_neutral_4]]
		}
	},
	ecolog={
		novice_outfit = {

		},
		bandit_outfit = {

		},
		bandit_brownrain_outfit = {

		},
		bandit_blackrain_outfit = {

		},
		bandit_light_outfit = {

		},
		cs_light_outfit = {

		},
		svoboda_light_outfit = {

		},
		soldier_outfit = {

		},
		stalker_outfit = {

		},
		dolg_outfit = {

		},
		svoboda_outfit = {

		},
		merc_outfit = {

		},
		cs_outfit = {

		},
		monolith_outfit = {

		},
		specops_outfit = {

		},
		cs_heavy_outfit = {

		},
		svoboda_heavy_outfit = {

		},
		dolg_heavy_outfit = {

		},
		military_outfit = {

		},
		scientific_outfit = {
			[[stalker_neutral\stalker_neutral_nauchniy]]
		},
		dolg_scientific_outfit = {
			[[stalker_dolg\stalker_dolg_1]]
		},
		monolith_scientific_outfit = {
			[[stalker_monolith\stalker_monolith_1]]
		},
		svoboda_scientific_outfit = {
			[[stalker_freedom\stalker_freedom_5]]
		},
		ecolog_outfit = {
			[[stalker_soldier\stalker_ecolog_military]]
		},
		monolith_assault_outfit = {
			[[stalker_monolith\stalker_monolith_3]]
		},
		neutral_assault_outfit = {
			[[stalker_neutral\stalker_neutral_3]]
		},
		monolith_exo_outfit = {
			[[stalker_monolith\stalker_monolith_4]]
		},
		merc_exo_outfit = {
			[[stalker_merc\stalker_merc_4]]
		},
		dolg_exo_outfit = {
			[[stalker_dolg\stalker_dolg_4]]
		},
		svoboda_exo_outfit = {
			[[stalker_freedom\stalker_freedom_4]]
		},
		exo_outfit = {
			[[stalker_neutral\stalker_neutral_4]]
		}
	},
	dolg={
		novice_outfit = {

		},
		bandit_outfit = {

		},
		bandit_brownrain_outfit = {

		},
		bandit_blackrain_outfit = {

		},
		bandit_light_outfit = {

		},
		cs_light_outfit = {

		},
		svoboda_light_outfit = {

		},
		soldier_outfit = {

		},
		stalker_outfit = {
			[[stalker_dolg\stalker_dolg_2_mask]]
		},
		dolg_outfit = {
			[[stalker_dolg\stalker_dolg_2_mask]]
		},
		svoboda_outfit = {
			[[stalker_dolg\stalker_dolg_2_mask]]
		},
		merc_outfit = {
			[[stalker_dolg\stalker_dolg_2_mask]]
		},
		cs_outfit = {

		},
		monolith_outfit = {
			[[stalker_dolg\stalker_dolg_2_mask]]
		},
		specops_outfit = {

		},
		cs_heavy_outfit = {

		},
		svoboda_heavy_outfit = {
			[[stalker_dolg\stalker_dolg_3]]
		},
		dolg_heavy_outfit = {
			[[stalker_dolg\stalker_dolg_3]]
		},
		military_outfit = {
			[[stalker_dolg\stalker_dolg_3]]
		},
		scientific_outfit = {
			[[stalker_neutral\stalker_neutral_nauchniy]]
		},
		dolg_scientific_outfit = {
			[[stalker_dolg\stalker_dolg_1]]
		},
		monolith_scientific_outfit = {
			[[stalker_monolith\stalker_monolith_1]]
		},
		svoboda_scientific_outfit = {
			[[stalker_dolg\stalker_dolg_1]]
		},
		ecolog_outfit = {
			[[stalker_soldier\stalker_ecolog_military]]
		},
		monolith_assault_outfit = {
			[[stalker_monolith\stalker_monolith_3]]
		},
		neutral_assault_outfit = {
			[[stalker_neutral\stalker_neutral_3]]
		},
		monolith_exo_outfit = {
			[[stalker_monolith\stalker_monolith_4]]
		},
		merc_exo_outfit = {
			[[stalker_merc\stalker_merc_4]]
		},
		dolg_exo_outfit = {
			[[stalker_dolg\stalker_dolg_4]]
		},
		svoboda_exo_outfit = {
			[[stalker_freedom\stalker_freedom_4]]
		},
		exo_outfit = {
			[[stalker_neutral\stalker_neutral_4]]
		}
	},
	freedom={
		novice_outfit = {

		},
		bandit_outfit = {

		},
		bandit_brownrain_outfit = {

		},
		bandit_blackrain_outfit = {

		},
		bandit_light_outfit = {

		},
		cs_light_outfit = {

		},
		svoboda_light_outfit = {

		},
		soldier_outfit = {

		},
		stalker_outfit = {
			[[stalker_freedom\stalker_freedom_2_mask]]
		},
		dolg_outfit = {
			[[stalker_freedom\stalker_freedom_2_mask]]
		},
		svoboda_outfit = {
			[[stalker_freedom\stalker_freedom_2_mask]]
		},
		merc_outfit = {
			[[stalker_freedom\stalker_freedom_2_mask]]
		},
		cs_outfit = {

		},
		monolith_outfit = {
			[[stalker_freedom\stalker_freedom_2_mask]]
		},
		specops_outfit = {

		},
		cs_heavy_outfit = {

		},
		svoboda_heavy_outfit = {
			[[stalker_freedom\stalker_freedom_3]]
		},
		dolg_heavy_outfit = {
			[[stalker_freedom\stalker_freedom_3]]
		},
		military_outfit = {
			[[stalker_freedom\stalker_freedom_3]]
		},
		scientific_outfit = {
			[[stalker_neutral\stalker_neutral_nauchniy]]
		},
		dolg_scientific_outfit = {
			[[stalker_freedom\stalker_freedom_5]]
		},
		monolith_scientific_outfit = {
			[[stalker_monolith\stalker_monolith_1]]
		},
		svoboda_scientific_outfit = {
			[[stalker_freedom\stalker_freedom_5]]
		},
		ecolog_outfit = {
			[[stalker_soldier\stalker_ecolog_military]]
		},
		monolith_assault_outfit = {
			[[stalker_monolith\stalker_monolith_3]]
		},
		neutral_assault_outfit = {
			[[stalker_neutral\stalker_neutral_3]]
		},
		monolith_exo_outfit = {
			[[stalker_monolith\stalker_monolith_4]]
		},
		merc_exo_outfit = {
			[[stalker_merc\stalker_merc_4]]
		},
		dolg_exo_outfit = {
			[[stalker_dolg\stalker_dolg_4]]
		},
		svoboda_exo_outfit = {
			[[stalker_freedom\stalker_freedom_4]]
		},
		exo_outfit = {
			[[stalker_neutral\stalker_neutral_4]]
		}
	},
	bandit={
		novice_outfit = {
			[[stalker_neutral\stalker_neutral_1]]
		},
		bandit_outfit = {
			[[stalker_bandit\stalker_bandit_1]]
		},
		bandit_brownrain_outfit = {
			[[stalker_bandit\stalker_bandit_3]]
		},
		bandit_blackrain_outfit = {
			[[stalker_bandit\stalker_bandit_4]]
		},
		bandit_light_outfit = {
			[[stalker_bandit\stalker_bandit_2]]
		},
		cs_light_outfit = {
			[[stalker_nebo\stalker_nebo_1]]
		},
		svoboda_light_outfit = {
			[[stalker_freedom\stalker_freedom_1]]
		},
		soldier_outfit = {
			[[stalker_soldier\stalker_soldier_2_face_1_mask]]
		},
		stalker_outfit = {
			[[stalker_neutral\stalker_neutral_2_mask]]
		},
		dolg_outfit = {
			[[stalker_dolg\stalker_dolg_2_mask]]
		},
		svoboda_outfit = {
			[[stalker_freedom\stalker_freedom_2_mask]]
		},
		merc_outfit = {
			[[stalker_merc\stalker_merc_2_mask]]
		},
		cs_outfit = {
			[[stalker_nebo\stalker_nebo_3]]
		},
		specops_outfit = {
			[[stalker_soldier\stalker_soldier_3]]
		},
		specops_outfit_2 = {
			[[stalker_soldier\stalker_soldier_2]]
		},
		cs_heavy_outfit = {
			[[stalker_nebo\stalker_nebo_2]]
		},
		svoboda_heavy_outfit = {
			[[stalker_freedom\stalker_freedom_3]]
		},
		dolg_heavy_outfit = {
			[[stalker_dolg\stalker_dolg_3]]
		},
		monolith_outfit = {
			[[stalker_monolith\stalker_monolith_2]]
		},
		military_outfit = {
			[[stalker_soldier\stalker_soldier_4]]
		},
		scientific_outfit = {
			[[stalker_neutral\stalker_neutral_nauchniy]]
		},
		dolg_scientific_outfit = {
			[[stalker_dolg\stalker_dolg_1]]
		},
		monolith_scientific_outfit = {
			[[stalker_monolith\stalker_monolith_1]]
		},
		svoboda_scientific_outfit = {
			[[stalker_freedom\stalker_freedom_5]]
		},
		ecolog_outfit = {
			[[stalker_soldier\stalker_ecolog_military]]
		},
		monolith_assault_outfit = {
			[[stalker_monolith\stalker_monolith_3]]
		},
		neutral_assault_outfit = {
			[[stalker_neutral\stalker_neutral_3]]
		},
		monolith_exo_outfit = {
			[[stalker_monolith\stalker_monolith_4]]
		},
		merc_exo_outfit = {
			[[stalker_merc\stalker_merc_4]]
		},
		dolg_exo_outfit = {
			[[stalker_dolg\stalker_dolg_4]]
		},
		svoboda_exo_outfit = {
			[[stalker_freedom\stalker_freedom_4]]
		},
		exo_outfit = {
			[[stalker_neutral\stalker_neutral_4]]
		}
	},
	army = {
		novice_outfit = {

		},
		bandit_outfit = {

		},
		bandit_brownrain_outfit = {

		},
		bandit_blackrain_outfit = {

		},
		bandit_light_outfit = {

		},
		cs_light_outfit = {

		},
		svoboda_light_outfit = {

		},
		soldier_outfit = {

		},
		stalker_outfit = {

		},
		dolg_outfit = {

		},
		svoboda_outfit = {

		},
		merc_outfit = {

		},
		cs_outfit = {

		},
		specops_outfit = {

		},
		cs_heavy_outfit = {

		},
		svoboda_heavy_outfit = {

		},
		dolg_heavy_outfit = {

		},
		monolith_outfit = {

		},
		military_outfit = {

		},
		scientific_outfit = {

		},
		dolg_scientific_outfit = {

		},
		monolith_scientific_outfit = {

		},
		ecolog_outfit = {
			[[stalker_soldier\stalker_ecolog_military]]
		},
		monolith_assault_outfit = {

		},
		neutral_assault_outfit = {

		},
		monolith_exo_outfit = {

		},
		merc_exo_outfit = {

		},
		dolg_exo_outfit = {

		},
		svoboda_exo_outfit = {

		},
		exo_outfit = {

		}
	}
}

armors = {}
helmets = {}

function npc_update(binder)
	local npc = binder.object
	if (binder.armor_check_update or 0)<time_global() then
		binder.armor_check_update=time_global()+1500
		--if npc:character_community()~="zombied" then
			npc:iterate_inventory(check_items,npc)
		--end
	end
end

function check_items(npc, item)
	local npc_id = npc:id()
	local snpc = alife():object(npc_id)
	if snpc then
		local money = snpc.offmoney
		if money and money ~= -1 and money ~= 0 then
			npc:give_money(money) 
			game_stats.money_quest_update(money) 
			snpc.offmoney = nil
		end
		local item_id = item:id()
		local sobj = alife():object(item_id)
		if sobj then
			local clsid = sobj:clsid()
			if clsid and (clsid==70 or clsid==69) then
				local cond = sobj.con
				if cond and cond > 0 and cond < 1 then
					item:set_condition(cond)
				end
				sobj.con = item:condition()
				sobj.pid = npc_id
					
				if npc:alive() and not xr_wounded.is_wounded(npc) and not excluded(npc:name()) and sobj.con > 0.3 then 
					local com = npc:character_community()
					if clsid==70 then
						local none = armors[npc_id] and armors[npc_id][item_id] and armors[npc_id][item_id].none
						if npc_id ~= none then
							local vis = imm.get_visual(item)
							if vis and suits_to_visuals and suits_to_visuals[com] and suits_to_visuals[com][vis] and #suits_to_visuals[com][vis]>0 and armor_levels[vis] then
								if armors[npc_id] == nil then
									armors[npc_id] = {}
								end
								if armors[npc_id][item_id] == nil then
									armors[npc_id][item_id] = {}
								end
								armors[npc_id][item_id].vis = vis
							end
						end
					else
						if helmets[npc_id] == nil then
							helmets[npc_id] = {}
						end
						if helmets[npc_id][item_id] == nil then
							helmets[npc_id][item_id] = {}
											
							armors[npc_id] = nil
						end
					end
				elseif snpc.offmoney ~= -1 then
					armors[npc_id] = nil
					helmets[npc_id] = nil
				end
			end
		end
	end
end

local change_o=0
function change_outfit()
	if change_o<time_global() then
		change_o=time_global() + 1500
		local tmparm = armors
		for npc_id,tabl_o in pairs(tmparm) do
			local snpc = alife():object(npc_id)
			local npc = level.object_by_id(npc_id)
			if snpc and npc and imm.start_game then
				local actor = db.actor
				if (imm.angle_diff(actor:direction(), actor:position():sub(npc:position()))<90 and npc:position():distance_to(actor:position()) > 2.5) or not actor:see(npc) or npc:position():distance_to(actor:position())>100 then
					local com = npc:character_community()
					if not npc:alive() then
						if snpc.offmoney == -1 then
							local t = imm.read_stalker_params(snpc)
							if t then
								if com == "bandit" then
									t.visual_name = "actors\\stalker_bandit\\stalker_bandit_k"
								elseif com == "army" or t.visual_name == "stalker_zombied_3" then 
									t.visual_name = "actors\\stalker_soldier\\stalker_soldier_k"	
								elseif com == "freedom" then 
									t.visual_name = "actors\\stalker_freedom\\stalker_freedom_k"
								elseif com == "dolg" then 
									t.visual_name = "actors\\stalker_dolg\\stalker_dolg_k"
								elseif com == "killer" then 
									t.visual_name = "actors\\stalker_merc\\stalker_merc_k"
								elseif com == "monolith" then 
									t.visual_name = "actors\\stalker_monolith\\stalker_monolith_k"
								elseif t.visual_name == "stalker_hero_novice_1" or t.visual_name == "stalker_zombied_1" or string.find(t.visual_name,"stalker_neutral_1") then 
									t.visual_name = "actors\\stalker_neutral\\stalker_novice_k"	
								else 
									t.visual_name = "actors\\stalker_neutral\\stalker_neutral_k"
								end
								imm.write_stalker_params(t,snpc,1)
							end
							snpc.offmoney = nil
							return
						end
					else
						--if not xr_wounded.is_wounded(npc) and npc:character_community()~="zombied" and not excluded(npc:name()) then
							local soutf
							local outf_id
							local vis
							local tmp
							local tmp_lev
							local tmp_id
							for k,v in pairs(tabl_o) do 
								if npc_id ~= v.none then
									outf_id = k
									vis = v.vis
									if tmp then
										tmp_lev = armor_levels[tmp]
									end
									if tmp_lev then
										local vis_lev = armor_levels[vis]
										if vis_lev then
											if vis_lev < tmp_lev then 
												outf_id = tmp_id
												vis = tmp
											end
										end
									end
									tmp_id = outf_id
									tmp = vis
								end
							end
							if outf_id then
								soutf = alife():object(outf_id)
								if soutf and vis then
									local visnew = "actors\\"..suits_to_visuals[com][vis][math.random(#suits_to_visuals[com][vis])]
												
									local tabl_h
									local shelm 
									local helm_id
									local tmpvis = imm.str_explode("\\",visnew)
									tmpvis = tmpvis[3]
									local helm_sect = drop_outfits.get_helmet_sect(tmpvis)
									if helm_sect then
										tabl_h = helmets[npc_id]
										if tabl_h then
											for k,v in pairs(tabl_h) do
												helm_id = k
												local tmp = alife():object(helm_id)
												if tmp and tmp:section_name() == helm_sect then
													shelm = tmp
													break
												end
											end
										end
									end
									if helm_sect and not shelm then
										armors[npc_id][outf_id].none = npc_id
										return
									end
									local sectcur,viscur,arm_levcur
									local viscur = imm.get_visual(npc)
									if viscur then
										sectcur = get_current_visual(viscur)
										if sectcur then
											arm_levcur = armor_levels[sectcur]
											if not arm_levcur then
												armors[npc_id][outf_id] = {}
												armors[npc_id][outf_id].none = npc_id
												break
											end
										else
											armors[npc_id][outf_id] = {}
											armors[npc_id][outf_id].none = npc_id
											break
										end
										local upgrnew_o
										local tn = imm.read_outfit_params(soutf)
										if tn then
											upgrnew_o = tn.upgrades
										end
										local arm_levnew = armor_levels[vis]
										if sectcur and arm_levnew and arm_levcur and (arm_levnew > arm_levcur or (arm_levnew >= arm_levcur and upgrnew_o and #upgrnew_o>0)) then
											local sotfcur = alife():create(sectcur, snpc.position, snpc.m_level_vertex_id, snpc.m_game_vertex_id, npc_id)
											if sotfcur then
												sotfcur.pid = npc_id
												local sotfcur_id = sotfcur.id
												if armors[npc_id][sotfcur_id] == nil then
													armors[npc_id][sotfcur_id] = {}
												end
												armors[npc_id][sotfcur_id].none = npc_id
												local upgr_o = snpc.upgo
												if upgr_o then
													local tc = imm.read_outfit_params(sotfcur)
													if tc then 
														tc.upgrades = upgr_o
														imm.write_outfit_params(tc,sotfcur)
													end
												end
												local helmcur
												local sect_h = drop_outfits.get_helmet_sect(viscur)
												if sect_h then
													helmcur = alife():create(sect_h, snpc.position, snpc.m_level_vertex_id, snpc.m_game_vertex_id, npc_id)
												end
												if helmcur then
													helmcur.pid = npc_id
													local upgr_h = snpc.upgh
													if upgr_h then
														local tc = imm.read_outfit_params(helmcur)
														if tc then 
															tc.upgrades = upgr_h
															imm.write_outfit_params(tc,helmcur)
														end
													end
												end
												local tbl = drop_outfits.count_cond(npc_id,viscur,nil)
												if tbl then
													local cond_o = tbl.cond_o
													local condold
													if cond_o then
														condold = snpc.cono
														if condold then 
															cond_o = cond_o-1+condold
															if cond_o <= 0 then
																cond_o = math.random(5,10)/100
															end
														end
														sotfcur.con = cond_o
													end							
													if helmcur then
														local cond_h = tbl.cond_h
														if cond_h then
															condold = snpc.conh
															if condold then 
																cond_h = cond_h-1+condold
																if cond_h <= 0 then
																	cond_h = math.random(5,10)/100
																end
															end
															helmcur.con = cond_h
														end
													end
												end
																											
												if arm_levnew > arm_levcur then
													snpc:set_rank(270*arm_levcur+math.random(1,50))
												end
												snpc.cono = soutf.con
												if upgrnew_o then
													snpc.upgo = upgrnew_o
												end
												for k,v in pairs(tabl_o) do
													if k ~= outf_id then
														armors[npc_id][k].none = npc_id
													end
												end
												armors[npc_id][outf_id] = nil
												local t = imm.read_stalker_params(snpc)
												if t then
													t.visual_name = visnew
													imm.write_stalker_params(t,snpc,1)
												end
												alife():release(soutf,true)	
												
												if helm_sect and tabl_h and shelm then
													if tabl_h[helm_id] then
														local upgr_h
														local th = imm.read_outfit_params(shelm)
														if th then
															upgr_h = th.upgrades
														end
														if upgr_h then
															snpc.upgh = upgr_h
														end
													end
													snpc.conh = shelm.con
													helmets[npc_id][helm_id] = nil
													alife():release(shelm,true)
												end
											end
										else
											armors[npc_id][outf_id] = {}
											armors[npc_id][outf_id].none = npc_id
										end
									end
								end
							end
						--end
					end
				end
			end
		end 
	end
end

local change_h=0
function change_helmet()
	if change_h<time_global() then
		change_h=time_global() + 1500
		local tmphelm = helmets
		for npc_id,tabl in pairs(tmphelm) do			
			local snpc = alife():object(npc_id)
			local npc = level.object_by_id(npc_id)
			if snpc and npc and imm.start_game then
				local actor = db.actor
				if (imm.angle_diff(actor:direction(), actor:position():sub(npc:position()))<90 and npc:position():distance_to(actor:position()) > 2.5) or not actor:see(npc) or npc:position():distance_to(actor:position())>100 then
					local t = imm.read_stalker_params(snpc)
					if t then
						local shelm
						local tmpvis = t.visual_name
						local tmpvis_1
						local tmpvis_2
						tmpvis = imm.str_explode("\\",tmpvis)
						tmpvis_1 = tmpvis[2]
						tmpvis = imm.str_explode(".",tmpvis[3])
						local vis = tmpvis[1]
						local helm_sect = drop_outfits.get_helmet_sect_can(vis)
						if helm_sect then
							for helm_id,tabl_h in pairs(tabl) do
								local tmp = alife():object(helm_id)
								if tmp and tmp:section_name() == helm_sect then
									shelm = tmp
									break
								end
							end
							if shelm then
								tmpvis_2 = drop_outfits.get_npc_vis(helm_sect,vis)
								if tmpvis_2 ~= vis then
									t.visual_name = "actors\\"..tmpvis_1.."\\"..tmpvis_2
									imm.write_stalker_params(t,snpc,1)
									local th = imm.read_outfit_params(shelm)
									if th then
										snpc.upgh = th.upgrades
									end
									snpc.conh = shelm.con
									alife():release(shelm,true)
									helmets[npc_id][shelm.id] = nil
									return
								end
							end
						end
					end
				end
			end
		end
	end
end

-------------

function get_condition(item_id)
	local item = level.object_by_id(item_id)
	if item then
		return item:condition()
	end
	return nil
end		

function helmet_found(npc_id, vis, sect)
	if not helmets then return nil end
	local tabl = helmets[npc_id]
	if not tabl or #tabl < 1 then return nil end
	if not sect then
		sect = drop_outfits.get_helmet_sect(vis)
	end
	if sect then
		for num,shelm in pairs(tabl) do
			if string.find(shelm:section_name(), sect) then
				return shelm
			end
		end
	end
	return nil
end

function get_current_visual(visual) 
	local vis
	if 		   string.find(visual,"stalker_bandit") 	then 
		if 	   visual == "stalker_bandit_1" 			then vis = "bandit_outfit" 
		elseif string.find(visual,"stalker_bandit_2")	then vis = "bandit_light_outfit" 
		elseif visual == "stalker_bandit_3"  			then vis = "bandit_brownrain_outfit"
		elseif string.find(visual,"stalker_bandit_3") 
			or visual == "stalker_bandit_4" 			then vis = "bandit_blackrain_outfit"
		end
							
	elseif 	   string.find(visual,"stalker_dolg") 		then
		if     string.find(visual,"stalker_dolg_1") 	then vis = "dolg_scientific_outfit"
		elseif string.find(visual,"stalker_dolg_2")  	then vis = "dolg_outfit"
		elseif string.find(visual,"stalker_dolg_3") 	then vis = "dolg_heavy_outfit"
		elseif visual == "stalker_dolg_4" 				then vis = "dolg_exo_outfit"
		end
							
	elseif 	   string.find(visual,"stalker_freedom") 	then
		if     string.find(visual,"stalker_freedom_1") 	then vis = "svoboda_light_outfit"
		elseif string.find(visual,"stalker_freedom_2") 	then vis = "svoboda_outfit"
		elseif string.find(visual,"stalker_freedom_3") 	then vis = "svoboda_heavy_outfit"
		elseif visual == "stalker_freedom_5" 			then vis = "svoboda_scientific_outfit"
		elseif visual == "stalker_freedom_4" 			then vis = "svoboda_exo_outfit"
		end

	elseif 	 string.find(visual,"stalker_hero") 			then
		if     visual == "stalker_hero_1" 
			or visual == "stalker_hero_novice_1"			then vis = "novice_outfit"
		elseif visual == "stalker_hero_stc_strelok"
			or visual == "stalker_hero_stalker_1" 			then vis = "stalker_outfit" 
		elseif visual == "stalker_hero_neutral_nauchniy"  	then vis = "scientific_outfit" 
		elseif visual == "stalker_hero_cs_heavy"  			then vis = "cs_heavy_outfit" 
		elseif visual == "stalker_hero_dolg_1"  			then vis = "dolg_outfit" 
		elseif visual == "stalker_hero_dolg_2"  			then vis = "dolg_heavy_outfit" 
		elseif visual == "stalker_hero_exo"  				then vis = "exo_outfit" 
		elseif visual == "stalker_hero_freedom_1" 			then vis = "svoboda_outfit" 
		elseif visual == "stalker_hero_freedom_2"  			then vis = "svoboda_heavy_outfit" 
		elseif visual == "stalker_hero_military"  			then vis = "military_outfit" 
		elseif visual == "stalker_hero_specops"  			then vis = "specops_outfit" 

		elseif visual == "stalker_hero_bandit"  			then vis = "bandit_outfit" 
		elseif visual == "stalker_hero_bandit_black"  		then vis = "bandit_blackrain_outfit" 
		elseif visual == "stalker_hero_bandit_brown"  		then vis = "bandit_brownrain_outfit" 
		elseif visual == "stalker_hero_freedom_3"  			then vis = "svoboda_light_outfit" 
		elseif visual == "stalker_hero_monolith"  			then vis = "monolith_outfit" 
		elseif visual == "stalker_hero_soldier"  			then vis = "soldier_outfit" 
		end

	elseif 	 string.find(visual,"stalker_merc") 		then
		if     visual == "stalker_merc_2" 				then vis = "merc_outfit"
		elseif visual == "stalker_merc_4" 				then vis = "merc_exo_outfit" 
		end
								
	elseif 	   string.find(visual,"stalker_monolith") 	then
		if     string.find(visual,"stalker_monolith_1") then vis = "monolith_scientific_outfit"
		elseif visual == "stalker_monolith_2" 			then vis = "monolith_outfit"
		elseif visual == "stalker_monolith_3" 			then vis = "monolith_assault_outfit"
		elseif visual == "stalker_monolith_4" 			then vis = "monolith_exo_outfit"
		end

	elseif 	   string.find(visual,"stalker_neutral") or string.find(visual,"mp_team") then
		if	   string.find(visual,"stalker_neutral_1") 	then vis = "novice_outfit" 
		elseif string.find(visual,"stalker_neutral_2") 	then vis = "stalker_outfit"  		
		elseif string.find(visual,"stalker_neutral_3") 	then vis = "neutral_assault_outfit"   
		elseif string.find(visual,"stalker_neutral_nauchniy") 
			or visual == "mp_team_blue_armor_sci" 		then vis = "scientific_outfit"   
		elseif visual == "stalker_neutral_4" 	 		then vis = "exo_outfit"   
		end

	elseif 	 string.find(visual,"stalker_soldier") 			then
		if     string.find(visual,"stalker_soldier_1") 		then vis = "soldier_outfit"
		elseif string.find(visual,"stalker_soldier_2") 		then vis = "specops_outfit_2" 
		elseif string.find(visual,"stalker_soldier_3") 		then vis = "specops_outfit"
		elseif visual == "stalker_soldier_4" 			 	then vis = "military_outfit" 
		elseif visual == "stalker_soldier_ecolog_face_1" 	then vis = "ecolog_outfit" 
		end
								
	elseif 	 string.find(visual,"stalker_zombied") 	then
		if     visual == "stalker_zombied_1" 		then vis = "novice_outfit"
		elseif visual == "stalker_zombied_2" 		then vis = "stalker_outfit"
		elseif visual == "stalker_zombied_3" 		then vis = "specops_outfit_2"
		elseif visual == "stalker_zombied_4" 		then vis = "exo_outfit" 
		end
		
	elseif visual == "stalker_ecolog_military" then vis = "ecolog_outfit"

	elseif 	 string.find(visual,"stalker_nebo") 			then
		if     visual == "stalker_nebo_1" 
			or string.find(visual,"stalker_nebo_2_face") 	then vis = "cs_light_outfit"
		elseif visual == "stalker_nebo_2_mask" 				then vis = "bandit_brownrain_outfit"
		elseif visual == "stalker_nebo_2" 					then vis = "cs_heavy_outfit"
		elseif visual == "stalker_nebo_3" 					then vis = "cs_outfit"
		end
								
	end
	return vis
end
