--[[
Copyright: © SomeFaggot, Gmod4Ever, Ирбиs, Real Wolf
]]

local holster_time_upd = nil
local hided = false

function start(obj)
	lwc_bdet.used(obj)
	snd = xr_sound.get_safe_sound_object([[$no_sound]])
	if (db.actor ~= nil) and (obj ~= nil) then

		if obj:section() == "medkit" or obj:section() == "medkit_army" or obj:section() == "medkit_scientic" then
				holster_time = 4000
				soundhub(obj)
			
		elseif obj:section() == "army_fast" or obj:section() == "army_food"  then
				holster_time = 5000
				soundhub(obj)
			
                elseif obj:section() == "pervitin"  then
				holster_time = 3000
				soundhub(obj)

                elseif obj:section() == "repair_kit" then
				snd= xr_sound.get_safe_sound_object([[inv_sounds\inv_use]])
				holster_time = 2000
				soundhub(obj)  
 
                elseif obj:section() == "inv_ruck" then
				snd= xr_sound.get_safe_sound_object([[inv_sounds\inv_ruck]])
				holster_time = 2000	
				soundhub(obj)
				local ruck = alife():create("active_ruck", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id())
				level.map_add_object_spot_ser(ruck.id, "red_location", "%c[255,238,155,23]Мой тайник для хабара")
				news_manager.send_tip(db.actor, "Тайник заложен.", nil, nil, 5000)
				
				elseif obj:section() == "mil_scanner_2" then
				if has_alife_info("kontra") and has_alife_info("nabat_on") then
					db.actor:give_info_portion("teleport_hram_1")
				end
				snd= xr_sound.get_safe_sound_object([[inv_sounds\inv_ruck]])
				holster_time = 2000	
				soundhub(obj)
				local ruck = alife():create("mil_scanner_2", db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id())

                elseif obj:section() == "antirad" or obj:section() == "amfetamin" or obj:section() == "antiseptic" then
				holster_time = 3000
				soundhub(obj)
	
		elseif obj:section() == "bandage" or obj:section() == "zhgut" then
				snd= xr_sound.get_safe_sound_object([[inv_sounds\inv_bandage]])
				holster_time = 5000
				soundhub(obj)
			
		elseif obj:section() == "vodka" then
				snd= xr_sound.get_safe_sound_object([[inv_sounds\inv_vodka]])
				holster_time = 4000
				soundhub(obj)
				amk_mod.test_for_need_sleep_vodka()

		elseif obj:section() == "det_accum" then
				snd= xr_sound.get_safe_sound_object([[inv_sounds\inv_accum]])
				holster_time = 3000
				soundhub(obj)
				lwc_accum.accum_binder():use_accum()
			
		elseif obj:section() == "energy_drink" then
				holster_time = 4000
				soundhub(obj)
				amk_mod.test_for_need_sleep_nrg()

		elseif obj:section() == "mineralka" then
				snd= xr_sound.get_safe_sound_object([[inv_sounds\inv_softdrink]])
				holster_time = 4000
				soundhub(obj)
			
		elseif obj:section() == "bread" or obj:section() == "conserva" or obj:section() == "kolbasa" or obj:section() == "sgus" then
				snd= xr_sound.get_safe_sound_object([[inv_sounds\inv_food]])
				holster_time = 7000
				soundhub(obj)

		elseif obj:section() == "matras" then			
				amk_mod.test_for_need_sleep_matras()

		elseif obj:section() == "pre_polubor_kaps" then
				if has_alife_info("pre_polubor_quest_camp") then
					amk.spawn_item_in_inv("pre_polubor_kaps_full")
				else
					amk.spawn_item_in_inv("pre_polubor_kaps")
					news_manager.send_tip(db.actor, "Нужно брать воду в другом месте", nil, nil, 5000)
				end

		elseif obj:section() == "sta_lebedev_pda" then
				if not has_alife_info("upi_about_lebedev_quest_end") then
					db.actor:give_info_portion("upi_about_lebedev_quest_end")
				end
				lwc.PlaySound([[script_replics\story_sound_lebedev]])
				amk.spawn_item_in_inv("sta_lebedev_pda")
					 
		elseif obj:section() == "dev_rad" then
				snd= xr_sound.get_safe_sound_object([[inv_sounds\inv_accum]])
				holster_time = 4000
				soundhub(obj)
				local rad = math.floor(db.actor.radiation * 100)
				news_manager.send_tip(db.actor, "Степень заражённости организма составляет "..rad.." мкР.", nil, "dev_rad", 5000)
				amk.spawn_item_in_inv("dev_rad")						 
		end
	end
end

function soundhub(obj)
	if db.actor:alive() then
		snd:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
		snd = xr_sound.get_safe_sound_object([[$no_sound]])
		if not hided then
			db.actor:hide_weapon()
			hided = true
		end
		medkit_use.used_item(obj)
		holster_time_upd = time_global() + holster_time
		weapontimer()
	end
end

function weapontimer()
	if holster_time_upd and holster_time_upd <= time_global() then
		holster_time_upd = nil
		holster_time = 0
		hided = false
		db.actor:restore_weapon()
	end
end
