Hero192 Posted January 25, 2016 Share Posted January 25, 2016 (edited) Hello community, I made a tazer system with some guides of a guy that I know but I found a problem,when I shoot 2 shoots on the wanted before the timer of animation end the sound keep playing no stop. Please I want it stop in same time that animation stops and how to avoid that bug? thanks in advance. --Client side: local taserSound = {} local client = getLocalPlayer() function onTaserSoundPlay(attacker) taserSound[client] = playSound("taser/Fire.wav",true) if taserSound[client] and isElement(taserSound[client]) then setSoundVolume(taserSound[client], 1.0) end end addEvent("onStartTaserSound", true) addEventHandler("onStartTaserSound", root, onTaserSoundPlay) addEvent ( "destroySound", true ) addEventHandler ( "destroySound", root, function () if isElement(taserSound[client]) then destroyElement(taserSound[client]) end end) --Server side: local tazerTimers = {} local lawTeam = {["Police"]=true, ["SWAT"]=true, ["AirForce"] = true} addEventHandler("onPlayerDamage", getRootElement(), function (attacker, weapon, _, loss) if (isElement(attacker) and getElementType(attacker) == "player" and weapon and attacker ~= source) then if (getPlayerTeam(attacker) and lawTeam[getTeamName(getPlayerTeam(attacker))]) then local wanted = getPlayerWantedLevel(source) if (wanted > 0) then if (weapon and weapon == 23) then if isTimer(tazerTimers[source]) then killTimer(tazerTimers[source]) end setPedAnimation(source, "ped", "KO_shot_stom") setElementHealth(source,(getElementHealth(source) + loss)) triggerClientEvent(root,"onStartTaserSound",root,attacker) tazerTimers[source] = setTimer(function(source) if isTimer(tazerTimers[source]) then killTimer(tazerTimers[source]) end setPedAnimation(source) triggerClientEvent (root, "destroySound", root) toggleAllControls(source,true) end,2000,1,source) end end end end end) Edited January 25, 2016 by Guest Link to comment
Hero192 Posted January 25, 2016 Author Share Posted January 25, 2016 Anyone can give me a hand? Link to comment
tosfera Posted January 25, 2016 Share Posted January 25, 2016 You got a "triggerClientEvent (root, "destroySound", root) " in the server's side. Use that after you destroy the timer and it'll stop the sound too and restart it (before "onStartTaserSound" ). Or another thing you can do, check if the sound is already an element in the client's side. If so, don't restart it. Link to comment
Hero192 Posted January 25, 2016 Author Share Posted January 25, 2016 I didnt understand you well, can you do what you said by editing my code to let me know what i did wrong exactly And thanks for your reply Link to comment
ViRuZGamiing Posted January 25, 2016 Share Posted January 25, 2016 Don't know if it'll work but try this; function onTaserSoundPlay(attacker) if (taserSound[client]) then cancelEvent() else taserSound[client] = playSound("taser/Fire.wav",true) if taserSound[client] and isElement(taserSound[client]) then setSoundVolume(taserSound[client], 1.0) end end end Link to comment
Hero192 Posted January 25, 2016 Author Share Posted January 25, 2016 Not working, anyone? Link to comment
Tekken Posted January 25, 2016 Share Posted January 25, 2016 Try with this. function onTaserSoundPlay(attacker) if isElement(taserSound[client]) then return false; else taserSound[client] = playSound("taser/Fire.wav",true) if taserSound[client] and isElement(taserSound[client]) then setSoundVolume(taserSound[client], 1.0) end end end 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