Xeonmeister Posted February 21, 2016 Share Posted February 21, 2016 Hi! I've made a "play-sound-for-all" function and i'd like to know if it's possible not to play a sound for one player but for everyone else? So everyone will hear the sound except that one guy. Link to comment
Captain Cody Posted February 21, 2016 Share Posted February 21, 2016 On that mates client side use setSoundVolume(sound, 0) Sure there are plenty of other ways, I just found that first and it works. Link to comment
tosfera Posted February 21, 2016 Share Posted February 21, 2016 That's possible but I wouldn't go for CodyL's way. That'll still create the sound for the player and will take some cpu usage for his client. I would rather trigger an event for every player that should hear the sound. Link to comment
Xeonmeister Posted February 22, 2016 Author Share Posted February 22, 2016 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. Link to comment
Ab-47 Posted February 22, 2016 Share Posted February 22, 2016 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
Bonus Posted February 22, 2016 Share Posted February 22, 2016 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 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 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