--[[-----------------------------------

ABC Mod by Speed aka Cabrobro. 
v1.1 (Inferno)

--------------------------------------]]


-- alterar random choice de portal e horror quando estiver pronto para release
-- grr tenho q alterar all.spawn de escape e colocar todos os level e vertex id corretos.
-- colocar check para wish granter baseado na distancia para mostrar os desejos.
-- corrigir horror color, parece bom = 11 horar gray 6pm gray dark 
-- horror weather usa 19 horar color
-- colocar o wather horror de 11 nos de 6-7 etc...

local isready = false
local isloaded = "false"
local hellisgoingon = "no"
local sp_mut = "yes"
function doabcevents(what)
 if what == "load" then 
	isloaded = "true" 
	 -- modifcar para 180000
	 db.lvlstartout =  time_global() + 20000 
 end
 if db.actor ~= nil and isloaded == "true" then
    if db.storage[db.actor:id()].pstor == nil then db.storage[db.actor:id()].pstor = {} end
	-- db.storage[db.actor:id()].pstor["joinoso"] = "yes" -- preciso remover
	-- db.storage[db.actor:id()].pstor["freepplay"] = "yes" -- preciso remover
	procfunctions(what)
 end

end

local freemem = 0
local spawnagain = "yes"
local countport, spawnmonsterbearact, horronearact
function procfunctions(what)
local level_name = level.name()	
local chkfreetime = time_global()
 if freemem == 0 then freemem = time_global() + 1000 end
 if chkfreetime > freemem then
 freemem = 0
   if level_name == "l12u_control_monolith" or level_name == "l11_pripyat" or level_name == "l12_stancia_2" then prinmono() end
   if level_name == "l11_pripyat" or level_name == "l12_stancia" or level_name == "l12_stancia_2" then prechkprit() end
   if level_name == "l12_stancia" then chkmfp() end
   --	checkrad()
   --	dofirstrunhud()
   eatsleep()
   rpartifact()
   boltrad()
   checkskillrank()
   checkportals()
   checkblownstuffs()
   checkwishcount()
   -- testing para level e vertex id -  preciso remover abaixo
   teleportcheck()	
   -- fim	 
 end

 --	checkweapon()
 setweather(what)
 chk_anom(what)
 abc_repair.chk_repair(what) 
 if what ~= nil then 
   abc_sleep.uptabc(what) 
 else 
   abc_sleep.uptabc("abc") 
 end

end

local waitfplayer = 0
function checkblownstuffs()
local level_name = level.name()
if waitfplayer == 0 then waitfplayer = time_global() + 60000 end
   if db.donextwave == "yup" then 
	  db.storage[db.actor:id()].pstor["abcblowoutwave"] = "yes" 
	  db.storage[db.actor:id()].pstor["abcblow_count"] = 0
	  db.donextwave = "no"
   end
   local didblowh = db.storage[db.actor:id()].pstor["abcblowoutwave"]
   if didblowh == nil then didblowh = "no" end
   if (sp_mut == "yes") and (didblowh == "no") and (db.blowout_waves == "yes") and (level_name ~= "l12_stancia_2") and (level_name ~= "l12_stancia") and (level_name ~= "l12u_sarcofag") and (level_name ~= "l12u_control_monolith") and (level_name ~= "l04u_labx18") and (level_name ~= "l08u_brainlab") and (level_name ~= "l10u_bunker") and (level_name ~= "l03u_agr_underground") then
  	  startabcstuffs()
   end
   if didblowh == "yes"	then 
	 local chmblow = db.storage[db.actor:id()].pstor["abcblow_count"]
	 if chmblow == nil then chmblow = 0 end
	 db.storage[db.actor:id()].pstor["abcblow_count"] = chmblow + 1  
	 if chmblow >= (3600 * db.blow_hours) then
		db.storage[db.actor:id()].pstor["abcblowoutwave"] = "no"
		db.storage[db.actor:id()].pstor["abcblow_count"] = 0
	 end
   end

   local helltimes = db.storage[db.actor:id()].pstor["abc_hell"] 
   local hellstart = db.storage[db.actor:id()].pstor["abc_hellstart"]
   if hellstart == nil then hellstart = "no" end	 
   if helltimes == "on" then
	   if hellstart == "yes" then
	     local counthell = db.storage[db.actor:id()].pstor["abchell_count"]
		 if counthell == nil then counthell = 0 end
		 db.storage[db.actor:id()].pstor["abchell_count"] = counthell + 1 
		 if counthell >= (3600 * db.hell_hours) then
			db.storage[db.actor:id()].pstor["abc_hellstart"] = "no"
			db.storage[db.actor:id()].pstor["abchell_count"] = 0
		 end
	   end
	   if hellstart == "no" and (level_name ~= "l05_bar") and (level_name ~= "l12_stancia_2") and (level_name ~= "l12_stancia") and (level_name ~= "l12u_sarcofag") and (level_name ~= "l12u_control_monolith") and (level_name ~= "l04u_labx18") and (level_name ~= "l08u_brainlab") and (level_name ~= "l10u_bunker") and (level_name ~= "l03u_agr_underground") then
			abchell("helltime")
	   end
   end

   local mutstart = db.storage[db.actor:id()].pstor["abc_mutstart"]
   if mutstart == nil then mutstart = "no" end
   if mutstart == "yes" then
     local countmut = db.storage[db.actor:id()].pstor["abcmut_count"]     	
	 if countmut == nil then countmut = 0 end
	 db.storage[db.actor:id()].pstor["abcmut_count"] = countmut + 1 
	   if countmut >= (3600 * db.mut_hours) then
		 db.storage[db.actor:id()].pstor["abc_mutstart"] = "no"
		 db.storage[db.actor:id()].pstor["abcmut_count"] = 0
	   end
   end  	
   if (sp_mut == "yes") and (mutstart == "no") and (level_name ~= "l12u_sarcofag") and (level_name ~= "l12u_control_monolith") and (level_name ~= "l04u_labx18") and (level_name ~= "l08u_brainlab") and (level_name ~= "l10u_bunker") and (level_name ~= "l03u_agr_underground") then
		saesansaesb()
   end

   local horstart = db.storage[db.actor:id()].pstor["abc_horstart"]
   if horstart == nil then horstart = "no" end
   if horstart == "yes" then
     local counthor = db.storage[db.actor:id()].pstor["abchor_count"]     	
	 if counthor == nil then counthor = 0 end
	 db.storage[db.actor:id()].pstor["abchor_count"] = counthor + 1 
	   if counthor >= 1000 then
		 db.storage[db.actor:id()].pstor["abc_horstart"] = "no"
		 db.storage[db.actor:id()].pstor["abchor_count"] = 0
	   end
   end  	
   if (horstart == "no") and (sp_mut == "yes") then horrortime() end

   if spawnagain == "no" then
	 countport = countport + 1 
	 if countport > 120 then
		spawnagain = "yes" 
		countport = 0
	 end
   end
   if spawnmonsterbearact == "yes" then abchell_time() end
   if horronearact == "yes" then abchorror_time() end
   if level_name == "l01_escape" then van_events("blood_esc") end
   if level_name == "l03u_agr_underground" then van_events("blood_agro") end
   if level_name == "l05_bar" then van_events("bar") end
   if level_name == "l07_military" then van_events("mil") end
   -- if level_name == "l12u_sarcofag" then checkwishgranter()	end -- and db.wishnotworking == "yes"
   if not has_alife_info("encyclopedy_zone_1986") then db.actor:give_info_portion("encyclopedy_zone_1986") end
   if db.cabrobro_npc == "yes" and not not has_alife_info("cabrobro_spawn_info") then db.actor:give_info_portion("cabrobro_spawn_info") end
end


function checkwishcount()
   local des1, des2, des3, des4, des5, disable 

   -- if db.storage[db.actor:id()].pstor["abc_wishgranter"] ~= nil then
	   des1 = db.storage[db.actor:id()].pstor["abc_wishgranter_desire1"]
   	   des2 = db.storage[db.actor:id()].pstor["abc_wishgranter_desire2"]
   	   des3 = db.storage[db.actor:id()].pstor["abc_wishgranter_desire3"]
   	   des4 = db.storage[db.actor:id()].pstor["abc_wishgranter_desire4"]
   	   des5 = db.storage[db.actor:id()].pstor["abc_wishgranter_desire5"]
   	   disable = db.storage[db.actor:id()].pstor["abc_wishgranter_disable"]
   -- end	

    if disable == "yes" then
		local countdis = db.storage[db.actor:id()].pstor["abc_wishgranter_dis_count"]
		if countdis == nil then countdis = 0 end
		logf("countdis = " .. countdis)
 		db.storage[db.actor:id()].pstor["abc_wishgranter_dis_count"] = countdis + 1
		if db.storage[db.actor:id()].pstor["abc_wishgranter_dis_count"] > 10 then -- alterar para 3600
			db.storage[db.actor:id()].pstor["abc_wishgranter_disable"] = "no"
			db.storage[db.actor:id()].pstor["abc_wishgranter_dis_count"] = 0
		end 
   end

   if des1 == "yes" then
 		db.storage[db.actor:id()].pstor["abc_wishgranter_des1_count"] =	db.storage[db.actor:id()].pstor["abc_wishgranter_des1_count"] + 1
		if db.storage[db.actor:id()].pstor["abc_wishgranter_des1_count"] > 3600 then
			db.storage[db.actor:id()].pstor["abc_wishgranter_desire1"] = "no"
			db.storage[db.actor:id()].pstor["abc_wishgranter_des1_count"] = 0
		end 
   end
   if des2 == "yes" then
 		db.storage[db.actor:id()].pstor["abc_wishgranter_des2_count"] =	db.storage[db.actor:id()].pstor["abc_wishgranter_des2_count"] + 1
		if db.storage[db.actor:id()].pstor["abc_wishgranter_des2_count"] > (3600 * 5) then
			db.storage[db.actor:id()].pstor["abc_wishgranter_desire2"] = "no"
			db.storage[db.actor:id()].pstor["abc_wishgranter_des2_count"] = 0
		end 
   end
   if des3 == "yes" then
 		db.storage[db.actor:id()].pstor["abc_wishgranter_des3_count"] =	db.storage[db.actor:id()].pstor["abc_wishgranter_des3_count"] + 1
		if db.storage[db.actor:id()].pstor["abc_wishgranter_des3_count"] > 3600 then
			db.storage[db.actor:id()].pstor["abc_wishgranter_desire3"] = "no"
			db.storage[db.actor:id()].pstor["abc_wishgranter_des3_count"] = 0
		end 
   end
   if des4 == "yes" then
 		db.storage[db.actor:id()].pstor["abc_wishgranter_des4_count"] =	db.storage[db.actor:id()].pstor["abc_wishgranter_des4_count"] + 1
		if db.storage[db.actor:id()].pstor["abc_wishgranter_des4_count"] > 3600 then
			db.storage[db.actor:id()].pstor["abc_wishgranter_desire4"] = "no"
			db.storage[db.actor:id()].pstor["abc_wishgranter_des4_count"] = 0
		end 
   end
   if des5 == "yes" then
 		db.storage[db.actor:id()].pstor["abc_wishgranter_des5_count"] =	db.storage[db.actor:id()].pstor["abc_wishgranter_des5_count"] + 1
		if db.storage[db.actor:id()].pstor["abc_wishgranter_des5_count"] > 3600 then
			db.storage[db.actor:id()].pstor["abc_wishgranter_desire5"] = "no"
			db.storage[db.actor:id()].pstor["abc_wishgranter_des5_count"] = 0
		end 
   end
end

local tradetime = 0
local dofirstjump = "yes"
function prinmono()
local chktrdtime = time_global()
if tradetime == 0 then tradetime = time_global() + 10000 end
	  local abcjoinoso = db.storage[db.actor:id()].pstor["joinoso"]    
	  local mlvp = vector():set( 29.97, 0.94, 253.26 )
	  local mlvpb = vector():set( 29.32, 3.14, 427.00 )
	  local mlvpc = vector():set( -7.12, 3.14, 423.00 )
	  local mlvpd = vector():set( 70.42, 3.14, 422.00 )
	  local osodoor = vector():set( 17.83, -42.10, 34.80 )
		if db.actor ~= nil then
	     local playhitempri = db.actor:object("h_1")
		 local chkfp = db.storage[db.actor:id()].pstor["freepplay"]
		 if chkfp ~= nil then db.declinedotele = "yup" end 
		 local level_name = level.name()	
	    	if level_name == "l11_pripyat" and db.mlvp_position == "nope" and playhitempri == nil then
			   if (mlvp:distance_to_sqr(db.actor:position()) <= 400) or (mlvpb:distance_to_sqr(db.actor:position()) <= 300) or (mlvpc:distance_to_sqr(db.actor:position()) <= 300) or (mlvpd:distance_to_sqr(db.actor:position()) <= 300) then
				  alife():create("h_1", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
				  -- logf("h_1 to player!")			  
				  get_console():execute("save abcmod_auto_save")
				  db.mlvp_position = "yup"
				  db.nearz = yup
			   end
		    end
			if level_name == "l12u_control_monolith" and db.declinedotele == "yup" and (osodoor:distance_to_sqr(db.actor:position()) <= 3) then
				-- logf("teleport to next level!")
				db.actor:disable_info_portion("autojump_enabled")
				local point = patrol("mon_jump_aes2_walk")
				local look = patrol("mon_jump_aes2_look")
				db.actor:set_actor_position(point:point(0))
				local dir = look:point(0):sub(point:point(0))
				db.actor:set_actor_direction(-dir:getH())
			end
			if level_name == "l12_stancia_2" and abcjoinoso ~= nil and dofirstjump == "yes" then
				dofirstjump = "again"
			   local trader_v = vector() 
			   trader_v.x = -246.81 
			   trader_v.y = -17.22
			   trader_v.z = -134.12
			   trader_v = vector():set(567.439025878906,18.2054023742676,280.095275878906)
									   
			   db.actor:set_actor_position(trader_v)
			   logf("do teleport to trader")
			end
			if level_name == "l12_stancia_2" and abcjoinoso ~= nil and dofirstjump == "again" and chktrdtime > tradetime then
				dofirstjump = "nope"
				db.storage[db.actor:id()].pstor["joinoso"] = nil
			    local trader_v = vector() 
			    trader_v.x = 555 
			    trader_v.y = 150
			    trader_v.z = 201 -- quando alterar spawn modificar para 250
			    -- db.actor:set_actor_position(trader_v)
				logf("do teleport to levelchanger")
			end
			
	   end
end
	
function chkmfp()
local level_name = level.name()
if level_name == "l12_stancia" then
	if not has_alife_info("pri_monolith_decoder_got") then
	   db.actor:give_info_portion("pri_monolith_decoder_got")
	 -- logf("pri_monolith_decoder_got")
	end
    if not has_alife_info("pri_decoder_docs_conclusion_info") then
		db.actor:give_info_portion("pri_decoder_docs_conclusion_info")
	  -- logf("pri_decoder_docs_conclusion_info")
	 end	
	local playdecoder = db.actor:object("decoder") 
	if playdecoder == nil then
       alife():create("decoder", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
	 -- logf("decoder to player!")
	end
    local playdoc = db.actor:object("pri_decoder_documents") 
	if playdoc == nil then
       alife():create("pri_decoder_documents", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
	  -- logf("documents to player!")
	end 
return true
end

end	


function prechkprit()
local whatlevel = level.name()
if db.nearz == "nope" and whatlevel == "l11_pripyat" and db.actor ~= nil then
 chkprit()
elseif db.nearz == "nope" and whatlevel == "l12_stancia" and db.actor ~= nil then
 chkprit()
elseif db.nearz == "nope" and whatlevel == "l12_stancia_2" and db.actor ~= nil then
 chkprit()
end
end

function chkprit()
-- db.nearz = "yup"
local level_name = level.name()
local playhitem = db.actor:object("h_1")
local playhitemb = db.actor:object("h_2")
local playdecoder = db.actor:object("decoder") 
local abcfreep = db.storage[db.actor:id()].pstor["freepset"]

if abcfreep ~= nil then 
	logf("abcfreep = freepset is not nil") 
	logf("db.nearz = " .. db.nearz)
end

if db.nearz == "nope" then
    -- local abcfreep = db.storage[db.actor:id()].pstor["freepset"]
    local abcfreepplay = db.storage[db.actor:id()].pstor["freepplay"]
	-- testing abaixo preciso remover
	alife():create("h_1", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())

	if level_name == "l11_pripyat" then 
      if playhitem ~= nil or abcfreep == "yes" then
		local mhitem = db.actor:object("h_1")
	    if playhitem ~= nil then
	       db.actor:drop_item(mhitem)
		   alife():release(alife():object(mhitem:id()), true)
        end
	   db.mlvp_position = "nope"
	   db.nearz = "yup"
	   db.storage[db.actor:id()].pstor["freepset"] = nil
       logf("yup do effect stuffs")
	   alife():create("h_2", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
	   local mdeadtruck = vector() 
	   mdeadtruck.x = 30.77 
	   mdeadtruck.y = 0.51
	   mdeadtruck.z = 74.11
	   db.actor:set_actor_position(mdeadtruck)
	   level.disable_input()
       local randomdream = math.random(1,3)
	   if randomdream == 1 then game.start_tutorial("mov_abc_1") end
	   if randomdream == 2 then game.start_tutorial("mov_abc_2") end
	   if randomdream == 3 then game.start_tutorial("mov_abc_3") end
      end

	elseif level_name == "l12_stancia" and (playhitemb ~= nil or abcfreepplay ~= nil) then
	 db.setpsyfplay = "off"
     db.nearz = "yup"
	elseif level_name == "l12_stancia_2" and (playhitemb ~= nil or abcfreepplay ~= nil) then
	 db.setpsyfplay = "off"
     db.nearz = "yup"
	elseif level_name == "l12_stancia" and (playhitemb ~= nil or abcfreepplay ~= nil) then
	 db.setpsyfplay = "on"
	end 

  end

return true
end

function stopmydream()
  level.enable_input()
  local snd_obj = xr_sound.get_safe_sound_object([[heart\2]])
  snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)
  level.add_pp_effector ("deadcity_wake.ppe", 1974, false)
end

function eatsleep()
 if db.actor ~= nil and db.eatconserva > 0 then
		db.actor:eat(db.actor:object("conserva"))
 end
end
local myrweatheris = level.get_weather()
function startabcstuffs()
	if db.actor ~= nil then
 	 local gamecurrentb = time_global()
	 local level_name = level.name()
	 local changeweat = 0
	 local yupdochange = 0
     local wavehit = hit()
	 local iswavelevel = "no"	
	 wavehit.direction = vector ():set (0, 0, 0)
	 wavehit.impulse = 0
	 wavehit.draftsman = db.actor
	 wavehit.type = hit.radiation
	 wavehit.power = 0.01
	 local hitpower = 0
	 local yupstart = "no"
	 local randomshake = 0 
	 local level_weather = myrweatheris

	if db.startabc == 0 then
	 db.startabc = 1
	 local bglt = level.get_time_hours() + 1 
	   if bglt > 0 and bglt < 6 then db.blowbytime = math.random(bglt,5) end
	   if bglt > 5 and bglt < 11 then db.blowbytime = math.random(bglt,10) end
	   if bglt > 10 and bglt < 18 then db.blowbytime = math.random(bglt,17) end
	   if bglt > 17 and bglt < 23 then db.blowbytime = math.random(bglt,22) end
	   logf("db.blowbytime = " .. db.blowbytime)
	end

	if db.blowbytime == level.get_time_hours() and db.startstime == 0 then
	   logf("db.blowbytime = " .. db.blowbytime)
		db.startstime = time_global()
		local bowtis = (db.blowstarttime * 60) * 1000
        db.startstime = db.startstime + bowtis
		-- db.startstime = db.startstime + 330000
		logf("db.blowbytime = " .. db.blowbytime .. " level.get_time_hours = " .. level.get_time_hours())
		logf(gamecurrentb .. " > " .. db.startstime)
	end

	  if (level_name ~= "l12_stancia_2") and (level_name ~= "l12_stancia") and (level_name ~= "l12u_sarcofag") and (level_name ~= "l12u_control_monolith") and (level_name ~= "l04u_labx18") and (level_name ~= "l08u_brainlab") and (level_name ~= "l10u_bunker") and (level_name ~= "l03u_agr_underground") then
	  iswavelevel = "yup"
	  end

	  if db.donextwave == "yup" and gamecurrentb > db.randomtimeout then
		db.shakethislevel = "no"
		db.shakeweather2 = "no"	
		db.blowsound = "no"
		db.randstop = "no"
		db.donextwave = "no"
    	-- logf("Next wave ready")
	  end
	
	  if db.storage[db.actor:id()].pstor["showoff"] == "no" then db.showoff = "no" end
      if (level_name == "l01_escape") and (not has_alife_info("escape_stalker_done")) and (level.get_time_hours() == 7) and (db.startstime == 0) and (db.showoff == "yes") then
		 db.startstime = time_global()
		 local bowtis = (db.blowstarttime * 60) * 1000
         db.startstime = db.startstime + 90000 -- 330000 bowtis
         -- db.startstime = db.startstime + 330000
		logf("starting count for blowout show off")
	  end
	  
	  if (gamecurrentb > db.startstime) and (db.startstime ~= 0) then yupstart = "yup" end
	  if (yupstart == "yup") and (db.shakeweather2 ~= "stop") and (iswavelevel == "yup") then

		 if db.rantimeout == 0 and db.randstop == "no" then
			 db.rantimeout = time_global() + 1000
	     elseif db.rantimeout < gamecurrentb and db.randstop == "no" then
			 db.rantimeout = 0
			 randomshake = math.random(-300,1000) 
			 db.countchance = db.countchance + 1
			 -- logf("starting random every 1 second: = " .. randomshake .. " - how many trys: " .. db.countchance)
		 end

        if (level_name == "l01_escape") and (not has_alife_info("escape_stalker_done")) and (db.showoff == "yes") then randomshake = 123 end

		if randomshake == 123 or randomshake == 621 or db.countchance == 1200 then 
	        -- logf("randomshake after if = " .. randomshake)
			yupdochange = 1 
		end

		if level_name == "l01_escape" then hitpower = 0.06 end
		if level_name == "l02_garbage" then hitpower = 0.07 end
		if level_name == "l03_agroprom" then hitpower = 0.07 end
		if level_name == "l05_bar" then hitpower = 0.08 end
		if level_name == "l06_rostok" then hitpower = 0.09 end
		if level_name == "l04_darkvalley" then hitpower = 0.09 end
		if level_name == "l08_yantar" then hitpower = 0.1 end
		if level_name == "l07_military" then hitpower = 0.1 end
		if level_name == "l10_radar" then hitpower = 0.15 end
		if level_name == "l11_pripyat" then hitpower = 0.18 end

			if yupdochange > 0 and db.shakethislevel == "no" then  

				if not has_alife_info("encyclopedy_zone_blowout_waves") then db.actor:give_info_portion("encyclopedy_zone_blowout_waves") end

		    	-- logf("randomshake = " .. randomshake .. " - how many trys: " .. db.countchance)
				db.blowisgoingon = "true"
				db.shakethislevel = "yup"
				db.randomtimeout = time_global() + 150000
				db.blowsound = "yup"
				db.randstop = "yup"
				db.countchance = 0
				db.showoff = "no"
				db.storage[db.actor:id()].pstor["showoff"] = "no"
				if db.horrortime == "yes" then db.horrortime = "stop" end

				if db.spawnblow == "yes" then 
					gospawnmutants() 
					if db.spawnmoremutants == "yes" then gospawnmutants() end
				end

				 if level.get_time_hours() > 19 or level.get_time_hours() < 5 then 
		     		level.set_weather("stancia_night")
				 else
		 		 	local randomsky = math.random(1,2) 
				 	if randomsky == 1 then 
						level.set_weather("stancia") 
					end
				 	if randomsky == 2 then 	
						level.set_weather("stancia2") 
					end	     	
			 	 end

				if db.playerinzone == "no" then
				local snd_obji = xr_sound.get_safe_sound_object([[heart\2]])
			    snd_obji:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)
				level.add_cam_effector("camera_effects\\earthquake.anm", 2014, true, "")
				end
				local snd_obj = xr_sound.get_safe_sound_object([[ambient\earthquake]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.0)

				if db.playerinzone == "no" then
				if (level_name ~= "l01_escape") and (level_name ~= "l02_garbage") and (level_name ~= "l05_bar") then genmyphatoms() end
				end

				local snd_obj = xr_sound.get_safe_sound_object([[anomaly\emi_blowout]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 4.0)	
				if db.playerinzone == "no" then
				level.add_pp_effector ("vibros.ppe", 1974, false)
				local snd_obj = xr_sound.get_safe_sound_object([[affects\hit_fist]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)
			    db.actor:hit(wavehit)
				db.actor.radiation = hitpower
				local randomfx = math.random(1,3)
				if randomfx == 1 then
				 level.add_pp_effector ("vibros_p.ppe", 1974, false) 
				 level.add_pp_effector ("dead_zone.ppe", 1976, false)
				end
				if randomfx == 2 then level.add_pp_effector ("dead_zone.ppe", 1976, false) end
				end
			
			end
			if (db.shakethislevel == "yup") and (db.blowsound == "yup") and (gamecurrentb > (db.randomtimeout - 140000)) then
				db.blowsound = "wait"
	 			local randomsky = math.random(1,3) 
				if level.get_time_hours() > 19 or level.get_time_hours() < 5 then randomsky = 4 end
				if randomsky == 1 then 	level.set_weather_fx ("sblowave_day") end
				if randomsky == 2 then 	level.set_weather_fx ("dblowave_day") end
				if randomsky == 3 then 	level.set_weather_fx ("sblowave_dark") end
				if randomsky == 4 then 	level.set_weather_fx ("sblowave_night") end
				if db.playerinzone == "no" then
		        local snd_obji = xr_sound.get_safe_sound_object([[heart\2]])
				snd_obji:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0) 
				end
			end
			if (db.shakethislevel == "yup") and (db.blowsound == "wait") and (gamecurrentb > (db.randomtimeout - 135000)) then
				db.blowsound = "next"
				local snd_obj = xr_sound.get_safe_sound_object([[anomaly\emi_blowout]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 4.0)
			end

			if db.randomtimeout > 0 then 
				changeweat = db.randomtimeout - 100000 
			end
			if db.shakeweather2 == "no" and gamecurrentb > changeweat and db.shakethislevel == "yup" then
				db.shakeweather2 = "next"

	 			local randomsky = math.random(1,3) 
				if level.get_time_hours() > 19 or level.get_time_hours() < 5 then randomsky = 4 end
				if randomsky == 1 then 	level.set_weather_fx ("sblowave_day") end
				if randomsky == 2 then 	level.set_weather_fx ("dblowave_day") end
				if randomsky == 3 then 	level.set_weather_fx ("sblowave_dark") end
				if randomsky == 4 then 	level.set_weather_fx ("sblowave_night") end


			     local randanime = math.random(1,6)
				 if randanime == 1 then db.abc_state = "sneak_run" end
				 if randanime == 2 then db.abc_state = "sneak_fire" end
				 if randanime == 3 then db.abc_state = "hide_fire" end
			 	 if randanime == 4 then db.abc_state = "raid" end
			 	 if randanime == 5 then db.abc_state = "hide_s_left" end
			 	 if randanime == 6 then db.abc_state = "hide_s_right" end
			    logf("set blowout state_name = " .. db.abc_state)

				if db.playerinzone == "no" then
		        local snd_obji = xr_sound.get_safe_sound_object([[heart\2]])
			    snd_obji:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)
				end
				local snd_obj = xr_sound.get_safe_sound_object([[ambient\earthquake]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.0)
				if db.playerinzone == "no" then
				-- level.add_cam_effector("camera_effects\\earthquake.anm", 1974, false, "")
				end
				local snd_obj = xr_sound.get_safe_sound_object([[anomaly\blowout]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 4.0)	
				if db.playerinzone == "no" then
			    level.add_pp_effector ("vibros.ppe", 1974, false)
				local snd_obj = xr_sound.get_safe_sound_object([[affects\hit_fist]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)
			    db.actor:hit(wavehit)
				db.actor.radiation = hitpower

				local randomfx = math.random(1,3)
				if randomfx == 1 then
				 level.add_pp_effector ("vibros_p.ppe", 1974, false) 
				 level.add_pp_effector ("dead_zone.ppe", 1976, false)
				end
				if randomfx == 2 then level.add_pp_effector ("dead_zone.ppe", 1976, false) end
				end
			--	db.blowisgoingon = "false"
			end

			if (db.shakethislevel == "yup") and (db.blowsound == "next") and (gamecurrentb > (db.randomtimeout - 90000)) then
				db.blowsound = "nextb"
				local snd_obj = xr_sound.get_safe_sound_object([[anomaly\blowout]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 4.0)
				if db.playerinzone == "no" then
		        local snd_obji = xr_sound.get_safe_sound_object([[heart\2]])
				snd_obji:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0) 	
				end
			end

			if db.randomtimeout > 0 then 
				changeweat = db.randomtimeout - 50000 
			end

			if db.shakeweather2 == "next" and gamecurrentb > changeweat and db.shakethislevel == "yup" then
				db.shakeweather2 = "yup"

	 			local randomsky = math.random(1,3) 
				if level.get_time_hours() > 19 or level.get_time_hours() < 5 then randomsky = 4 end
				if randomsky == 1 then 	level.set_weather_fx ("sblowave_day") end
				if randomsky == 2 then 	level.set_weather_fx ("dblowave_day") end
				if randomsky == 3 then 	level.set_weather_fx ("sblowave_dark") end
				if randomsky == 4 then 	level.set_weather_fx ("sblowave_night") end

			     local randanime = math.random(1,6)
				 if randanime == 1 then db.abc_state = "sneak_run" end
				 if randanime == 2 then db.abc_state = "sneak_fire" end
				 if randanime == 3 then db.abc_state = "hide_fire" end
			 	 if randanime == 4 then db.abc_state = "raid" end
			 	 if randanime == 5 then db.abc_state = "hide_s_left" end
			 	 if randanime == 6 then db.abc_state = "hide_s_right" end
			    logf("set blowout state_name = " .. db.abc_state)

				if db.playerinzone == "no" then
		        local snd_obji = xr_sound.get_safe_sound_object([[heart\2]])
			    snd_obji:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)
				end
				local snd_obj = xr_sound.get_safe_sound_object([[ambient\earthquake]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.0)
				if db.playerinzone == "no" then
				-- level.add_cam_effector("camera_effects\\earthquake.anm", 1974, false, "")

				if (level_name ~= "l01_escape") and (level_name ~= "l02_garbage") then 
					genmyphatoms()
					if (level_name ~= "l03_agroprom") and (level_name ~= "l05_bar") then
						genpsydogs()
					end
				end
				end
				local snd_obj = xr_sound.get_safe_sound_object([[anomaly\zhar_blow]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 4.0)	
				if db.playerinzone == "no" then	
			    level.add_pp_effector ("vibros.ppe", 1974, false)
				local snd_obj = xr_sound.get_safe_sound_object([[affects\hit_fist]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)
			    db.actor:hit(wavehit)
				db.actor.radiation = hitpower

	 			local randomfx = math.random(1,3)
				if randomfx == 1 then
				 level.add_pp_effector ("vibros_p.ppe", 1974, false) 
				 level.add_pp_effector ("dead_zone.ppe", 1976, false)
				end
				if randomfx == 2 then level.add_pp_effector ("dead_zone.ppe", 1976, false) end
				end

			end

			if (db.shakethislevel == "yup") and (db.blowsound == "nextb") and (gamecurrentb > (db.randomtimeout - 40000)) then
				db.blowsound = "last"
				local snd_obj = xr_sound.get_safe_sound_object([[anomaly\zhar_blow]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 4.0)	
		        local snd_obji = xr_sound.get_safe_sound_object([[heart\2]])
				snd_obji:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0) 
			end
	
			if  gamecurrentb > db.randomtimeout and db.shakethislevel == "yup" and db.shakeweather2 == "yup" then
				-- remove shake
				db.shakeweather2 = "onemore"

	 			local randomsky = math.random(1,3) 
				if level.get_time_hours() > 19 or level.get_time_hours() < 5 then randomsky = 4 end
				if randomsky == 1 then 	level.set_weather_fx ("sblowave_day") end
				if randomsky == 2 then 	level.set_weather_fx ("dblowave_day") end
				if randomsky == 3 then 	level.set_weather_fx ("sblowave_dark") end
				if randomsky == 4 then 	level.set_weather_fx ("sblowave_night") end

			     local randanime = math.random(1,6)
				 if randanime == 1 then db.abc_state = "sneak_run" end
				 if randanime == 2 then db.abc_state = "sneak_fire" end
				 if randanime == 3 then db.abc_state = "hide_fire" end
			 	 if randanime == 4 then db.abc_state = "raid" end
			 	 if randanime == 5 then db.abc_state = "hide_s_left" end
			 	 if randanime == 6 then db.abc_state = "hide_s_right" end
			    logf("set blowout state_name = " .. db.abc_state)

				if db.playerinzone == "no" then		        
				local snd_obji = xr_sound.get_safe_sound_object([[heart\2]])
			    snd_obji:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)
				end
				local snd_obj = xr_sound.get_safe_sound_object([[ambient\earthquake]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.0)
				if db.playerinzone == "no" then
				-- level.add_cam_effector("camera_effects\\earthquake.anm", 1974, false, "")
				end
				local snd_obj = xr_sound.get_safe_sound_object([[anomaly\blowout]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 4.0)	
				if db.playerinzone == "no" then
			    level.add_pp_effector ("vibros.ppe", 1974, false)     		
				local snd_obj = xr_sound.get_safe_sound_object([[affects\hit_fist]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)
			    db.actor:hit(wavehit)
				db.actor.radiation = hitpower

	 			local randomfx = math.random(1,7)
				if randomfx == 1 then level.add_pp_effector ("dead_zone.ppe", 1976, false) end
				if randomfx == 2 then level.add_pp_effector ("deadcity_wake.ppe", 1976, false) end
				if randomfx == 3 then level.add_pp_effector ("deadcity_wake1.ppe", 1976, false) end
				if randomfx == 4 then level.add_pp_effector ("monolith_off.ppe", 1974, false) end
				if randomfx == 5 then level.add_pp_effector ("radar_psi.ppe", 1974, false) end
				end
			end  

			if (db.shakethislevel == "yup") and (db.blowsound == "last") and (gamecurrentb > (db.randomtimeout + 9500)) then
				db.blowsound = "end"
				local snd_obj = xr_sound.get_safe_sound_object([[anomaly\blowout]])
				snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 4.0)
				if db.playerinzone == "no" then
		        local snd_obji = xr_sound.get_safe_sound_object([[heart\2]])
			   	snd_obji:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 3.0)	
				end
			end

			if (db.shakethislevel == "yup") and (db.blowsound == "end") and (gamecurrentb > (db.randomtimeout + 15000)) then
				db.blowisgoingon = "false"
				db.blowsound = "stop"
				if db.playerinzone == "no" then
		       	level.add_pp_effector ("blink.ppe", 234, false)
				level.remove_cam_effector(2014)
				end
					if level_name == "l08_yantar" then level.set_weather("yantar") 
					elseif level_name == "l04_darkvalley" then level.set_weather("yantar")
					elseif level_name == "l10_radar" then level.set_weather("radar")
					else			
					level.set_weather(level_weather)
					end		
				sp_mut = "no"
				db.shakeweather2 = "stop"
				if db.horrortime == "stop" then db.horrortime = "yes" end
				--  for next wave 1100000 - 20 minutos + random choice
					local nextblowin = (db.blowavetime * 60) * 1000
					db.randomtimeout = time_global() + nextblowin
					if db.donextwave == "no" then 
					   db.donextwave = "yup" 
					end
			end
 	  end  
	end
end

function genmyphatoms(howmany)
	local cttt
	local phantom_max 					= 10
	local phantom_spawn_probability		= 0.6
	local phantom_spawn_radius			= 30.0
	local phantom_spawn_height			= 2.5
	local phantom_fov					= 45
	if howmany == nil then howmany = 5 end
    for cttt = 1, howmany do
	  if math.random() < phantom_spawn_probability then
			if phantom_manager:phantom_count() < phantom_max then
				local radius = phantom_spawn_radius * ( math.random()/2.0+0.5 )
				local ang    = phantom_fov * math.random() - phantom_fov * 0.5
				local dir    = vector_rotate_y( db.actor:direction(), ang )
				phantom_manager.spawn_phantom( db.actor:position():add( dir:mul(radius) ) )
			end
	  end
    end
end


function genpsydogs(w)
	local noobposition = db.actor:position()
	local xnoob = math.random(1,90)
	local znoob = math.random(1,90)
	if w == "hell" then
		xnoob = math.random(-100,200)
		znoob = math.random(-100,200)
	end
	local nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 4, noobposition.z + znoob )
	alife():create("psy_dog", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
end

local horrorisset = "no"
local horrorstart = 0
local rmht = -1
function horrortime()
if db.actor ~= nil then
 local hth = level.get_time_hours()
 local htm = level.get_time_minutes()
 local gamecurrentg = time_global()

 if horrorstart == 0 then horrorstart = gamecurrentg + 20000 end
 if db.horrortime == "yes" and isready == false and (gamecurrentg > horrorstart) then
 -- logf("horror test 1")
  if hth < 5 and horrorisset == "no" then 
	rmht = math.random(hth,4) 
	horrorisset = "yes"
	logf("horror = " .. rmht .. " h = " .. horrorstart .. " gs = " .. gamecurrentg)
  elseif hth > 5 then
	horrorisset = "no"
  end
  if hth == rmht then 
	-- htm > 0 and htm < 5 then
	db.hortime = true
	logf("setting horror time true")
	logf("horror = " .. rmht)
	logf("horror test 2")
  else
	db.hortime = false
	isready = false
	-- logf("horror test 3")
  end
  if db.hortime == true and isready == false and level.name() ~= "l05_bar" and db.playerinzone == "no" then
    db.storage[db.actor:id()].pstor["abc_horstart"] = "yes"
	logf("starting horror")
	local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_the_horror1]])
	snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	level.add_pp_effector ("dead_zone.ppe", 1974, false)
	isready = true
	horronearact = "yes"
	genmyphatoms()
	chktime()
    if db.spawnmoremutantsh == "yes" then chktime() end
  end
 end
end
end


function gospawnmutants()
 if db.spawnblow == "yes" and db.hortime == false then
   db.hortime = false

	local level_name = level.name()
	local noobposition = db.actor:position()
	local nmpos, xnoob, znoob
	local meetplayer = false
		if level_name == "l01_escape" then
			local bloodbridge = vector():set( -15.43, 3.93, 56.08 )
			alife():create("bloodsucker_weak", bloodbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local bloodafterbridge = vector():set( -5.05, 2.17, 251.47 )
			alife():create("bloodsucker_weak", bloodafterbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			fracunderbridge = vector():set( -51.17, -8.43, -62.76 ) 
			alife():create("fracture_weak", fracunderbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkbridge = vector():set( 28.65, 2.90, 26.77 )
			alife():create("snork_weak", snorkbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkafterbridge = vector():set( -5.05, 2.17, 251.47 )
			alife():create("snork_weak", snorkafterbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkafterbridge = vector():set( -9.17, 2.17, 296.04 )
			alife():create("snork_weak", snorkafterbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkafterbridge = vector():set( 142.01, 1.75,337.88 )
			alife():create("chimera_weak", snorkafterbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local nmsp = vector():set( 10, 10, 20 )
			nmsp.x = nmsp.x + 10
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
		return true
		elseif level_name == "l02_garbage" then
			local sblood = vector():set( 261.18, -8.02, -139.98 )
			alife():create("bloodsucker_weak", sblood, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracnear = vector():set( -54.19, 1.73, -45.91 ) 
			alife():create("fracture_weak", fracnear, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracnear = vector():set( -76.42, -1.85, 199.83 ) 
			alife():create("fracture_weak", fracnear, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local burergar = vector():set( 190.48, -1.02, 8.19 )
			alife():create("burer_weak", burergar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkgar = vector():set( -54.19, 1.73, -45.91 )
			alife():create("snork_normal", snorkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal", snorkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( 81.67, 2.59, -228.35 )
			alife():create("cat_weak", catgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( -76.42, -1.85, 199.83 )
			alife():create("cat_weak", catgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( 190.48, -1.02, 8.19 )
			alife():create("cat_weak", catgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimeragar = vector():set( 81.67, 2.59, -228.35 )
			alife():create("chimera_weak", chimeragar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimeragar = vector():set( -76.42, -1.85, 199.83 )
			alife():create("chimera_weak", chimeragar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local tushkgar = vector():set( 190.48, -1.02, 8.19 )
			alife():create("tushkano_normal", tushkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
		return true
		elseif level_name == "l03_agroprom" then
			local sblood = vector():set( -94.83, 13.12, 155.43 )
			alife():create("bloodsucker_weak", sblood, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracnear = vector():set( 104.57, 3.22, -152.36 ) 
			alife():create("fracture_weak", fracnear, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracnear = vector():set( 13.19, 13.04, -101.63 ) 
			alife():create("fracture_weak", fracnear, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local bureragro = vector():set( -94.83, 13.12, 155.43 )
			alife():create("burer_weak", bureragro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkagro = vector():set( 44.38, 3.83, 94.90 )
			alife():create("snork_normal", snorkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal", snorkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catagro = vector():set( -165.71, 1.34, -35.21 )
			alife():create("cat_weak", catagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( -165.71, 1.34, -35.21 )
			alife():create("cat_weak", catagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( 13.19, 13.04, -101.63 )
			alife():create("cat_weak", catagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimeraagro = vector():set( -221.96, 7.37, 44.36 )
			alife():create("chimera_weak", chimeraagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimeragar = vector():set( -221.96, 7.37, 44.36 )
			alife():create("chimera_weak", chimeraagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local tushkagro = vector():set( -94.83, 13.12, 155.43 )
			alife():create("tushkano_normal", tushkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
		return true
		elseif level_name == "l05_bar" then
			local chimerabar = vector():set( 277.65, 2.05, -89.09 )
			alife():create("chimera_weak", chimerabar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracnear = vector():set( 191.49, 5.20, -141.46 ) 
			alife():create("fracture_weak", fracnear, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local burerbar = vector():set( 55.54, 1.30, 220.85 )
			alife():create("burer_weak", burerbar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkbar = vector():set( 142.94, 8.29, 94.65 )
			alife():create("snork_weak", snorkbar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local tushkbar = vector():set( 277.65, 2.05, -89.09 )
			alife():create("snork_normal", tushkbar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkbar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkbar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkbar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
		return true
		elseif level_name == "l06_rostok" then
			local chimeraros = vector():set( -55.51, -13.99, -178.57 )
			alife():create("snork_weak", chimeraros, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak", chimeraros, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", chimeraros, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
		return true
		elseif level_name == "l04_darkvalley" then
			local catvall = vector():set( -53.12, -0.29, -132.12 )
			alife():create("cat_weak", catvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", catvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local bloodnbuervall = vector():set( -53.12, -0.29, -132.12 )
			alife():create("bloodsucker_weak", bloodnbuervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("burer_weak", bloodnbuervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local bloodnbuervall = vector():set( -39.06, 1.67, 16.83 )
			alife():create("bloodsucker_weak", bloodnbuervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal", bloodnbuervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracvall = vector():set( -97.80, -0.45, -5.99 )
			alife():create("fracture_weak", fracvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal", fracvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimvall = vector():set( 112.56, 0.97, 72.27 )
			alife():create("chimera_weak", chimvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", chimvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", chimvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("gigant_strong", chimvall, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("snork_normal", chimvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local buervall = vector():set( 112.56, 0.97, 72.27 )
			alife():create("burer_weak", buervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracvall = vector():set( -147.53, 0.31, -329.44 )
			alife():create("fracture_weak", fracvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", fracvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkvall = vector():set( 45.45, 1.68, -224.66 )
			alife():create("snork_normal", snorkvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkvall = vector():set( 102.65, 1.62, -66.59 )
			alife():create("snork_normal", snorkvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local nmsp = vector():set( 112.56, 0.97, 72.27 )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
		return true	 
		elseif level_name == "l04u_labx18" then
			xnoob = math.random(-200,200)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("bloodsucker_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
		return true
		elseif level_name == "l07_military" then
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("bloodsucker_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
		return true	 
		elseif level_name == "l08_yantar)" then
			local syantb = vector():set( 93.84, 2.94, -133.47 )
			alife():create("bloodsucker_normal", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("burer_weak", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("fracture_weak", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_hell", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_ghost", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true	 
		elseif level_name == "l11_pripyat" then
			local chimerapri = vector():set( -15.07, -0.41, 34.17 )
			alife():create("chimera_weak", chimerapri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", chimerapri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local burerpri = vector():set( 156.33, -0.79, 5.64 )
			alife():create("burer_weak", burerpri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catpri = vector():set( 70.27, -0.64, -23.60 )
			alife():create("cat_weak", catpri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", catpri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			nmpos = vector():set( 56.97, 0.79, -118.73 )
			alife():create("fracture_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("fracture_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			nmpos = vector():set( 124.79, -0.83, -51.74 )
			alife():create("bloodsucker_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			nmpos = vector():set( -67.11, -0.15, 41.19 )
			alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			nmpos = vector():set( 3.96, -0.90, -10.96 )
			alife():create("snork_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local nmsp = vector():set( -102.09, 1.80, 12.16 )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local nmsp = vector():set( -15.07, -0.41, 34.17 )			
			alife():create("gigant_strong", nmsp, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_hell", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_ghost", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true
		elseif level_name == "l12_stancia" and db.setpsyfplay == "off" then
			genpsydogs()
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("bloodsucker_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("gigant_strong", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("tushkano_normal", nmspos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmspos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmspos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmspos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_hell", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_ghost", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true
		elseif level_name == "l12_stancia_2" and db.setpsyfplay == "off" then
			genpsydogs()
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("bloodsucker_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			-- alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("gigant_strong", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_hell", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_ghost", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true
		end

 end
end


function chktime()
local level_name = level.name()
local noobposition = db.actor:position()
local nmpos, xnoob, znoob
		if level_name == "l01_escape" then
			-- alterei
			local bloodbridge = vector():set( -15.43, 3.93, 56.08 )
			alife():create("bloodsucker_weak", bloodbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local bloodafterbridge = vector():set( -5.05, 2.17, 251.47 )
			alife():create("bloodsucker_weak", bloodafterbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			fracunderbridge = vector():set( -51.17, -8.43, -62.76 ) 
			alife():create("fracture_weak", fracunderbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("fracture_weak", fracunderbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkbridge = vector():set( 28.65, 2.90, 26.77 )
			alife():create("snork_weak", snorkbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkafterbridge = vector():set( -5.05, 2.17, 251.47 )
			alife():create("snork_weak", snorkafterbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkafterbridge = vector():set( -9.17, 2.17, 296.04 )
			alife():create("snork_weak", snorkafterbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkafterbridge = vector():set( 142.01, 1.75,337.88 )
			alife():create("snork_weak", snorkafterbridge, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local nmsp = vector():set( noobposition.x + 20, noobposition.y, noobposition.z + 20 )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			return true	
		elseif level_name == "l02_garbage" then
			local sblood = vector():set( 261.18, -8.02, -139.98 )
			alife():create("bloodsucker_weak", sblood, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracnear = vector():set( -54.19, 1.73, -45.91 ) 
			alife():create("fracture_weak", fracnear, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracnear = vector():set( -76.42, -1.85, 199.83 ) 
			alife():create("fracture_weak", fracnear, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local burergar = vector():set( 190.48, -1.02, 8.19 )
			alife():create("burer_weak", burergar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkgar = vector():set( -54.19, 1.73, -45.91 )
			alife():create("snork_normal", snorkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal", snorkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( 81.67, 2.59, -228.35 )
			alife():create("cat_weak", catgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( -76.42, -1.85, 199.83 )
			alife():create("cat_weak", catgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( 190.48, -1.02, 8.19 )
			alife():create("cat_weak", catgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimeragar = vector():set( 81.67, 2.59, -228.35 )
			alife():create("chimera_weak", chimeragar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimeragar = vector():set( -76.42, -1.85, 199.83 )
			alife():create("chimera_weak", chimeragar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local tushkgar = vector():set( noobposition.x + 20, noobposition.y, noobposition.z + 20 )
			alife():create("tushkano_normal", tushkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkgar, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true	
		elseif level_name == "l03_agroprom" then
			local sblood = vector():set( -94.83, 13.12, 155.43 )
			alife():create("bloodsucker_weak", sblood, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracnear = vector():set( 104.57, 3.22, -152.36 ) 
			alife():create("fracture_weak", fracnear, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracnear = vector():set( 13.19, 13.04, -101.63 ) 
			alife():create("fracture_weak", fracnear, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local bureragro = vector():set( -94.83, 13.12, 155.43 )
			alife():create("burer_weak", bureragro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkagro = vector():set( 44.38, 3.83, 94.90 )
			alife():create("snork_normal", snorkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal", snorkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catagro = vector():set( -165.71, 1.34, -35.21 )
			alife():create("cat_weak", catagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( -165.71, 1.34, -35.21 )
			alife():create("cat_weak", catagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catgar = vector():set( 13.19, 13.04, -101.63 )
			alife():create("cat_weak", catagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimeraagro = vector():set( -221.96, 7.37, 44.36 )
			alife():create("chimera_weak", chimeraagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimeragar = vector():set( -221.96, 7.37, 44.36 )
			alife():create("chimera_weak", chimeraagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local tushkagro = vector():set( noobposition.x + 20, noobposition.y, noobposition.z + 20 )
			alife():create("tushkano_normal", tushkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", tushkagro, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true
		elseif level_name == "l06_rostok" then
			local chimeraros = vector():set( -55.51, -13.99, -178.57 )
			alife():create("snork_weak", chimeraros, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak", chimeraros, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", chimeraros, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true
		elseif level_name == "l04_darkvalley" then
			local catvall = vector():set( -53.12, -0.29, -132.12 )
			alife():create("cat_weak", catvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", catvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local bloodnbuervall = vector():set( -53.12, -0.29, -132.12 )
			alife():create("bloodsucker_weak", bloodnbuervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("burer_weak", bloodnbuervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local bloodnbuervall = vector():set( -39.06, 1.67, 16.83 )
			alife():create("bloodsucker_weak", bloodnbuervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal", bloodnbuervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracvall = vector():set( -97.80, -0.45, -5.99 )
			alife():create("fracture_weak", fracvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal", fracvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local chimvall = vector():set( 112.56, 0.97, 72.27 )
			alife():create("chimera_weak", chimvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", chimvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", chimvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("gigant_strong", chimvall, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("snork_normal", chimvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			-- local buervall = vector():set( 112.56, 0.97, 72.27 )
			-- alife():create("burer_weak", buervall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local fracvall = vector():set( -147.53, 0.31, -329.44 )
			alife():create("fracture_weak", fracvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", fracvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkvall = vector():set( 45.45, 1.68, -224.66 )
			alife():create("snork_normal", snorkvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local snorkvall = vector():set( 102.65, 1.62, -66.59 )
			alife():create("snork_normal", snorkvall, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local nmsp = vector():set( noobposition.x + 20, noobposition.y, noobposition.z + 20 )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_hell", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true	 
		elseif level_name == "l04u_LabX18" then
			xnoob = math.random(-200,200)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("bloodsucker_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,100)
			znoob = math.random(-200,200)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y, noobposition.z + znoob )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			-- alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_hell", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true
		elseif level_name == "l07_military" then
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("bloodsucker_normal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 12, noobposition.z + znoob )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-200,600)
			znoob = math.random(-200,600)
			nmpos = vector():set( noobposition.x + 20, noobposition.y, noobposition.z + 20 )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("zombie_immortal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
		return true
		elseif level_name == "l08_yantar)" then
			local syantb = vector():set( 93.84, 2.94, -133.47 )
			alife():create("bloodsucker_hell", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("burer_weak", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("fracture_weak", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", syantb, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_hell", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_ghost", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true	 	 
		elseif level_name == "l11_pripyat" then
			local chimerapri = vector():set( -15.07, -0.41, 34.17 )
			alife():create("chimera_weak", chimerapri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("chimera_weak", chimerapri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local burerpri = vector():set( 156.33, -0.79, 5.64 )
			alife():create("burer_weak", burerpri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local catpri = vector():set( 70.27, -0.64, -23.60 )
			alife():create("cat_weak", catpri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("cat_weak", catpri, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			nmpos = vector():set( 56.97, 0.79, -118.73 )
			alife():create("fracture_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("fracture_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			nmpos = vector():set( 124.79, -0.83, -51.74 )
			alife():create("bloodsucker_hell",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			nmpos = vector():set( -67.11, -0.15, 41.19 )
			alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			nmpos = vector():set( noobposition.x + 20, noobposition.y, noobposition.z + 20 )
			alife():create("snork_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("snork_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local nmsp = vector():set( -102.09, 1.80, 12.16 )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			alife():create("tushkano_normal", nmsp, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
			local nmsp = vector():set( -15.07, -0.41, 34.17 )			
			alife():create("gigant_strong", nmsp, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			xnoob = math.random(-100,100)
			znoob = math.random(-100,100)
			nmpos = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
			alife():create("zombie_normal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_hell", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_ghost", nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		return true
		end
end

function saesansaesb()
if db.actor ~= nil then
local gamecurrentb = time_global()
local yupdochange = 0
local randomshake = 0
local yupstart = "no"
 if db.startstimeh == 0 then
  db.startstimeh = time_global()
  -- db.lvlstartouth =  db.lvlstartouth + 90000
  db.startstimeh = time_global() + 300000
 end
 local skipescape = "no"
 if level.name() == "l01_escape" and not has_alife_info("escape_lager_complete") then skipescape = "yes" end
 if db.rantimeouth == 0 and db.randstoph == "no" then
  db.rantimeouth = time_global() + 1000
 elseif db.rantimeouth < gamecurrentb and db.randstoph == "no" and skipescape == "no" then
  db.rantimeouth = 0
  randomshake = math.random(1,800) 
  -- logf("test saessansaesb random choice = " .. randomshake)	
  -- randomshake = 123
  db.countchanceh = db.countchanceh + 1
 end
	if randomshake == 123 or randomshake == 231 or randomshake == 621 or db.countchanceh == 1000 then 
	    -- logf("randomshake after if = " .. randomshake)
		yupdochange = 1 
	end
	if (gamecurrentb > db.startstimeh) then yupstart = "yup" end
	if yupdochange > 0 and db.shakeweather2h ~= "stop" and yupstart == "yup" then 
		db.storage[db.actor:id()].pstor["abc_mutstart"] = "yes" 
		db.randstoph = "yup"
		db.shakethislevelh = "yup"
		db.shakeweather2h = "stop"
		sp_mut = "no"
    	gospawnmutants()
	   if db.spawnmoremutants == "yes" then gospawnmutants() end
		-- genmyphatoms()
	end
end
end

function rpartifact()
if db.actor ~= nil then
 local active_slot = db.actor:active_slot()
 local playartsong = "no"
 local gametime = time_global()
 local act_rank = ranks.get_obj_rank_name(db.actor)
 local playrepairsoung	
  if active_slot == 1 then
    local currentactive_item = db.actor:active_item()  
    if currentactive_item ~= nil then 
	 local myitem_id = currentactive_item:id()
     local myitem_name = currentactive_item:name()
	 local myitem_clsid = get_clsid(currentactive_item)
	 local myrepair_item = db.actor:object("af_repair_battery")
      if myitem_clsid == 39 then
		 playartsong = "yup"
		 if string.find(myitem_name, "repair_battery") and myrepair_item ~= nil then
	       local item_in_slot_2 = db.actor:item_in_slot(2)
           local item_in_slot_6 = db.actor:item_in_slot(6)
           if item_in_slot_2 ~= nil and (act_rank == "novice") and item_in_slot_2:condition() <= 0.64 then 
		  	  item_in_slot_2:set_condition(0.65) 
			  playrepairsoung = "yes"
		   end
           if item_in_slot_2 ~= nil and (act_rank == "experienced") and item_in_slot_2:condition() <= 0.74 then 
		  	  item_in_slot_2:set_condition(0.75) 
			  playrepairsoung = "yes"
		   end
           if item_in_slot_2 ~= nil and (act_rank == "veteran") and item_in_slot_2:condition() <= 0.84 then 
		  	  item_in_slot_2:set_condition(0.85) 
			  playrepairsoung = "yes"
		   end
           if item_in_slot_2 ~= nil and (act_rank == "master") and item_in_slot_2:condition() <= 0.89 then 
		  	  item_in_slot_2:set_condition(0.90) 
			  playrepairsoung = "yes"
		   end
           if item_in_slot_6 ~= nil and (act_rank == "novice") and item_in_slot_6:condition() <= 0.69 then 
		      item_in_slot_6:set_condition(0.70) 
			  playrepairsoung = "yes"
		   end
           if item_in_slot_6 ~= nil and (act_rank == "experienced") and item_in_slot_6:condition() <= 0.74 then 
		      item_in_slot_6:set_condition(0.75) 
			  playrepairsoung = "yes"
		   end
           if item_in_slot_6 ~= nil and (act_rank == "veteran") and item_in_slot_6:condition() <= 0.84 then 
		      item_in_slot_6:set_condition(0.85) 
			  playrepairsoung = "yes"
		   end
           if item_in_slot_6 ~= nil and (act_rank == "master") and item_in_slot_6:condition() <= 0.89 then 
		      item_in_slot_6:set_condition(0.90) 
			  playrepairsoung = "yes"
		   end
	     end
		 if playrepairsoung == "yes" then
			local snd_obj = xr_sound.get_safe_sound_object([[anomaly\teleport_incoming]])
			snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
			db.repairtimeout = time_global() + 6000	
			playartsong = "no"
		 end
         if gametime > db.repairtimeout and playartsong == "yup" then 
		   local snd_obj = xr_sound.get_safe_sound_object([[anomaly\anomaly_gravy_blast00]])
		   snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.0)
		   db.repairtimeout = time_global() + 20000
		   local snd_obja = xr_sound.get_safe_sound_object([[ambient\random\rnd_doubler]])
		   snd_obja:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.0)
		 end
	   end
    end
  end
end
end

wishradtimeout = 0
function boltrad()
if db.actor ~= nil then
 local active_slot = db.actor:active_slot()
 local gametime = time_global()
 local bolthit = hit()
 bolthit.direction = vector ():set (0, 0, 0)
 bolthit.impulse = 0
 bolthit.draftsman = db.actor
 bolthit.type = hit.radiation
 bolthit.power = 0.009
  local wish_suit = db.actor:item_in_slot(6)
  local wish_suit_name	
  if wish_suit ~= nil then
	 wish_suit_name = wish_suit:section()
  end
  if active_slot == 1 or active_slot == 2 or wish_suit_name == "outfit_lethalspeed_exo_m1" then
    local currentactive_item = db.actor:active_item()  
    if currentactive_item ~= nil then 
      local mws_name = currentactive_item:section()
	  local radweapon = "no" 
	  local radpower = 0.006
		 if string.find(mws_name, "sknife") then
			radweapon = "yes"
		 end
		 if string.find(mws_name, "wpn_fn2000_rad") or string.find(mws_name, "wpn_vintorez_rad") or string.find(mws_name, "wpn_g36_rad") then
			radweapon = "yes"
			radpower = 0.025
		 end
		 if string.find(mws_name, "wpn_lr300_rad") or string.find(mws_name, "wpn_winchester_m5") then
			radweapon = "yes"
			radpower = 0.017
		 end
         if gametime > db.repairtimeout and radweapon == "yes" then 
		   db.repairtimeout = time_global() + 2000
		   db.actor.radiation = radpower
		 end
    end
	if wish_suit_name == "outfit_lethalspeed_exo_m1" then
         if gametime > wishradtimeout then 
		   wishradtimeout = time_global() + 2000
		   db.actor.radiation = 0.030
		 end
	end
  end
end
end

function checkskillrank()

local act_rank = ranks.get_obj_rank_name(db.actor)
local weapactive_slot = db.actor:active_slot()
if act_rank ~= nil then

 if weapactive_slot == 1 or weapactive_slot == 2 then  
   local current_weap = db.actor:active_item() 
   local setweaponcond = "yes"
   local weapname

   if current_weap ~= nil then 

    weapname = current_weap:section()
    if string.find(weapname, "mp5") or string.find(weapname, "bm16") or string.find(weapname, "wpn_pm") or string.find(weapname, "wpn_pb") or string.find(weapname, "wpn_colt") or string.find(weapname, "berreta") or string.find(weapname, "walther") or string.find(weapname, "af_") or string.find(weapname, "nife") or string.find(weapname, "knive") then
       setweaponcond = "nope"
    end

    if setweaponcond ~= "nope" then
	  if db.storage[db.actor:id()].pstor[current_weap:id().."_repair"] ~= "trader" then
       if act_rank == "novice" and current_weap:condition() > 0.65 then current_weap:set_condition(0.65) end
       if act_rank == "experienced" and current_weap:condition() > 0.75 then current_weap:set_condition(0.75) end
   	   if act_rank == "veteran" and current_weap:condition() > 0.85 then current_weap:set_condition(0.85) end
	  end
    end
   end
 end

 local current_suit = db.actor:get_current_outfit()
 local setcurrent_suit = "yes"
 local csuitname
 if current_suit ~= nil then 
  csuitname = current_suit:section() 
  if string.find(csuitname, "novice") or string.find(csuitname, "bandit_outfit") or string.find(csuitname, "killer_outfit") or string.find(csuitname, "stalker_outfit") or string.find(csuitname, "bandit_antigas") or string.find(csuitname, "bandit_veteran") or string.find(csuitname, "killer_antigas") then
  setcurrent_suit = "nope"
  end
  if setcurrent_suit ~= "nope" then
   if db.storage[db.actor:id()].pstor[current_suit:id().."_repair"] ~= "trader" then
	 if act_rank == "novice" and current_suit:condition() > 0.70 then current_suit:set_condition(0.70) end
	 if act_rank == "experienced" and current_suit:condition() > 0.77 then current_suit:set_condition(0.77) end
	 if act_rank == "veteran" and current_suit:condition() > 0.87 then current_suit:set_condition(0.87) end
   end
  if (db.storage[db.actor:id()].pstor[current_suit:id().."_helmet"] == "off") and (db.storage[db.actor:id()].pstor[current_suit:id().."_helmet_off"] ~= "yes") then
     local stncfsuit = current_suit:condition() - 0.2
     current_suit:set_condition(stncfsuit)
	 db.storage[db.actor:id()].pstor[current_suit:id().."_helmet_off"] = "yes"
	 db.storage[db.actor:id()].pstor[current_suit:id().."_helmet_on"] = "nope"
  end
  if (db.storage[db.actor:id()].pstor[current_suit:id().."_helmet"] == "on") and (db.storage[db.actor:id()].pstor[current_suit:id().."_helmet_on"] ~= "yes") then
     local stncfsuit = current_suit:condition() + 0.2
     current_suit:set_condition(stncfsuit)
	 db.storage[db.actor:id()].pstor[current_suit:id().."_helmet_on"] = "yes"
	 db.storage[db.actor:id()].pstor[current_suit:id().."_helmet_off"] = "nope"
  end
 end
end
end

end

function lootmoney(npc)
if npc ~= nil then
	local npc_rank, deadmoney
	npc_rank = ranks.get_obj_rank_name(npc)
	if npc_rank == "novice" then  
		deadmoney = math.random(25,201) 
	elseif npc_rank == "experienced" then  
		deadmoney = math.random(50,302)
	elseif npc_rank == "veteran" then 
		deadmoney = math.random(100,604)
	elseif npc_rank == "master" then 
		deadmoney = math.random(200,1208) 	
	end

	if npc_rank ~= nil then
	 local screenwidth = device().width
	 local screenheight = device().height
	 local divwh = screenwidth / screenheight
	 if divwh < 1.4 and screenwidth <=800 and screenheight <= 600 then
 		news_manager.relocate_money(db.actor, "in", deadmoney)
	 end
	  local mylootingid = game.translate_string("looting_id")
	  local news_texti = "%c[255,255,0,0]" .. mylootingid .. " \\n"..npc:character_name()..": $"..game.translate_string(tostring(deadmoney).."RU")
	  db.actor:give_game_news(news_texti, "ui\\ui_iconsTotal", Frect():set(0,0,83,47), 0, 10000)
	  db.actor:give_money(deadmoney)
	  game_stats.money_quest_update(deadmoney) 

	end
return
else
logf("looting npc is nil")
end
end


---- hud stuffs here




local myctimeis = -1
local cmgdw = 0
local defaultweatheris = "default"
local wealoaded = "no"
local chth = 0
local dcw_info = 0 
function setweather(wot)
local cyyy = 0
local hth = level.get_time_hours()
local level_name = level.name()
local myweathers_types = {"default", "default2", "horror", "horror2", "yantar", "yantar2", "default4", "radar", "radar2", "chuva", "rain", "default3"}
local count_types = 12
if hth > 5 and hth < 20 then 
	myweathers_types = {"default", "default2", "horror", "horror2", "yantar", "yantar2", "default4", "radar", "radar2", "stancia", "stancia2", "chuva", "rain", "default3"} 
	count_types = 14
end
if db.chaotic_weather == "off" then
	local myweathers_types = {"default", "default2", "default4", "chuva", "rain", "default3"}
	local count_types = 6
end
if (level_name == l08_yantar) or (level_name == l04_darkvalley) then
	myweathers_types = {"yantar", "yantar2"} 
	count_types = 2
end
 if (dcw_info == 4) and not has_alife_info("encyclopedy_chaotic_weather") then db.actor:give_info_portion("encyclopedy_chaotic_weather") end
 if (db.blowisgoingon == "false") and (hellisgoingon == "no") and (level_name ~= "l12_stancia_2") and (level_name ~= "l12_stancia") and (level_name ~= "l12u_sarcofag") and (level_name ~= "l12u_control_monolith") and (level_name ~= "l04u_labx18") and (level_name ~= "l08u_brainlab") and (level_name ~= "l10u_bunker") and (level_name ~= "l03u_agr_underground") then
 local gametimew = time_global()
 if chth == 0 then chth = time_global() + 10000 end
 if wot == "load" then level.set_weather_fx("surge_day")
	 wealoaded = "yes"
 end 
	if hth > myctimeis and db.setmyweather == "true" then
	 db.setmyweather = "false" 
	end
   if wealoaded == "yes" and gametimew > chth  then
     for cyyy = 0, 24 do
		if db.setmyweather == "false" and hth == cyyy then
			db.setmyweather = "true"
			myctimeis = hth
			level.add_pp_effector ("dead_zone.ppe", 1978, false)
			level.add_pp_effector ("teleport.ppe", 1979, false)  
			local randomweather = myweathers_types[math.random(count_types)]
				if defaultweatheris == randomweather and cmgdw == 2 then 
					local randomweatherb = myweathers_types[math.random(count_types)]
					if randomweatherb ~= randomweather then cmgdw = 0 end
				else
					cmgdw = 0
				end
				cmgdw = 0
				if randomweather and cmgdw < 2 then 
					if (level_name == l08_yantar) or (level_name == l04_darkvalley) then
						level.set_weather(randomweather)
					else
					level.set_weather("horror")
					-- level.set_weather(randomweather)  
					end
					defaultweatheris = randomweather
					myrweatheris = randomweather
					cmgdw = cmgdw + 1
					dcw_info = dcw_info + 1
				logf ("setting random weather - setmyweather =  true - weather = " .. randomweather)
				end
		end
	end
   end

  end 

end

local checkcorpagain = true
function npc_on_deatch(victim, who)
local level_name = level.name()
 if level_name == "l04_darkvalley" and checkcorpagain == true then
   -- victim = killed - who = killer
   local check_gaus = victim:object("wpn_gauss")
   local check_ammogaus = victim:object("ammo_gauss")
   if check_gaus == nil and check_ammogaus ~= nil then
	 alife():create("wpn_gauss", victim:position(), victim:level_vertex_id(), victim:game_vertex_id(), victim:id())
	 alife():create("ammo_gauss", victim:position(), victim:level_vertex_id(), victim:game_vertex_id(), victim:id())
	 alife():create("ammo_gauss", victim:position(), victim:level_vertex_id(), victim:game_vertex_id(), victim:id())
	 checkcorpagain = false
   end
 end

if victim ~= nil and who ~= nil and db.gore == "on" then
 local victimis = victim:name()
 local whois = who:name()
  if whois == db.actor:name() then 
   local cur_weapon = db.actor:active_item()
   if cur_weapon ~= nil then
     local cur_weapon_name =  cur_weapon:section() 
     local victim_pos = victim:position()
     local npc_pos = vector():set( victim_pos.x, victim_pos.y + 1, victim_pos.z)	
   
   	 if cur_weapon_name == "wpn_sgauss" then
   		local particle = particles_object("anomaly2\\body_tear_00")
        particle:play_at_pos(npc_pos)
        local snd_obj = xr_sound.get_safe_sound_object([[anomaly\anomaly_body_tear_1]])
        snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 0.3)
   		destroy_it(victim, "chk")
   	 end
   	 if string.find(cur_weapon_name, "winchester") or string.find(cur_weapon_name, "wpn_gauss") or 
   	    string.find(cur_weapon_name, "bm16") or string.find(cur_weapon_name, "wpn_svd") or string.find(cur_weapon_name, "wpn_knife") or
   	    string.find(cur_weapon_name, "spas12") or string.find(cur_weapon_name, "toz34") then
   		local particle = particles_object("hit_fx\\hit_flesh_headshot")
   	    particle:play_at_pos(npc_pos)
   	    local snd_obj = xr_sound.get_safe_sound_object([[anomaly\anomaly_body_tear_1]])
   	    snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 0.3)
   	 	particle:stop()
   	 end
   end
  end
end
end


function destroy_it(object, what)
if db.vaporize == "on" then
	if what == "chk" then db.vanish = object end

	if what == "yes" then
		alife():release(alife():object(object:id()), true)	
		-- db.del_obj(object)
		-- db.storage[object:id()] = nil
		logf("release")
		db.vanish = nil
	end
end
end


function abchell(wot, portp)
local ccs
local actor_rank = ranks.get_obj_rank_name(db.actor)
if (waitfplayer > 0) and (time_global() > waitfplayer) and db.actor:alive() then
 if wot == "hellportal" and spawnagain == "yes" then
  local chkhellport = math.random(1,300)	-- 100
  logf("hell portal" .. chkhellport)	
  if chkhellport == 10 and db.playerinzone == "no" then -- 50
	spawnagain = "no"
	countport = 0

	local snd_obj = xr_sound.get_safe_sound_object([[anomaly\teleport_incoming]])
	snd_obj:play_no_feedback(db.actor, sound_object.s3d, 0, portp, 1.0)

	local hmnpc = 4
	local hmmon = 3
	local hmrmon = 12
	local merc     = {"mil_killer_respawn_1", "mil_killer_respawn_2", "cit_killer_respawn_3", "cit_killer_respawn_2", "cit_killer_respawn_1"}
	local bandit   = {"cit_bandit_respawn_1", "cit_bandit_respawn_2", "val_bandit_respawn_3", "val_bandit_respawn_4", "ros_bandit_respawn_4"}
	local mono     = {"pri_monolith_respawn_1", "pri_monolith_respawn_2", "pri_monolith_respawn_3", "rad_monolith_respawn_3", "rad_monolith_respawn_2"}
	local mili 	   = {"pri_respawn_military", "rad_specnaz_respawn_specnaz", "rad_soldier_master", "val_soldier_respawn_1", "agr_soldier_regular"}
	local zombied  = {"rad_zombied_respawn_1", "rad_zombied_respawn_2", "yan_zombied_respawn_2", "yan_zombied_respawn_3", "rad_zombied_respawn_3" }
	local monsters = {"zombie_immortal", "zombie_hell", "zombie_ghost", "bloodsucker_hell", "snork_strong", "chimera_weak", "burer_weak", "fracture_weak", "gigant_strong", "psy_dog", "zombie_normal", "controller_tubeman"}

	if actor_rank == "novice" then 
		monsters = {"zombie_immortal", "zombie_hell", "zombie_ghost", "snork_strong", "chimera_weak", "fracture_weak", "gigant_strong", "zombie_normal"} 
		hmrmon = 8
		hmmon = 3
	    hmnpc = 4
	end
	if actor_rank == "experienced" then  
		monsters = {"zombie_immortal", "zombie_hell", "zombie_ghost", "bloodsucker_hell", "snork_strong", "chimera_weak", "burer_weak", "fracture_weak", "zombie_normal"} 
		hmrmon = 9
		hmmon = 3
	    hmnpc = 5
	end
    if actor_rank == "veteran" then
		monsters = {"zombie_immortal", "zombie_hell", "zombie_ghost", "bloodsucker_hell", "snork_strong", "chimera_weak", "burer_weak", "fracture_weak", "gigant_strong", "psy_dog", "zombie_normal", "controller_tubeman"} 
		hmrmon = 12
		hmmon = 4
	    hmnpc = 6
	end
	if actor_rank == "master" then 
		monsters = {"zombie_immortal", "zombie_hell", "zombie_ghost", "bloodsucker_hell", "snork_strong", "chimera_weak", "burer_weak", "fracture_weak", "gigant_strong", "psy_dog", "zombie_normal", "controller_tubeman"} 
		hmrmon = 12
		hmmon = 5
	    hmnpc = 6
	end

	local creatures = {"merc", "bandit", "monster", "mono", "mili", "monster", "zombied"} 
	local who = creatures[math.random(7)]
	if who == "zombied" then
		for ccs = 1, hmnpc do	 
			alife():create(zombied[math.random(5)], portp, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
	end
	if who == "merc" then
		for ccs = 1, hmnpc do	 
			alife():create(merc[math.random(5)], portp, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
	end
	if who == "bandit" then
		for ccs = 1, hmnpc do	 
			alife():create(bandit[math.random(5)], portp, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
	end
	if who == "mono" then
		for ccs = 1, hmnpc do	 
			alife():create(mono[math.random(5)], portp, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
	end
	if who == "mili" then
		for ccs = 1, hmnpc do	 
			alife():create(mili[math.random(5)], portp, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
	end
	if who == "monster" then
		for ccs = 1, hmmon do	 
			alife():create(monsters[math.random(hmrmon)], portp, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
	end
  end
 end

 if wot == "helltime" then
 -- do similar horrow/blowout time
 	local chkhelltime = math.random(1,300)	-- 300
	logf("helltime - " .. chkhelltime)
	if chkhelltime == 10 and db.playerinzone == "no" then -- 150
		hellisgoingon = "yes"
		if not has_alife_info("encyclopedy_zone_inferno") then db.actor:give_info_portion("encyclopedy_zone_inferno") end
		db.storage[db.actor:id()].pstor["abc_hellstart"] = "yes"
		level.add_pp_effector ("teleport.ppe", 1981, false) 
		level.set_weather("inferno")
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_the_horror2]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
		genmyphatoms(7)
		spawnmonsterbearact = "yes"	
		local noobposition = db.actor:position()
		local nmpos, xnoob, znoob, cz
		xnoob = math.random(-100,100)
		znoob = math.random(-100,100)
		local posnearact = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
		alife():create("zombie_immortal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		alife():create("zombie_immortal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		xnoob = math.random(-100,100)
		znoob = math.random(-100,100)
		posnearact = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
		alife():create("zombie_ghost", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		alife():create("zombie_ghost", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		xnoob = math.random(-100,100)
		znoob = math.random(-100,100)
		posnearact = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
		alife():create("zombie_hell", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		alife():create("zombie_hell", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		xnoob = math.random(-100,100)
		znoob = math.random(-100,100)
		posnearact = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
		alife():create("zombie_normal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		alife():create("zombie_normal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		xnoob = math.random(-100,100)
		znoob = math.random(-100,100)
		posnearact = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)

		if actor_rank == "novice" then 
			alife():create("bloodsucker_hell", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
		if actor_rank == "experienced" then  
			alife():create("chimera_weak", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("bloodsucker_hell", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
	    if actor_rank == "veteran" then
			alife():create("burer_weak", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("bloodsucker_hell", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			genpsydogs("hell")
		end
		if actor_rank == "master" then 
			alife():create("chimera_weak", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("gigant_strong", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("burer_weak", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("bloodsucker_hell", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			genpsydogs("hell")
		end


	end
 end

end
end

local counthelltime = 0
function abchell_time()
if db.actor:alive() then
counthelltime = counthelltime + 1
local noobposition = db.actor:position()
local nmpos, xnoob, znoob, cz
xnoob = math.random(1,3)
znoob = math.random(1,3)
local posnearact = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
	if counthelltime == 5 then
		level.add_pp_effector ("dead_zone.ppe", 1979, false)
		-- level.set_weather_fx("surge_inferno")
	end
	if counthelltime == 15 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_immortal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_moan5]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthelltime == 35 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_hell", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_scr4]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthelltime == 55 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_normal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_scr10]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthelltime == 75 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_ghost", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_fallscream]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthelltime == 85 then
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_ratchant]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	    genmyphatoms(7)
	end
	if counthelltime == 100 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_immortal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_respawn]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthelltime == 120 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_normal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_ratchant]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthelltime == 140 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_normal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_scr4]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthelltime == 160 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_ghost", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_moan1]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthelltime == 180 then
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_ratchant]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	    genmyphatoms(7)
		-- level.set_weather("inferno")
	end
	if counthelltime > 180 then
		spawnmonsterbearact = "no"
		hellisgoingon = "no"	
	end
end
end



local counthorror = 0
function abchorror_time()
if db.actor:alive() then
counthorror = counthorror + 1
local noobposition = db.actor:position()
local nmpos, xnoob, znoob, cz
xnoob = math.random(1,3)
znoob = math.random(1,3)
local posnearact = vector():set(noobposition.x + xnoob, noobposition.y, noobposition.z + znoob)
	if counthorror == 15 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_immortal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_respawn]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthorror == 35 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_normal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_ratchant]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthorror == 55 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_normal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_scr4]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthorror == 75 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_ghost", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_moan1]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthorror == 95 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_immortal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_moan5]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthorror == 115 then
		level.add_pp_effector ("dead_zone.ppe", 1978, false)
		alife():create("zombie_immortal", posnearact, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		local snd_obj = xr_sound.get_safe_sound_object([[ambient\random\rnd_ratchant]])
		snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 2.5)
	end
	if counthorror > 115 then
		horronearact = "no"
	end
end
end



function check_use(obj, who)
-- logf("check_use - " .. obj:name())
  if db.actor and who and who:id()==db.actor:id() then
    -- check_drop_item(obj)
  end
end


local anomtime = 0
local callportal = "no"
local objart
local objartid
function chk_anom(obj)
if db.actor ~= nil then
local canomt = time_global()
if anomtime == 0 and callportal == "yes" then anomtime = time_global() + 5000 end

  if obj ~= nil and obj ~= "load" then
  -- logf("chk_anom = " .. obj:section())
    if obj:section() == "af_electra_teleport" then
		callportal = "yes"
		objart = obj
		objartid = obj:id()
    end	
  end

 if canomt > anomtime and callportal == "yes" and anomtime > 0 and level.present() then
	callportal = "no"
	anomtime = 0

		local didpickup = db.actor:item_in_slot(1)
		local isiis = "no"
		if didpickup ~= nil then isiis = didpickup:id() end
		if level.object_by_id(objartid) ~= nil and isiis ~= objartid then
			abc_portals(objart)

			-- testando wish granter			
	    	local gui_win = abc_wishgranter.wisher_ui(get_hud())
			level.start_stop_menu(gui_win, true)

		end
 end

end
end

function abc_portals(obj)
local level_name = level.name()
local setonlyone = "yes"
if db.storage[db.actor:id()].pstor == nil then
   db.storage[db.actor:id()].pstor = {}
end


local abcportala = db.storage[db.actor:id()].pstor["abcportala"]
local abcportalb = db.storage[db.actor:id()].pstor["abcportalb"]

if abcportala == nil then
 db.storage[db.actor:id()].pstor["abc_hell"] = "on"
 local noobposition = obj:position()
-- logf("portal A position")
-- logf("portal A position = " .. noobposition.x .. " - " .. noobposition.y .. " - " .. noobposition.z)
 local portpos = vector():set(noobposition.x, noobposition.y + 1, noobposition.z + 1)
 db.storage[db.actor:id()].pstor["abcportala"] = "set"
 local portmin = level.get_time_minutes()
 local porthour = level.get_time_hours()
 if portmin < 10 then portmin = "0"..portmin end
 if porthour < 10 then porthour = "0"..porthour end

 db.storage[db.actor:id()].pstor["abcportala_time"] = "[" .. porthour .. ":" .. portmin .. "]"
 db.storage[db.actor:id()].pstor["abcportala_n"] = level_name

 local portalnumber = db.storage[db.actor:id()].pstor["number"]
 if portalnumber ~= nil then
	db.storage[db.actor:id()].pstor["number"] = portalnumber + 1
 else
	db.storage[db.actor:id()].pstor["number"] = 1
 end

db.storage[db.actor:id()].pstor["abcportala_num"] = db.storage[db.actor:id()].pstor["number"]

-- logf("making portal A")
setonlyone = "no"
alife():release(alife():object(obj:id()), true)
local anom_obj = alife():create("abc_zone_portal", portpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
db.storage[db.actor:id()].pstor["abcportala_id"] = anom_obj.id
end

-- abcportala = db.storage[db.actor:id()].pstor["abcportala"]

if abcportalb == nil and abcportala == "set" and setonlyone == "yes" then
 local noobposition = obj:position()
-- logf("portal B position")
-- logf("portal B position = " .. noobposition.x .. " - " .. noobposition.y .. " - " .. noobposition.z)
 local portpos = vector():set(noobposition.x, noobposition.y + 1, noobposition.z + 1)
 db.storage[db.actor:id()].pstor["abcportalb"] = "set"
 local portmin = level.get_time_minutes()
 local porthour = level.get_time_hours()
 if portmin < 10 then portmin = "0"..portmin end
 if porthour < 10 then porthour = "0"..porthour end
 db.storage[db.actor:id()].pstor["abcportalb_time"] = "[" .. porthour .. ":" .. portmin .. "]"
 db.storage[db.actor:id()].pstor["abcportalb_n"] = level_name

 local portalnumber = db.storage[db.actor:id()].pstor["number"]
 if portalnumber ~= nil then
	db.storage[db.actor:id()].pstor["number"] = portalnumber + 1
 else
	db.storage[db.actor:id()].pstor["number"] = 1
 end

db.storage[db.actor:id()].pstor["abcportalb_num"] = db.storage[db.actor:id()].pstor["number"]

-- logf("making portal B")
alife():release(alife():object(obj:id()), true)
local anom_obj = alife():create("abc_zone_portal", portpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
db.storage[db.actor:id()].pstor["abcportalb_id"] = anom_obj.id
end


abcportala = db.storage[db.actor:id()].pstor["abcportala"]
abcportalb = db.storage[db.actor:id()].pstor["abcportalb"]

if abcportala == "set" and abcportalb == "set" then
    local obja, objb
	local portala = db.storage[db.actor:id()].pstor["abcportala_n"]
	local portalb = db.storage[db.actor:id()].pstor["abcportalb_n"]

    local portalatime = db.storage[db.actor:id()].pstor["abcportala_time"]

    local portalbtime = db.storage[db.actor:id()].pstor["abcportalb_time"]

	local obja_id = db.storage[db.actor:id()].pstor["abcportala_id"]
	local objb_id = db.storage[db.actor:id()].pstor["abcportalb_id"]

	local portalanum = db.storage[db.actor:id()].pstor["abcportala_num"]
	local portalbnum = db.storage[db.actor:id()].pstor["abcportalb_num"]

	if portalb ~= portala then

	if db.storage[db.actor:id()].pstor[level_name.."_a_id"] ~= nil then
	   -- logf("portal in this level already set! - removing previous portal")
	   local mobja = alife():object(db.storage[db.actor:id()].pstor[level_name.."_a_id"])
	   local mobjb = alife():object(db.storage[db.actor:id()].pstor[level_name.."_b_id"])
	   if mobja ~= nil then 
	     -- logf("mobja not nil removing")
		 level.map_remove_object_spot(mobja.id, "level_changer") 
	     alife():release(alife():object(mobja.id), true)
	   end
	   if mobjb ~= nil then 
	     -- logf("mobjb not nil removing")
		 level.map_remove_object_spot(mobjb.id, "level_changer")
         alife():release(alife():object(mobjb.id), true)
	   end
	   local portalnumber = db.storage[db.actor:id()].pstor["number"]
	   local prevaname = db.storage[db.actor:id()].pstor["abcportal_preva_name"]
	   local prevbname = db.storage[db.actor:id()].pstor["abcportal_prevb_name"]
	   if portalnumber ~= nil then 
			db.storage[db.actor:id()].pstor["number"] = portalnumber - 2  
			portalanum = portalanum - 2
			portalbnum = portalbnum - 2
		end
	   if prevaname ~= nil then 
		if db.storage[db.actor:id()].pstor[prevaname.."_a_num"] ~= nil then
			db.storage[db.actor:id()].pstor[prevaname.."_a_num"] = db.storage[db.actor:id()].pstor[prevaname.."_a_num"] - 1
		end
		if db.storage[db.actor:id()].pstor[prevaname.."_b_num"] ~= nil then
			db.storage[db.actor:id()].pstor[prevaname.."_b_num"] = db.storage[db.actor:id()].pstor[prevaname.."_b_num"] - 1
		end
	   end	
	   if prevbname ~= nil then 
		if db.storage[db.actor:id()].pstor[prevbname.."_a_num"] ~= nil then
			db.storage[db.actor:id()].pstor[prevbname.."_a_num"] = db.storage[db.actor:id()].pstor[prevbname.."_a_num"] - 1
		end
		if db.storage[db.actor:id()].pstor[prevbname.."_b_num"] ~= nil then
			db.storage[db.actor:id()].pstor[prevbname.."_b_num"] = db.storage[db.actor:id()].pstor[prevbname.."_b_num"] - 1
		end
	   end	
			
      end

		db.storage[db.actor:id()].pstor["abcportal_preva_name"] = portala
		db.storage[db.actor:id()].pstor["abcportal_prevb_name"] = portalb


		db.storage[db.actor:id()].pstor[portala.."_b_name"] = portalb
		db.storage[db.actor:id()].pstor[portala.."_a_time"] = portalatime
		db.storage[db.actor:id()].pstor[portala.."_b_time"] = portalbtime
		db.storage[db.actor:id()].pstor[portala.."_a_id"] = obja_id
		db.storage[db.actor:id()].pstor[portala.."_b_id"] = objb_id
		db.storage[db.actor:id()].pstor[portala.."_a_num"] = portalanum
		db.storage[db.actor:id()].pstor[portala.."_b_num"] = portalbnum

		db.storage[db.actor:id()].pstor[portalb.."_a_name"] = portala
		db.storage[db.actor:id()].pstor[portalb.."_b_time"] = portalbtime
		db.storage[db.actor:id()].pstor[portalb.."_a_time"] = portalatime
		db.storage[db.actor:id()].pstor[portalb.."_a_id"] = obja_id
		db.storage[db.actor:id()].pstor[portalb.."_b_id"] = objb_id
		db.storage[db.actor:id()].pstor[portalb.."_a_num"] = portalanum
		db.storage[db.actor:id()].pstor[portalb.."_b_num"] = portalbnum
 	else

-- test para 2 portais

	if db.storage[db.actor:id()].pstor[level_name.."_sl_a_id"] ~= nil then
	   -- logf("portal in this level already set! - removing previous portal")
	   local mobja = alife():object(db.storage[db.actor:id()].pstor[level_name.."_sl_a_id"])
	   local mobjb = alife():object(db.storage[db.actor:id()].pstor[level_name.."_sl_b_id"])
	   if mobja ~= nil then 
	     -- logf("sl_ mobja not nil removing same level")
		 level.map_remove_object_spot(mobja.id, "level_changer") 
	     alife():release(alife():object(mobja.id), true)
	   end
	   if mobjb ~= nil then 
	     -- logf("sl_ mobjb not nil removing same level")
		 level.map_remove_object_spot(mobjb.id, "level_changer")
         alife():release(alife():object(mobjb.id), true)
	   end
	   local portalnumber = db.storage[db.actor:id()].pstor["number"]
	   local prevaname = db.storage[db.actor:id()].pstor["abcportal_preva_name_sl"]
	   local prevbname = db.storage[db.actor:id()].pstor["abcportal_prevb_name_sl"]
	   if portalnumber ~= nil then 
			db.storage[db.actor:id()].pstor["number"] = portalnumber - 2  
			portalanum = portalanum - 2
			portalbnum = portalbnum - 2
		end
	   if prevaname ~= nil then 
		if db.storage[db.actor:id()].pstor[prevaname.."_a_num"] ~= nil then
			db.storage[db.actor:id()].pstor[prevaname.."_a_num"] = db.storage[db.actor:id()].pstor[prevaname.."_a_num"] - 1
		end
		if db.storage[db.actor:id()].pstor[prevaname.."_b_num"] ~= nil then
			db.storage[db.actor:id()].pstor[prevaname.."_b_num"] = db.storage[db.actor:id()].pstor[prevaname.."_b_num"] - 1
		end
	   end	
	   if prevbname ~= nil then 
		if db.storage[db.actor:id()].pstor[prevbname.."_a_num"] ~= nil then
		--	db.storage[db.actor:id()].pstor[prevbname.."_a_num"] = db.storage[db.actor:id()].pstor[prevbname.."_a_num"] - 1
		end
		if db.storage[db.actor:id()].pstor[prevbname.."_b_num"] ~= nil then
		--	db.storage[db.actor:id()].pstor[prevbname.."_b_num"] = db.storage[db.actor:id()].pstor[prevbname.."_b_num"] - 1
		end
	   end	
     end

-- fim test

		local portalaa = portala .. "_sl"
		local portalbb = portala .. "_sl"

		db.storage[db.actor:id()].pstor["abcportal_preva_name_sl"] = portalaa
		db.storage[db.actor:id()].pstor["abcportal_prevb_name_sl"] = portalbb

		db.storage[db.actor:id()].pstor[portalaa.."_b_name"] = portalb
		db.storage[db.actor:id()].pstor[portalaa.."_a_time"] = portalatime
		db.storage[db.actor:id()].pstor[portalaa.."_b_time"] = portalbtime
		db.storage[db.actor:id()].pstor[portalaa.."_a_id"] = obja_id
		db.storage[db.actor:id()].pstor[portalaa.."_b_id"] = objb_id
		db.storage[db.actor:id()].pstor[portalaa.."_a_num"] = portalanum
		db.storage[db.actor:id()].pstor[portalaa.."_b_num"] = portalbnum

		db.storage[db.actor:id()].pstor[portalbb.."_a_name"] = portala
		db.storage[db.actor:id()].pstor[portalbb.."_b_time"] = portalbtime
		db.storage[db.actor:id()].pstor[portalbb.."_a_time"] = portalatime
		db.storage[db.actor:id()].pstor[portalbb.."_a_id"] = obja_id
		db.storage[db.actor:id()].pstor[portalbb.."_b_id"] = objb_id
		db.storage[db.actor:id()].pstor[portalbb.."_a_num"] = portalanum
		db.storage[db.actor:id()].pstor[portalbb.."_b_num"] = portalbnum

	end

-- logf("portal A and B set")

	local curportal = db.storage[db.actor:id()].pstor["number"]
	local prevportal = curportal - 1

    level.map_add_object_spot(obja_id, "level_changer", "Portal (" .. prevportal .. ")" .. portala .. " to (" .. curportal .. ")" .. portalb .. " :: " .. portalatime)
    level.map_add_object_spot(objb_id, "level_changer", "Portal (" .. curportal .. ")" .. portalb .. " to (" .. prevportal .. ")" .. portala .. " :: " .. portalbtime)

-- logf("Portals A and B done, adding to map mark")

	db.storage[db.actor:id()].pstor["abcportala"] = nil
	db.storage[db.actor:id()].pstor["abcportalb"] = nil

if not has_alife_info("encyclopedy_zone_portals") then db.actor:give_info_portion("encyclopedy_zone_portals") end



end

end


function playsound()
			local snd_objt = xr_sound.get_safe_sound_object([[affects\tinnitus3a]])
			snd_objt:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)	
end

local exitingfromlvl = "no"
local exitingfrompos = "no"
local actcurpor = "no"
local teleback = "no"
local portzone = "no"
local chkporttime, exit_to_lv
function checkportals()
if db.actor ~= nil then
local level_name = level.name()

 if db.storage[db.actor:id()].pstor ~= nil then

   if db.storage[db.actor:id()].pstor[level_name.."_sl_b_name"] ~= nil then
     if db.storage[db.actor:id()].pstor[level_name.."_sl_b_name"] == level_name then

	   local mobja = level.object_by_id(db.storage[db.actor:id()].pstor[level_name.."_sl_a_id"])
	   if mobja ~= nil then
	    if (mobja:position():distance_to_sqr(db.actor:position()) <= 2600) then
			   abchell("hellportal", mobja:position())
		end
	    if (mobja:position():distance_to_sqr(db.actor:position()) <= 2) then

			local mobjb = level.object_by_id(db.storage[db.actor:id()].pstor[level_name.."_sl_b_id"])
			local setpostob = mobjb:position()
			local setnpostob = vector() 
			setnpostob.x = setpostob.x
			setnpostob.y = setpostob.y
			setnpostob.z = setpostob.z + 3
            db.actor:set_actor_position(setnpostob)  
			local dir = db.actor:get_current_direction()
			db.actor:set_actor_direction(-dir:getH())
			level.add_pp_effector ("teleport.ppe", 2008, false)
			-- logf("teleporting A to B same level")
			playsound()
        end
	   end

	   local mobjb = level.object_by_id(db.storage[db.actor:id()].pstor[level_name.."_sl_b_id"])
	   if mobjb ~= nil then
	    if (mobjb:position():distance_to_sqr(db.actor:position()) <= 2600) then
			   abchell("hellportal", mobjb:position())
		end
	    if (mobjb:position():distance_to_sqr(db.actor:position()) <= 2) then

			local mobja = level.object_by_id(db.storage[db.actor:id()].pstor[level_name.."_sl_a_id"])
			local setpostoa = mobja:position()
			local setnpostoa = vector() 
			setnpostoa.x = setpostoa.x
			setnpostoa.y = setpostoa.y
			setnpostoa.z = setpostoa.z + 3
            db.actor:set_actor_position(setnpostoa) 
			local dir = db.actor:get_current_direction()
			db.actor:set_actor_direction(-dir:getH())
			level.add_pp_effector ("teleport.ppe", 2008, false)   
			-- logf("teleporting B to A same level")
			playsound()
        end
       end

     end
   end


  if db.storage[db.actor:id()].pstor["abc_exit_to_id"] ~= nil then
	local mpobj = level.object_by_id(db.storage[db.actor:id()].pstor["abc_exit_to_id"])	
	    if mpobj ~= nil then
			local setpostoa = mpobj:position()
			local setnpostoa = vector() 
			setnpostoa.x = setpostoa.x
			setnpostoa.y = setpostoa.y
			setnpostoa.z = setpostoa.z + 3
            db.actor:set_actor_position(setnpostoa) 
			local dir = db.actor:get_current_direction()
			db.actor:set_actor_direction(-dir:getH())
			level.add_pp_effector ("teleport.ppe", 2008, false)   
			-- logf("teleporting no from the same level")
			playsound()
			db.storage[db.actor:id()].pstor["abc_exit_to_id"] = nil
		end
  end

  if db.storage[db.actor:id()].pstor[level_name.."_a_name"] ~= nil then
     if db.storage[db.actor:id()].pstor[level_name.."_a_name"] ~= level_name then

	   local mobjb = level.object_by_id(db.storage[db.actor:id()].pstor[level_name.."_b_id"])
	   if mobjb ~= nil then
	    if (mobjb:position():distance_to_sqr(db.actor:position()) <= 1300) then
			   -- abchell("hellportal", mobjb:position())
		end
	    if (mobjb:position():distance_to_sqr(db.actor:position()) <= 3) and portzone ~= "yes" then
			actcurpor = db.actor:position()
			-- logf("Portal B :: portal A is not in the same level of portal B")
			exit_to_lv = db.storage[db.actor:id()].pstor[level_name.."_a_name"]
			db.storage[db.actor:id()].pstor["abc_exit_to_id"] = db.storage[db.actor:id()].pstor[level_name.."_a_id"]
			portzone = "yes"
	    	local gui_win = portal_ui(get_hud())
			level.start_stop_menu(gui_win, true)

		end
	   end

	 end
   end

  if db.storage[db.actor:id()].pstor[level_name.."_b_name"] ~= nil then
     if db.storage[db.actor:id()].pstor[level_name.."_b_name"] ~= level_name then
	   local mobjb = level.object_by_id(db.storage[db.actor:id()].pstor[level_name.."_a_id"])
	   if mobjb ~= nil then
	    if (mobjb:position():distance_to_sqr(db.actor:position()) <= 1300) then
			   -- abchell("hellportal", mobjb:position())
		end
	    if (mobjb:position():distance_to_sqr(db.actor:position()) <= 3) and	portzone ~= "yes" then
			actcurpor = db.actor:position()
			-- logf("Portal A :: portal B is not in the same level of portal A")
			exit_to_lv = db.storage[db.actor:id()].pstor[level_name.."_b_name"]
			db.storage[db.actor:id()].pstor["abc_exit_to_id"] = db.storage[db.actor:id()].pstor[level_name.."_b_id"]
			portzone = "yes"
	    	local gui_win = portal_ui(get_hud())
			level.start_stop_menu(gui_win, true)

		end
	   end

	 end
   end
	    
 end
end
end


function teletodlevel(exit_to_lv)
-- logf("exit_to_lv = " .. exit_to_lv)

			local act_posto
			-- altear all.spawn para valores redondo comecando do 100
			if exit_to_lv == "l01_escape"            then act_posto = vector():set(10, 100, 10) end
			if exit_to_lv == "l02_garbage"           then act_posto = vector():set(10, 120, 10) end
			if exit_to_lv == "l03_agroprom"          then act_posto = vector():set(10, 140, 10) end
			if exit_to_lv == "l05_bar"               then act_posto = vector():set(10, 160, 10) end
			if exit_to_lv == "l06_rostok"            then act_posto = vector():set(10, 180, 10) end
			if exit_to_lv == "l04_darkvalley"        then act_posto = vector():set(10, 200, 10) end
			if exit_to_lv == "l08_yantar"            then act_posto = vector():set(10, 220, 10) end
			if exit_to_lv == "l07_military"          then act_posto = vector():set(10, 240, 10) end
			if exit_to_lv == "l10_radar"             then act_posto = vector():set(10, 260, 10) end
			if exit_to_lv == "l11_pripyat"           then act_posto = vector():set(10, 280, 10) end
			if exit_to_lv == "l12_stancia"           then act_posto = vector():set(10, 300, 10) end
			if exit_to_lv == "l12_stancia_2"         then act_posto = vector():set(10, 320, 10) end
			if exit_to_lv == "l12u_sarcofag"         then act_posto = vector():set(10, 340, 10) end
			if exit_to_lv == "l12u_control_monolith" then act_posto = vector():set(10, 360, 10) end
			if exit_to_lv == "l04u_labx18"           then act_posto = vector():set(10, 380, 10) end
			if exit_to_lv == "l08u_brainlab"         then act_posto = vector():set(10, 400, 10) end
			if exit_to_lv == "l10u_bunker"           then act_posto = vector():set(10, 420, 10) end
			if exit_to_lv == "l03u_agr_underground"  then act_posto = vector():set(10, 440, 10) end
	
			-- teste scorfago
			
			if exit_to_lv == "wishgranter"  then act_posto = vector():set(22,58,42) end
		
			db.actor:set_actor_position(act_posto)

exitingfromlvl = level.name()
exitingfrompos = act_posto
		
end

class "portal_ui" (CUIScriptWnd)
function portal_ui:__init(owner) super()
	self.owner = owner
	self:InitControls()
	self:InitCallBacks()
end

function portal_ui:__finalize() end

function portal_ui:InitControls()
	self:Init(0,0,1024,768)
	local xml = CScriptXmlInit()
	xml:ParseFile("message_box.xml")

	self.message_box = CUIMessageBox()
	self:Register(self.message_box,"message_box")

end

function portal_ui:InitCallBacks()
	 self:AddCallback("message_box",		ui_events.MESSAGE_BOX_YES_CLICKED,    self.OnMsgYes,			self)
	 self:AddCallback("message_box",		ui_events.MESSAGE_BOX_NO_CLICKED,	  self.OnMsgNo,				self)
	 self:Onload()
end

function portal_ui:on_quit(what)
 self:GetHolder():start_stop_menu (self,true)
 if what == nil then 
	what = "goback" 
 end
 if what == "goback" then
	local setnpostoa = vector() 
	actcurpor = db.actor:position()
	setnpostoa.x = actcurpor.x
	setnpostoa.y = actcurpor.y
	setnpostoa.z = actcurpor.z -3 
    db.actor:set_actor_position(setnpostoa)
	local dir = db.actor:get_current_direction()
	db.actor:set_actor_direction(-dir:getH()) 
	teleback = "no"
	actcurpor = "no"
	portzone = "no"
 end
 if what == "gonext" then
	teletodlevel(exit_to_lv)
	portzone = "no"
 end

end

function portal_ui:OnKeyboard(dik, keyboard_action)
	CUIScriptWnd.OnKeyboard(self,dik,keyboard_action)
	if keyboard_action == ui_events.WINDOW_KEY_PRESSED then
		if dik == DIK_keys.DIK_ESCAPE then
			portzone = "yes"
			self:on_quit("goback")			 
		end
	 end
end

function portal_ui:OnMsgYes()
	portzone = "yes"
	self:on_quit("gonext")
end
function portal_ui:OnMsgNo()
	portzone = "yes"
	self:on_quit("goback")
end

function portal_ui:Onload()
	self.message_box:Init("message_box_change_level")
	self.message_box:SetAutoDelete(true)
	self.message_box:SetWindowName("message_box")
	self:AttachChild(self.message_box)	
	local teletos = game.translate_string("abc_portal_id")
	local telenlvn = game.translate_string(exit_to_lv)
	self.message_box:SetText(teletos .. " " .. telenlvn .. "?")
end


function free_playwish()
  level.show_indicators()
  level.enable_input()
  db.actor:restore_weapon()
  level.add_pp_effector ("deadcity_wake1.ppe", 231, false)
  -- level.add_pp_effector ("radar_psi.ppe", 1974, false)
  -- db.actor:disable_info_portion("sar2_monolith_miracle")
end

function mov_desire_1()
-- "I want the zone to disappear"
wishnews("abc_wish_vendetta_1")
free_playwish()
genmyphatoms(7)
local noobposition = db.actor:position()
local nmpos, xnoob, znoob
xnoob = math.random(-15,20)
znoob = math.random(-15,20)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
xnoob = math.random(-15,20)
znoob = math.random(-15,20)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("bloodsucker_hell", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
xnoob = math.random(-15,20)
znoob = math.random(-15,20)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
local nmpos, xnoob, znoob, cz
xnoob = math.random(-5,8)
znoob = math.random(-5,8)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("zombie_ghost", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
xnoob = math.random(-15,25)
znoob = math.random(-15,25)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
end

function mov_desire_2()
-- "I want to be rich"
wishnews("abc_wish_granted")
free_playwish()
local noobposition = db.actor:position()
local nmpos, xnoob, znoob, cz
local monein = db.actor:money() + 100000
dialogs.relocate_money(db.actor, monein, "in")
 for cz = 1, 10 do
	xnoob = math.random(-5,10)
	znoob = math.random(-5,10)
	nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
	alife():create("tushkano_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
 end
end

function mov_desire_3()
--- "I want to rule the world"
wishnews("abc_wish_vendetta_3")
free_playwish()
genmyphatoms(7)
local noobposition = db.actor:position()
local nmpos, xnoob, znoob
xnoob = math.random(-15,20)
znoob = math.random(-15,20)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("fracture_weak", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
xnoob = math.random(-15,20)
znoob = math.random(-15,20)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("bloodsucker_hell", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
xnoob = math.random(-15,20)
znoob = math.random(-15,20)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("burer_weak",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
end

function mov_desire_4()
-- "Humanity is corrupt, mankind must be controlled"
wishnews("abc_wish_vendetta_4")
free_playwish()
local noobposition = db.actor:position()
local nmpos, xnoob, znoob, cz
xnoob = math.random(-5,8)
znoob = math.random(-5,8)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("zombie_ghost", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
xnoob = math.random(-15,25)
znoob = math.random(-15,25)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
xnoob = math.random(-15,25)
znoob = math.random(-15,25)
nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
alife():create("controller_tubeman", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
 for cz = 1, 10 do
	xnoob = math.random(-5,10)
	znoob = math.random(-5,10)
	nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
	alife():create("tushkano_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
 end
end

function mov_desire_5()
-- "I want to immortality"
wishnews("abc_wish_vendetta_5")
free_playwish()
genmyphatoms(7)
local noobposition = db.actor:position()
local nmpos, xnoob, znoob, cz
 for cz = 1, 2 do
	xnoob = math.random(-5,8)
	znoob = math.random(-5,8)
	nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
	alife():create("zombie_ghost", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
	xnoob = math.random(-15,25)
	znoob = math.random(-15,25)
	nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
	alife():create("zombie_immortal", nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
	xnoob = math.random(-15,25)
	znoob = math.random(-15,25)
	nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
	alife():create("zombie_hell",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
	xnoob = math.random(-15,20)
	znoob = math.random(-15,20)
	nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
	alife():create("zombie_strong",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
	xnoob = math.random(-15,20)
	znoob = math.random(-15,20)
	nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
	alife():create("zombie_normal",nmpos, db.actor:level_vertex_id() , db.actor:game_vertex_id() )
 end

end

function mov_desire_6()
wishnews("abc_wish_granted")
alife():create("outfit_lethalspeed_exo_m1", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
alife():create("wpn_sgauss", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
alife():create("ammo_sgauss", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
alife():create("ammo_sgauss", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
alife():create("ammo_sgauss", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
local noobposition = db.actor:position()
local nmpos, xnoob, znoob, cz
local mono = {"pri_monolith_respawn_1", "pri_monolith_respawn_2", "pri_monolith_respawn_3", "rad_monolith_respawn_3", "rad_monolith_respawn_2"}
 for cz = 1, 10 do
	xnoob = math.random(-15,20)
	znoob = math.random(-15,20)
	nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
	alife():create(mono[math.random(5)], nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
 end
end

function mov_desire_7()
wishnews("abc_wish_granted")
alife():create("af_wishgranter", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id(), db.actor:id())
local noobposition = db.actor:position()
local nmpos, xnoob, znoob, cz
local zombied  = {"rad_zombied_respawn_1", "rad_zombied_respawn_2", "yan_zombied_respawn_2", "yan_zombied_respawn_3", "rad_zombied_respawn_3" }
 for cz = 1, 10 do
	xnoob = math.random(-15,20)
	znoob = math.random(-15,20)
	nmpos = vector():set( noobposition.x + xnoob, noobposition.y + 3, noobposition.z + znoob )
	alife():create(zombied[math.random(5)], nmpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
 end
end

function wishnews(news)
	local x = 166
	local y = 470
	local news_text = "\\n".."%c[255,160,160,160]"..game.translate_string("abc_wish_granter").." >> \\n".."%c[default]"..game.translate_string(news)
	if news == "abc_wish_granted" then 
		news_text = "\\n".."%c[255,160,160,160]"..game.translate_string("abc_wish_granter").." >> \\n".."%c[default]"..game.translate_string("abc_wish_granted").."\\n".."%c[default]"..game.translate_string("abc_wish_remember")
	end
	abc_news(news_text, x, y)
	return true
end

function abc_news(news, x, y)
	local wish_news = xr_sound.get_safe_sound_object([[device\pda\pda_news]])
    wish_news:play(db.actor, 0, sound_object.s2d)
	db.actor:give_game_news(news, "ui\\ui_iconsTotal", Frect():set(x,y,83,47), 0, 15000)
end

local stwish = "no"
local ctowish = 0
function checkwishgranter()
	if db.storage[db.actor:id()].pstor["abc_wishgranter_used"] == "yes" then
	local monopos = vector():set(24, 53, 36)	
		if (monopos:distance_to_sqr(db.actor:position()) <= 2) and stwish == "no" then
			logf("mircale from abc.script") 
		    -- local gui_win = abc_wishgranter.wisher_ui(get_hud())
			-- level.start_stop_menu(gui_win, true)
			stwish = "yes"
			-- logf("sarcofago - level.start_stop_menu")
		end
	end
 if stwish == "yes" then 
   ctowish = ctowish + 1
	if ctowish == 40 then 
		stwish = "no"
		ctowish = 0
	end
 end
end

local blood_agro = "no"
local fac
function van_events(w)
if w == "blood_esc" then
	if db.storage[db.actor:id()].pstor["blood_esc"] ~= "yes" then
		local bloodpos = vector():set(353, 16, -34)
		if (bloodpos:distance_to_sqr(db.actor:position()) <= 50) then 
			db.storage[db.actor:id()].pstor["blood_esc"] = "yes"
			alife():create("bloodsucker_hell", bloodpos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
	end
end

if w == "blood_agro" then
	if blood_agro ~= "yes" then
		local bloodpos = vector():set(-101, -14, -23)
		if (bloodpos:distance_to_sqr(db.actor:position()) <= 40) then 
			blood_agro = "yes"
			alife():create("zombie_ghost", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id())
			alife():create("zombie_normal", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id())
		end
	end
end

if w == "bar" then
	if db.storage[db.actor:id()].pstor["bar_war"] ~= "yes" and (db.lvlstartout < time_global()) then
		local randbar = math.random(-10,30) -- (-50, 100)
		logf("faction wars - bar randbar = " .. randbar)
		if randbar == 10 then
			db.storage[db.actor:id()].pstor["bar_war"] = "yes"
			local checkbarpos, checkbarpos1, checkbarpos2, checkbarpos3, checkbarpos4
			checkbarpos1 = vector():set(246, 0, -50)
			checkbarpos2 = vector():set(58, 0, 160)
			checkbarpos3 = vector():set(191.49, 5.20, -141.46)
			checkbarpos4 = vector():set(206, 0, -24)
			local randpos = math.random(1,4)
			if randpos == 1 then checkbarpos = checkbarpos1 end
			if randpos == 2 then checkbarpos = checkbarpos2 end
			if randpos == 3 then checkbarpos = checkbarpos3 end
			if randpos == 4 then checkbarpos = checkbarpos4 end
			local bar_spawn_pos = checkbarpos
			if (checkbarpos1:distance_to_sqr(db.actor:position()) <= 100) then bar_spawn_pos = checkbarpos2 end
			if (checkbarpos2:distance_to_sqr(db.actor:position()) <= 100) then bar_spawn_pos = checkbarpos3 end
			if (checkbarpos3:distance_to_sqr(db.actor:position()) <= 100) then bar_spawn_pos = checkbarpos4 end

			local fre = {"abc_fre_respawn_1", "abc_fre_respawn_2", "abc_fre_respawn_3", "abc_fre_respawn_4", "abc_fre_respawn_5"}
			local ban = {"abc_ban_respawn_1", "abc_ban_respawn_2", "abc_ban_respawn_3", "abc_ban_respawn_4", "abc_ban_respawn_5"}
			local mil = {"abc_mil_respawn_1", "abc_mil_respawn_2", "abc_mil_respawn_3", "abc_mil_respawn_4", "abc_mil_respawn_5"}
			local mon = {"abc_mon_respawn_1", "abc_mon_respawn_2", "abc_mon_respawn_3", "abc_mon_respawn_4", "abc_mon_respawn_5"}
			local kil = {"abc_kil_respawn_1", "abc_kil_respawn_2", "abc_kil_respawn_3", "abc_kil_respawn_4", "abc_kil_respawn_5"}

			local faction = {"fre", "ban", "mil", "mon", "kil"} 
			fac = faction[math.random(5)]
			local fac_npc
			for ccs = 1, 15 do	 
				if fac == "kil" then fac_npc = kil[math.random(5)] end
				if fac == "mil" then fac_npc = mil[math.random(5)] end
				if fac == "mon" then fac_npc = mon[math.random(5)] end
				if fac == "ban" then fac_npc = ban[math.random(5)] end
				if fac == "fre" then fac_npc = fre[math.random(5)] end
				alife():create(fac_npc, bar_spawn_pos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			end		

		end

	end
	if db.storage[db.actor:id()].pstor["bar_war"] == "yes" then
		local countfnw = db.storage[db.actor:id()].pstor["bar_war_count"]
		if countfnw == nil then countfnw = 0 end
		db.storage[db.actor:id()].pstor["bar_war_count"] = countfnw + 1

		if db.storage[db.actor:id()].pstor["bar_war_count"] == 60 and level.name() == "l05_bar" and db.actor:alive()  then
			-- news_manager.send_tip(db.actor, "abc_bar_news", 0, "abc_bar", 15000, nil)
			  local news_text = "\\n".."%c[255,160,160,160]"..game.translate_string("st_tip").." \\n".."%c[default]"..game.translate_string("abc_bar_news")
			  abc_news(news_text, "abc_bar")
		end
		if db.storage[db.actor:id()].pstor["bar_war_count"] == 90 and level.name() == "l05_bar" and db.actor:alive() then
			news_manager.send_tip(db.actor, fac.."_abc_reply", 0, "abc_"..fac, 15000, nil)
		    local news_text = "\\n".."%c[255,160,160,160]"..game.translate_string("st_tip").." \\n".."%c[default]"..game.translate_string("abc_bar_news")
		      abc_news(news_text, "abc_bar")
		end
		if db.storage[db.actor:id()].pstor["bar_war_count"] > 3600 then
			db.storage[db.actor:id()].pstor["bar_war_count"] = 0
			db.storage[db.actor:id()].pstor["bar_war"] = "no"
		end
	end
end

if w == "mil" then
	if db.storage[db.actor:id()].pstor["mil_war"] ~= "yes" and (db.lvlstartout < time_global()) then
		-- alterar para -50,100
		local randmil = math.random(-10,30)
		logf("faction wars - Mil randmil = " .. randmil)
		if randmil == 15 then
			db.storage[db.actor:id()].pstor["mil_war"] = "yes"
			local checkmilpos, checkmilpos1, checkmilpos2, checkmilpos3, checkmilpos4
			checkmilpos1 = vector():set(28, -13, 228)
			checkmilpos2 = vector():set(30, -1, 85)
			checkmilpos3 = vector():set(-150, -8, 82)
			checkmilpos4 = vector():set(45, -9, 228)
			local randpos = math.random(1,4)
			if randpos == 1 then checkmilpos = checkmilpos1 end
			if randpos == 2 then checkmilpos = checkmilpos2 end
			if randpos == 3 then checkmilpos = checkmilpos3 end
			if randpos == 4 then checkmilpos = checkmilpos4 end
			local mil_spawn_pos = checkmilpos
			if (checkbarpos1:distance_to_sqr(db.actor:position()) <= 100) then mil_spawn_pos = checkbarpos2 end
			if (checkbarpos2:distance_to_sqr(db.actor:position()) <= 100) then mil_spawn_pos = checkbarpos3 end
			if (checkbarpos3:distance_to_sqr(db.actor:position()) <= 100) then mil_spawn_pos = checkbarpos4 end

			local kil = {"abc_kil_respawn_1", "abc_kil_respawn_2", "abc_kil_respawn_3", "abc_kil_respawn_4", "abc_kil_respawn_5"}
			local mil = {"abc_mil_respawn_1", "abc_mil_respawn_2", "abc_mil_respawn_3", "abc_mil_respawn_4", "abc_mil_respawn_5"}
			local dol = {"abc_dol_respawn_1", "abc_dol_respawn_2", "abc_dol_respawn_3", "abc_dol_respawn_4", "abc_dol_respawn_5"}
			local mon = {"abc_mon_respawn_1", "abc_mon_respawn_2", "abc_mon_respawn_3", "abc_mon_respawn_4", "abc_mon_respawn_5"}

			local faction = {"dol", "mil", "mon", "kil"} 
			fac = faction[math.random(4)]
			local fac_npc
			for ccs = 1, 20 do	 
				if fac == "kil" then fac_npc = kil[math.random(5)] end
				if fac == "mil" then fac_npc = mil[math.random(5)] end
				if fac == "mon" then fac_npc = mon[math.random(5)] end
				if fac == "dol" then fac_npc = ban[math.random(5)] end
				alife():create(fac_npc, mil_spawn_pos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
			end		

		end

	end
	if db.storage[db.actor:id()].pstor["mil_war"] == "yes" then
		local countfmw = db.storage[db.actor:id()].pstor["mil_war_count"]
		if countfmw == nil then countfmw = 0 end
		db.storage[db.actor:id()].pstor["mil_war_count"] = countfmw + 1
		if db.storage[db.actor:id()].pstor["mil_war_count"] == 30 and level.name() == "l07_military" then
			 abc_news() 
		end
		if db.storage[db.actor:id()].pstor["mil_war_count"] > 3600 then
			db.storage[db.actor:id()].pstor["mil_war_count"] = 0
			db.storage[db.actor:id()].pstor["mil_war"] = "no"
		end
	end

end

end


-- func para pegar game e level vertex id
local waittelelevel = 0
local teletolevel = 0
function teleportcheck()
if waittelelevel == 0 then waittelelevel = time_global() + 5000 end
if time_global() > waittelelevel then

   -- db.actor.radiation = -1
   teletolevel = teletolevel + 1
   if teletolevel == 10 then  
	-- db.storage[db.actor:id()].pstor["joinoso"] = "no"
	-- l12u_sarcofag	wishgranter
	-- db.actor:set_character_community("bandit", 0, 0)
	-- relation_registry.set_community_goodwill ("bandit", db.actor:id(), 200)
	-- teletodlevel("l05_bar") 
		news_manager.send_tip(db.actor, "abc_bar_news", 0, "abc_bar", 15000, nil)
   end


end
end
 