Welf Posted June 23, 2020 Posted June 23, 2020 Olá Galera, to editando esse script que quando alguem colidir com um veiculo desligado na rua ele dispara o alarme, no entanto, notei que se um veiculo tiver disparado, o outro ao lado que eu bater fica mudo ou não dispara, alguem pode ajudar? Client-side: addEventHandler("onClientVehicleCollision", getRootElement(), function (_,force) local x,y,z = getElementPosition(source) local fDamageMultiplier = getVehicleHandling(source).collisionDamageMultiplier local hitforce = force*fDamageMultiplier if (hitforce > 5) then if (getVehicleEngineState(source) == false) then if not (sound) then sound = playSound3D("alarm.mp3", x, y, z, false) setSoundMaxDistance(sound,70) attachElements(sound,source) else if (isSoundFinish(sound)==true) then destroyElement(sound) sound = playSound3D("alarm.mp3", x, y, z, false) setSoundMaxDistance(sound,70) attachElements(sound,source) end end end end end )
ber Posted June 23, 2020 Posted June 23, 2020 Poderia reformular sua pergunta? Pois pra mim não ficou muito claro seu problema. O alarme só dispara uma vez? Tipo, se um veículo estiver disparado e você bater em outro ele não vai disparar nesse mais recente?
Welf Posted June 23, 2020 Author Posted June 23, 2020 8 minutes ago, ber said: Poderia reformular sua pergunta? Pois pra mim não ficou muito claro seu problema. O alarme só dispara uma vez? Tipo, se um veículo estiver disparado e você bater em outro ele não vai disparar nesse mais recente? Perdão pela má formulação, mas é exatamente isso que disse! O alarme só dispara uma vez por veículo! se um veículo estiver disparado e você bater em outro ele não vai disparar nesse mais recente! ele só vai disparar nesse mais recente quando o alarme (alarm.mp3) terminar de tocar no veiculo anterior.
ber Posted June 30, 2020 Posted June 30, 2020 (edited) Aparentemente o que tinha de errado no seu script é que ele está checando se o som está rodando no seu Client e não no veículo, para alterar isso ao invés de usar um 'if (sound)' use um if getElementData(source, "alarm") Não testei mas creio que está funcionando: function colission( force ) local x,y,z = getElementPosition(source) local fDamageMultiplier = getVehicleHandling(source).collisionDamageMultiplier local hitforce = force*fDamageMultiplier if (hitforce > 5) then if (getVehicleEngineState(source) == false) then if getElementData(source, "alarm") == false then sound = playSound3D("alarm.mp3", x, y, z, false) setSoundMaxDistance(sound,70) attachElements(sound,source) setElementData(source, "alarm", true) setTimer(function() setElementData(source, "alarm", false) end, 30000, 1) -- < ALTERE PARA O TEMPO QUE DURA O ALARME end end end end addEventHandler("onClientVehicleCollision", root, colission) Espero ter ajudado Edited June 30, 2020 by ber 1
Welf Posted June 30, 2020 Author Posted June 30, 2020 6 minutes ago, ber said: Não testei mas creio que está funcionando: function colission( force ) local x,y,z = getElementPosition(source) local fDamageMultiplier = getVehicleHandling(source).collisionDamageMultiplier local hitforce = force*fDamageMultiplier if (hitforce > 5) then if (getVehicleEngineState(source) == false) then if getElementData(source, "alarm") == false then sound = playSound3D("alarm.mp3", x, y, z, false) setSoundMaxDistance(sound,70) attachElements(sound,source) setElementData(source, "alarm", true) setTimer(function() setElementData(source, "alarm", false) end, 30000, 1) -- < ALTERE PARA O TEMPO QUE DURA O ALARME end end end end addEventHandler("onClientVehicleCollision", root, colission) Espero ter ajudado Funcionou perfeito! Valeu!
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