Jump to content

Help! Weather nature night and day sounds


No4NaMe

Recommended Posts

function Nightmare() 
		local hour,minutes = getTime()
        if hour == 06 and minutes == 0 then 
            local sound = playSound("day.mp3") 
        else
		if hour == 12 and minutes == 0 then 
            local sound = playSound("day.mp3")  
        else
		if hour == 15 and minutes == 0 then 
            local sound = playSound("night.mp3") 
        else
		if hour == 20 and minutes == 0 then 
            local sound = playSound("night.mp3") 
	--setSoundVolume(sound,50.0)
	end
	end
	addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),Nightmare)
	setTimer(sound, 12000,0)  
	end
	end
	end

Tell me what's wrong with this script, at the specified time the music does not want to play!

Link to comment
function Nightmare() 
		local hour,minutes = getTime()
        if hour == 06 and minutes == 0 then 
            local sound = playSound("day.mp3") 
        elseif
			hour == 12 and minutes == 0 then 
            local sound = playSound("day.mp3")  
        elseif
			hour == 15 and minutes == 0 then 
            local sound = playSound("night.mp3") 
        elseif
        	hour == 20 and minutes == 0 then 
            local sound = playSound("night.mp3") 
			--setSoundVolume(sound,50.0)
		end
	end
	addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),Nightmare)
	setTimer(sound, 12000,0)  

 

Link to comment
  • Moderators
function Nightmare()
	setTimer(sound, 900,0)
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),Nightmare) 

function sound()
	local hour,minutes = getTime()
	if hour == 06 and minutes == 0 then 
		playSound("day.mp3") 
	elseif hour == 12 and minutes == 0 then 
		playSound("day.mp3")  
	elseif hour == 15 and minutes == 0 then 
		playSound("night.mp3") 
	elseif hour == 20 and minutes == 0 then 
		playSound("night.mp3") 
		--setSoundVolume(sound,50.0)
	end
end

Try it.

Link to comment
On ١٣‏/٣‏/٢٠١٨ at 04:44, No4NaMe said:

Tell me what's wrong with this script, at the specified time the music does not want to play!

function Nightmare( ) 
	local hour,minutes = getTime( )
	if ( hour >= 6 ) and ( hour < 12 ) then 
		local sound = playSound ( "day.mp3" ) 
	elseif ( hour >= 12 ) and ( hour < 15 ) then 
		local sound = playSound ( "day.mp3" )  
	elseif ( hour >= 15 ) and ( hour < 20 ) then 
		local sound = playSound ( "night.mp3" ) 
	elseif ( hour >= 20 ) and ( hour < 24 ) then 
		local sound = playSound ( "night.mp3" ) 
	end
	setTimer(function()
		if ( isElement ( sound ) ) then 
			destroyElement ( sound ) 
		end 
	end , 3000 , 1 )
end
addEventHandler ( "onClientResourceStart" , resourceRoot , Nightmare )

 

20 hours ago, DNL291 said:

function Nightmare()
	setTimer(sound, 900,0)
end
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),Nightmare) 

function sound()
	local hour,minutes = getTime()
	if hour == 06 and minutes == 0 then 
		playSound("day.mp3") 
	elseif hour == 12 and minutes == 0 then 
		playSound("day.mp3")  
	elseif hour == 15 and minutes == 0 then 
		playSound("night.mp3") 
	elseif hour == 20 and minutes == 0 then 
		playSound("night.mp3") 
		--setSoundVolume(sound,50.0)
	end
end

Try it.

how the sound will start?

  • Confused 1
Link to comment
10 hours ago, Debo15 said:

function Nightmare( ) 
	local hour,minutes = getTime( )
	if ( hour >= 6 ) and ( hour < 12 ) then 
		local sound = playSound ( "day.mp3" ) 
	elseif ( hour >= 12 ) and ( hour < 15 ) then 
		local sound = playSound ( "day.mp3" )  
	elseif ( hour >= 15 ) and ( hour < 20 ) then 
		local sound = playSound ( "night.mp3" ) 
	elseif ( hour >= 20 ) and ( hour < 24 ) then 
		local sound = playSound ( "night.mp3" ) 
	end
	setTimer(function()
		if ( isElement ( sound ) ) then 
			destroyElement ( sound ) 
		end 
	end , 3000 , 1 )
end
addEventHandler ( "onClientResourceStart" , resourceRoot , Nightmare )

 

how the sound will start?

no work

Link to comment

and

    function playTimeSound()  
        local hour, minutes = getTime() 
        if hour == 06 and minutes == 0 then 
            local timesound = playSound(":DayZ/sounds/ambience/day.mp3",true) 
        elseif hur == 12 and minutes == 0 then 
            local timesound = playSound(":DayZ/sounds/ambience/day.mp3",true) 
        elseif hour == 15 and minutes == 0 then 
            local timesound = playSound(":DayZ/sounds/ambience/day.mp3",true) 
        elseif hour == 20 and minutes == 0 then 
            local timesound = playSound(":DayZ/sounds/ambience/night.mp3",true) 
			setSoundVolume(timesound,gameplayVariables["ambiencesoundvolume"])
        end 
    end 
addEventHandler("onClientRender", getRootElement(), playTimeSound )

no work

Link to comment
3 minutes ago, Debo15 said:

Write meta script here

<meta>
    <!-- sounds folder -->    
    <script src="sounds_c.lua" type="client" cache="false" />
    <file type="client" src="day.mp3" />
    <file type="client" src="night.mp3" />
</meta>

Link to comment
19 hours ago, Debo15 said:

function Nightmare( ) 
	local hour,minutes = getTime( )
	if ( hour >= 6 ) and ( hour < 12 ) then 
		local sound = playSound ( "day.mp3" ) 
	elseif ( hour >= 12 ) and ( hour < 15 ) then 
		local sound = playSound ( "day.mp3" )  
	elseif ( hour >= 15 ) and ( hour < 20 ) then 
		local sound = playSound ( "night.mp3" ) 
	elseif ( hour >= 20 ) and ( hour < 24 ) then 
		local sound = playSound ( "night.mp3" ) 
	end
	setTimer(function()
		if ( isElement ( sound ) ) then 
			destroyElement ( sound ) 
		end 
	end , 3000 , 1 )
end
addEventHandler ( "onClientResourceStart" , resourceRoot , Nightmare )

 

how the sound will start?

no works

Link to comment
local sound
function playBackgroundSound()
    if sound and isElement(sound) then stopSound(sound) end
 	local hour,minutes = getTime( )
 	if hour >= 6 and hour < 12 then 
		sound = playSound ( "day.mp3" ) 
	elseif ( hour >= 12 ) and ( hour < 15 ) then 
		sound = playSound ( "day.mp3" )  
	elseif ( hour >= 15 ) and ( hour < 20 ) then 
		sound = playSound ( "night.mp3" ) 
	elseif ( hour >= 20 ) and ( hour < 24 ) then 
		sound = playSound ( "night.mp3" ) 
	end
end
setTimer(playBackgroundSound, 600000, 0)
setTimer(playBackgroundSound, 500, 1)

Try.

Edited by Spc
Link to comment
12 hours ago, Spc said:

local sound
function playBackgroundSound()
    if sound and isElement(sound) then stopSound(sound) end
 	local hour,minutes = getTime( )
 	if hour >= 6 and hour < 12 then 
		sound = playSound ( "day.mp3" ) 
	elseif ( hour >= 12 ) and ( hour < 15 ) then 
		sound = playSound ( "day.mp3" )  
	elseif ( hour >= 15 ) and ( hour < 20 ) then 
		sound = playSound ( "night.mp3" ) 
	elseif ( hour >= 20 ) and ( hour < 24 ) then 
		sound = playSound ( "night.mp3" ) 
	end
end
setTimer(playBackgroundSound, 600000, 0)
setTimer(playBackgroundSound, 500, 1)

Try.

and no work xD

Just now, No4NaMe said:

and no work xD

and weather sound my code work

local weathersounds = {
	--":DayZ/sounds/ambience/thunder.mp3",
	":DayZ/sounds/ambience/crow.mp3",
}
function WeatherSound()
if PlayWeatherSound and isElement(PlayWeatherSound) then stopSound(PlayWeatherSound) end
local weatherID = getWeather() 
    if weatherID == 4 or weatherID == 7 or weatherID == 12 or weatherID == 15 then  
        local PlayWeatherSound = playSound(weathersounds[math.random(1,#weathersounds)]) 
		setSoundVolume(PlayWeatherSound,gameplayVariables["ambiencesoundvolume"])
    end 
end 
addEventHandler ("onClientRender",resourceRoot,WeatherSound)
setTimer(WeatherSound,70000,0)

 

Link to comment
2 hours ago, Spc said:

The sound is added to the meta? Maybe file is broken or you pasting this code to the server-side. The script must be on client-side.

everything is done correctly some code works, and the one that needs to stop after the specified time does not work

Link to comment
On 15.03.2018 at 21:51, Spc said:

local sound
function playBackgroundSound()
    if sound and isElement(sound) then stopSound(sound) end
 	local hour,minutes = getTime( )
 	if hour >= 6 and hour < 12 then 
		sound = playSound ( "day.mp3" ) 
	elseif ( hour >= 12 ) and ( hour < 15 ) then 
		sound = playSound ( "day.mp3" )  
	elseif ( hour >= 15 ) and ( hour < 20 ) then 
		sound = playSound ( "night.mp3" ) 
	elseif ( hour >= 20 ) and ( hour < 24 ) then 
		sound = playSound ( "night.mp3" ) 
	end
end
setTimer(playBackgroundSound, 600000, 0)
setTimer(playBackgroundSound, 500, 1)

Try.

sound is played once, not by time

Link to comment
3 hours ago, No4NaMe said:

sound is played once, not by time

local sound
local time = 0
function playBackgroundSound()
 	local hour,minutes = getTime( )
 	if hour >= 6 and hour < 12 then 
 		if time == 0 or (time ~= 1 and isElement(sound)) then 
        	stopSound(sound)
			sound = playSound ( "day.mp3",true ) 
   		end
		time = 1
	elseif ( hour >= 12 ) and ( hour < 15 ) then 
		if  time == 0 or (time ~= 1 and isElement(sound)) then 
   		 	stopSound(sound) 
    		sound = playSound ( "day.mp3",true ) 
  		end 
		time = 1
	elseif ( hour >= 15 ) and ( hour < 20 ) then 
		if  time == 0 or (time ~= 2 and isElement(sound)) then 
    		stopSound(sound) 
    		sound = playSound ( "night.mp3",true ) 
  		end
		time = 2
	elseif ( hour >= 20 ) and ( hour < 24 ) then 
		if  time == 0 or (time ~= 2 and isElement(sound)) then 
    		stopSound(sound) 
    		sound = playSound ( "night.mp3",true ) 
 		 end
		time = 2
	end
end
setTimer(playBackgroundSound, 600000, 0)
setTimer(playBackgroundSound, 500, 1)

Try it.

Edited by Spc
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...