Jump to content

Guys I need Help


Hero192

Recommended Posts

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 by Guest
Link to comment

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...