Siriius Posted June 1, 2017 Share Posted June 1, 2017 (edited) 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 June 1, 2017 by >[G]eoX< Language Link to comment
idarrr Posted June 1, 2017 Share Posted June 1, 2017 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
Siriius Posted June 1, 2017 Author Share Posted June 1, 2017 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
idarrr Posted June 1, 2017 Share Posted June 1, 2017 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
Siriius Posted June 1, 2017 Author Share Posted June 1, 2017 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
idarrr Posted June 1, 2017 Share Posted June 1, 2017 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
Siriius Posted June 1, 2017 Author Share Posted June 1, 2017 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
idarrr Posted June 1, 2017 Share Posted June 1, 2017 Yeah of course, because the sound is set to loop. Replace with this one. -- This sound will play once local sound = playSound("Night.mp3", false) 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now