--[[ -----------------------------------------------------------------------------------------------
 File       : xr_garmon.script
 Description: GG+garmoshka
 Copyright  : 2010 © ФеНиКс - основа, ALEX BOY - реализация
 Author     : Starter, ВЛАД ,ФеНиКс, ALEX BOY ,Shadows
 Last update: 02.07.2010(by ФеНиКс) и (by ALEX BOY) 
--]]-----------------------------------------------------------------------------------------------


local device_active = true
local snd_obj,react

function item_update()
    local item = db.actor:active_item()
    if not (item and item:section() == "garmoshka_b") then
        if snd_obj and snd_obj:playing() then
            snd_obj:stop()
        end
        return
    end
    if device_active then
        snd_obj = sound_object("characters_voice\\human_01\\bandit\\music\\harmonica_"..tostring(math.random(1,8)))  
        snd_obj:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
    for k, v in pairs (db.storage) do
        local stalker = level.object_by_id(k)
        if (stalker and IsStalker(stalker)) then
            if stalker:position():distance_to(db.actor:position()) < 10 then
                if not snd_obj:playing() then
                    react = sound_object("characters_voice\\human_01\\stalker\\reactions\\music\\reaction_music_"..tostring(math.random(1,7)))  
                    react:play_at_pos(stalker, stalker:position(), sound_object.s2d)
                    react.volume = 0.8
                end
            end
        end
    end
        device_active = false
    else
        if not snd_obj:playing() then
            device_active = true
        end
    end
end















-------------------
--function play_zvuk()
--local act = db.actor
--local os = act:position()
--for id,o in pairs(db.storage) do--for id=1,65534 do	
--local obj = level.object_by_id(id)
--if obj and IsStalker(obj) and obj:alive() and obj.health > 0.1 and  --then 
--obj:position():distance_to(db.actor:position()) < 1 then		--if 
 -- news_manager.send_tip(db.actor, "ВСЁ НОРМ!", 0, "default", 8000)
 -- else --/ ошибка спавна
  --  news_manager.send_tip(db.actor, "ПИЗДОС! ошибка...", 0, "default", 8000)
--local snd_obj0 = sound_object("characters_voice\\human_01\\stalker\\reactions\\music\\reaction_music_"..tostring(math.random(1,7)))
--snd_obj0:play_at_pos(db.actor, vector():set(0,0,0), 0, sound_object.s2d)
--end
--end
--end
--end
