--[[==============================================================
DayZ Background Sounds for MTA:DayZ by SimS
==============================================================]]--

isSpecialSoundsActivated = false -- CHANGE THIS TO "TRUE" IF YOU WANT THE "HEAVY SOUNDS" (these sounds adds about 5mb of download to the user client, and the sounds have about 1:30~2:30 minutes of duration). IF YOU DON'T WANT THEM, JUST LEAVE AS "FALSE".
soundVolume = 0.25 -- Set the sound volume. DEFAULT: 0.25 (25%) - Use from 0.0 to 1.0 (works like "percent" numbers)

-- DON'T TOUCH IN THIS LINES, OR THE SCRIPT WILL BLOW UP
normalcount = 0
specialplay = 0


function startTimer( ) -- Starts the timer to play the random sounds
	if ( specialplay == 0 ) then -- if time is defined, will play the sounds every 60 seconds (defined by 'time' variable)]]
		timeval = 60
	elseif ( specialplay == 1 ) then -- if time is defined, will play the sounds every 120 seconds (defined by 'time' variable)]]
		timeval = 120
	elseif ( specialplay == 2 ) then -- if time is defined, will play the sounds every 200 seconds (defined by 'time' variable)]]
		timeval = 200
	end
	bgtimer = setTimer(randomDayZBackgroundSounds, timeval*1000, 0)
	if ( bgtimer ~= false ) then
		outputDebugString ( "Timer's running. Will run every "..timeval.." seconds" )
	end
end
--addEvent("startTimer", true)
--addCommandHandler("iniciaTimer", startTimer)

function randomDayZBackgroundSounds () 
	if ( isSpecialSoundsActivated == true) then -- If you defined the first line as TRUE, he will alternate between short and long sound files
		if ( normalcount < 4 ) then -- if the 'short sounds' play less than 4 times, they will continue to randomize between them and play
			if ( specialplay >= 1 ) then
				killTimer ( bgtimer )
				specialplay = 0
				startTimer ( )
			end
			randnum = math.random( 0, 8 )
			normalcount = normalcount+1
		else -- if the 'short sounds' play more than 4 times, then the sounds will be randomize between "long sounds" and play ONE time only
			randnum = math.random( 9, 11)
			killTimer( bgtimer )
			if ( randnum == 11 ) then -- if the sound who will play is the 11 (2:30 minutes sound), then the timer to the next sound will be set to 200 seconds (3 minutes and 20 seconds)
				specialplay = 2
				startTimer ( )
			else -- if the sound who will play is the other sounds (~1:30 minutes sounds), then the timer to the next sound will be set to 120 seconds (2 minutes)
				specialplay = 1
				startTimer ( )
			end
			normalcount = 0
		end
	else -- If you defined the first line as FALSE, then the "long sounds" will not be played, and he will alternate only between the 'short sounds'
		randnum = math.random( 0,8 )
	end
	local bgsound = playSound("sounds/suspense/suspense_"..randnum..".ogg") --Play suspense# files from the 'sounds/suspense' folder
	setSoundVolume(bgsound, soundVolume)
end
--addCommandHandler("dayzsound", randomDayZBackgroundSounds)

addEventHandler( "onClientResourceStart", getRootElement( ), startTimer) --add the event handler


addEventHandler("onClientResourceStop", getRootElement( ), function ()
								killTimer ( bgtimer )
							  end )
