Jump to content

Play sound for everyone except one player


Xeonmeister

Recommended Posts

I've managed to do it. I only needed to trigger a server event and bring a variable that contains the element of the player. From there i trigger a client event where that variable will be examined and if it s the player then the sound won t be played.

Just use element data, set that single players element data to something, then run a loop to get all players, play the sound for players that are not in that element data. Like

setElementData(getPlayerFromName("playerThatWontHear", "allowed", true)

for k, v in pairs(getElementsByType("player")) do

if (not getElementData(v, "allowed")) then

playSound(...)

end

end

Link to comment

Element data is a bit useless here, if you want to save the players, just use a table.

Also your code is a bit .. well ... wrong o.O

What are you even trying to do there?

Just loop all players and ask if its the one player ... Like tosfera wrote:

addCommandHandler ( "playsound", function ( player, cmd, nottarget )  
     if nottarget and nottarget ~= "" then 
          local nottargetpl = getPlayerFromName ( nottarget )  
          if notttargetpl then 
               local players = getElementsByType ( "player" ) 
               for i=1, #players do 
                    if players[i] ~= nottargetpl then 
                          triggerClientEvent ( players[i], "playthesound", player ) 
                    end 
               end 
          else 
               outputChatBox ( "The player does't exist!", player, 155 ) 
          end 
     else 
          triggerClientEvent ( "playthesound", player )  
     end 
end ) 

Edit:

Oh, you already did it :D

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...