SoManyTears Posted May 5, 2020 Share Posted May 5, 2020 I want this sound to play only in the cities that are there.But even when I enter las venturas or los santos, the sound does not stop.can someone help me ? cities = { ["Bone County"] = true, ["Red County"] = true, ["Tierra Robada"] = true, ["Flint County"] = true, ["Whetstone"] = true, } function change_weather() local x,y,z = getElementPosition(localPlayer) local city = getZoneName(x,y,z, true) if cities[city] then local sound = playSound("ambiance.mp3",true) else stopSound (sound) end end setTimer(change_weather, 1000, 1) Link to comment
Moderators IIYAMA Posted May 5, 2020 Moderators Share Posted May 5, 2020 (edited) @SoManyTears Because the local declaration ensures that the value is deleted at the end of the function. if cities[city] then if not isElement(sound) then sound = playSound("ambiance.mp3",true) end elseif isElement(sound) then stopSound (sound) sound = nil end setTimer(change_weather, 1000, 0) -- 1 too 0 Edited May 5, 2020 by IIYAMA 1 Link to comment
KronoS Lettify Posted May 5, 2020 Share Posted May 5, 2020 (edited) 2 minutes ago, IIYAMA said: @SoManyTears Because the local declaration ensures that the value is deleted at the end of the function. if cities[city] then if not isElement(sound) then sound = playSound("ambiance.mp3",true) end elseif isElement(sound) then stopSound (sound) sound = nil end You're fast Edited May 5, 2020 by KronoS Lettify 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