Jump to content

StopSound Using GetTime


Siriius

Recommended Posts

 

Eh attempted to reproduce the sound at a certain time, once the playback is finished, do not play again unless the cycle is restarted (or re-do the indicated time). But the error gives that when finishing the reproduction continues reproducing again and again.
 

Sry for my bad englis

function Nightmare() 
    local sound = playSound("Night.mp3",true)
	local gateTimer = getTime() 
    if (gateTimer >= 22) then 
        outputChatBox( "Esta anocheciendo. . .", 80, 80, 200 )
		if (gateTimer < 22) then
    stopSound ( sound ) 
end 
end 
end
setTimer(Nightmare, 73000, 0) 

 

Edited by >[G]eoX<
Language
Link to comment

Might work.

local minDuration = getMinuteDuration()
local _, timeminute = getTime()
local minuteTimer = (60-timeminute)*minDuration
setTimer(Nightmare, minuteTimer, 1)

function Nightmare() 
	local gateTimer = getTime() 
	if (gateTimer == 22) then -- Only play the sound at 22
		local sound = playSound("Night.mp3",true)
		outputChatBox( "Esta anocheciendo. . .", 80, 80, 200 )
	end
	setTimer(Nightmare, 60*minDuration, 1) -- This will check the time every minute in game time
end
Link to comment
6 minutes ago, idarrr said:

Might work.


local minDuration = getMinuteDuration()
local _, timeminute = getTime()
local minuteTimer = (60-timeminute)*minDuration
setTimer(Nightmare, minuteTimer, 1)

function Nightmare() 
	local gateTimer = getTime() 
	if (gateTimer == 22) then -- Only play the sound at 22
		local sound = playSound("Night.mp3",true)
		outputChatBox( "Esta anocheciendo. . .", 80, 80, 200 )
	end
	setTimer(Nightmare, 60*minDuration, 1) -- This will check the time every minute in game time
end

 

I had previously tried to place it at an exact time but it did not reproduce the music and the message. And no, it does not work

Link to comment
local minDuration = getMinuteDuration()
local _, timeminute = getTime()
local minuteTimer = (60-timeminute)*minDuration

function Nightmare() 
	local gateTimer = getTime() 
	if (gateTimer == 22) then -- Only play the sound at 22
		local sound = playSound("Night.mp3",true)
		outputChatBox( "Esta anocheciendo. . .", 80, 80, 200 )
	end
	setTimer(Nightmare, 60*minDuration, 1) -- This will check the time every minute in game time
end
setTimer(Nightmare, minuteTimer, 1)

 

Link to comment
7 minutes ago, idarrr said:

local minDuration = getMinuteDuration()
local _, timeminute = getTime()
local minuteTimer = (60-timeminute)*minDuration

function Nightmare() 
	local gateTimer = getTime() 
	if (gateTimer == 22) then -- Only play the sound at 22
		local sound = playSound("Night.mp3",true)
		outputChatBox( "Esta anocheciendo. . .", 80, 80, 200 )
	end
	setTimer(Nightmare, 60*minDuration, 1) -- This will check the time every minute in game time
end
setTimer(Nightmare, minuteTimer, 1)

 

 

After it finishes, it reproduces again, even though it is more than 22 Probe this way and work for me. I do not know if it would give me a problem in the future.

setTimer(function()
local h, m = getTime() 
if ( h == 22 ) then 
if not yes then
sound = playSound("Night.mp3", false )
yes = true 
end
else 
yes = false
end
end, 3000, 0)

 

Link to comment

Yeah that works. But checking every 3 seconds isn't good idea. The one I gave to you is working on me. But it seems that the timer doesn't sync with GTA time. So this is works perfectly on my localhost.

local minDuration = getMinuteDuration()
local _, timeminute = getTime()
local minuteTimer = (61-timeminute)*minDuration


function Nightmare() 
	local hour, minute = getTime() 
	if (hour == 22) then -- Only play the sound at 22
		local sound = playSound("Night.mp3",true)
		outputChatBox( "Esta anocheciendo. . .", 80, 80, 200 )
	end
	local minuteTimer = (61-minute)*minDuration
	setTimer(Nightmare, minuteTimer, 1) -- This will check the time every minute in game time
end
setTimer(Nightmare, minuteTimer, 1)

 

Link to comment
4 minutes ago, idarrr said:

Yeah that works. But checking every 3 seconds isn't good idea. The one I gave to you is working on me. But it seems that the timer doesn't sync with GTA time. So this is works perfectly on my localhost.


local minDuration = getMinuteDuration()
local _, timeminute = getTime()
local minuteTimer = (61-timeminute)*minDuration


function Nightmare() 
	local hour, minute = getTime() 
	if (hour == 22) then -- Only play the sound at 22
		local sound = playSound("Night.mp3",true)
		outputChatBox( "Esta anocheciendo. . .", 80, 80, 200 )
	end
	local minuteTimer = (61-minute)*minDuration
	setTimer(Nightmare, minuteTimer, 1) -- This will check the time every minute in game time
end
setTimer(Nightmare, minuteTimer, 1)

 

 

It is if it works, but the sound continues to play even after 22

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...