---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
 zoom = false
 pau = false
 pauval = 0
 prefov = 0
 radpower = 0
 curad = 0
 next_zamer = 0
 next_pisk = 0
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------

function korobka()
  local active_item = db.actor:active_item()
  local hud = get_hud()  
  local as = device().fov
  if as < prefov-0.5 then zoom = true end
  if (as > prefov+0.5) or (as > 65) then zoom = false end
  prefov = as 
  if zoom == false then                
    if hud:GetCustomStatic("hud_ur") then
      hud:RemoveCustomStatic("hud_ur")
      hud:RemoveCustomStatic("hud_pr")
      local snd_obj = xr_sound.get_safe_sound_object([[megadevice\setoff]])
      snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
    end  
    pau = false	
  end



  if (zoom) and (active_item) and (active_item:section() == "wpn_korobka") then 
    if pau == false then
      local snd_obj = xr_sound.get_safe_sound_object([[megadevice\seton]])
      snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
      pau = true
      pauval = time_global() + 350 ------------------ задает паузу до появления на экране
      next_zamer = time_global() + 350 
      curad = db.actor.radiation
    else     
      if time_global() > pauval then
-----------------------------------------------------------------------
          if time_global() > next_zamer then
            radpower = db.actor.radiation - curad
	    curad = db.actor.radiation
            next_zamer = time_global() + 200 -------------- пауза между замерами
	    if radpower < 0 then radpower = 0 end  
          if radpower ~= 0 then
	    local snd_obj = xr_sound.get_safe_sound_object([[megadevice\tresk]])
    	    snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
          end
          end        
------------------------------------------------------------------ 
	    if (curad > 0.5) and (time_global() > next_pisk) then
              local snd_obj = xr_sound.get_safe_sound_object([[megadevice\alarm]])
      	      snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)                       	    
	      next_pisk = time_global() + 500
            end
-----------------------------------------------------------------------------------------
        local txtur = "00.0000"
        local txtpr = "0.00000"
    	local ur=db.actor.radiation * 100
      	local pos,pos2 = string.find(""..ur,".",1,1)
      	if pos ~= nil and pos2 ~= nil then
          txtur = string.sub(""..ur,1,pos+4)
          if ur < 10 then txtur = "0"..txtur end
        end 
      	pos,pos2 = string.find(""..radpower,".",1,1)
      	if pos ~= nil and pos2 ~= nil then
          txtpr = string.sub(""..radpower,1,pos+5)
        end    
        if hud:GetCustomStatic("hud_ur") == nil then
          hud:AddCustomStatic("hud_ur", true)
	  hud:AddCustomStatic("hud_pr", true)
        end  
        hud:GetCustomStatic("hud_ur"):wnd():SetText(""..txtur) 
	hud:GetCustomStatic("hud_pr"):wnd():SetText(""..txtpr) 
      end        
    end
  end


end

