WeeD1 Posted April 30, 2019 Posted April 30, 2019 Olá rapaziada, estou com um erro em um mod de radio, mas não sei como resolver. Fiz diversos testes no servidor, e percebi que o erro ocorre pois ele está tentando parar um som que já está parado, pois ao terminar uma música, se a pessoa apertar o botão para desligar o radio, ele vai acusar esse erro. Alguém que consiga me ajudar com isso? Não tenho muito conhecimento nessa parte que envolve som. WARNING: Radio/cVehRadio.lua:6:Bad argument @ 'stopSound' [Expected sound at argument 1] addEvent("onServerToggleRadio", true) addEventHandler("onServerToggleRadio", getLocalPlayer(), function(toggle, url, veh, volume) if not isElement(veh) then if radioSound[veh] ~= nil then stopSound(radioSound[veh].soundElement) radioSound[veh].soundElement = nil end return end if toggle == true then local x, y, z = getElementPosition(veh) if radioSound[veh] ~= nil then if radioSound[veh].soundElement ~= nil then stopSound(radioSound[veh].soundElement) end local sound = playSound3D(url, x, y, z) if volume ~= nil then setSoundVolume(sound, volume) end setSoundMinDistance(sound, 10.3) setSoundMaxDistance(sound, 32.8) attachElements(sound, veh) radioSound[veh] = { } radioSound[veh].soundElement = sound else local sound = playSound3D(url, x, y, z) if volume ~= nil then setSoundVolume(sound, volume) end setSoundMinDistance(sound, 10.2) setSoundMaxDistance(sound, 31.6) attachElements(sound, veh) radioSound[veh] = { } radioSound[veh].soundElement = sound end else if radioSound[veh] ~= nil then if radioSound[veh].soundElement ~= nil then stopSound(radioSound[veh].soundElement) radioSound[veh].soundElement = nil end end end end )
Jonas^ Posted April 30, 2019 Posted April 30, 2019 Verifique se existe um som em andamento, if isElement (radioSound[veh].soundElement) then -- Se existir um som em andamento, então: stopSound(radioSound[veh].soundElement) -- Para o som atual. radioSound[veh].soundElement = nil -- Anula a variavel para liberar espaço na memoria. end Nem tinha visto a linha 1 1
DNL291 Posted April 30, 2019 Posted April 30, 2019 Você pode fazer adicionar isto no código @WeeD1: local _stopSound = stopSound function stopSound( s ) if isElement(s) then return _stopSound( s ) end end Vai evitar mensagens de erro quando parar o som. 1 1
Jonas^ Posted April 30, 2019 Posted April 30, 2019 8 minutes ago, DNL291 said: Você pode fazer adicionar isto no código @WeeD1: local _stopSound = stopSound function stopSound( s ) if isElement(s) then return _stopSound( s ) end end Vai evitar mensagens de erro quando parar o som. Eu sempre faço direto a verificação na função, nunca usei desta forma, parece ser melhor. 1
DNL291 Posted April 30, 2019 Posted April 30, 2019 44 minutes ago, Jonas^ said: Eu sempre faço direto a verificação na função, nunca usei desta forma, parece ser melhor. É melhor assim quando se utiliza várias vezes stopSound. Outra útil é pra função destroyElement: local _destroyElement = destroyElement function destroyElement( element ) if isElement(s) then return _destroyElement( element ) end end 1
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