Wortex Posted October 16, 2012 Share Posted October 16, 2012 Hello everyone. How does one change the radius of default voice chat resource? I don't really want people to speak to each other miles away, so the question is: How to limit them by radius? Details: If a guy is speaking, the other player can't hear what hes saying because hes not in the radius and vice versa, but if they both come to the same place or close to each other (defined by the radius), they can communicate and chat. Link to comment
Renkon Posted October 16, 2012 Share Posted October 16, 2012 Check onPlayerChat radius example. local nearbyPlayers = {} addEventHandler( 'onPlayerVoiceStart', root, function() local r = 20 -- We get users' position local posX, posY, posZ = getElementPosition( source ) -- create a sphere of the specified radius in that position local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) -- get a table all player elements inside it nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) -- and destroy the sphere, since we're done with it destroyElement( chatSphere ) -- We create a ColSphere -- We get next Empty channel local empty = exports.voice:getNextEmptyChannel ( ) exports.voice:setPlayerChannel(source, empty) -- We have playerList. Now what? Simple, we set them in a empty channel but first we egt current channel for index, player in ipairs (nearbyPlayers) do -- Supposing they are in the main channel (this wont work if they aren't. or bah, wont' work correctly ;D exports.voice:setPlayerChannel(player, empty) end end) -- So after that... addEventHandler("onPlayerVoiceStop",root, function() -- We set those playas back :3 exports.voice:setPlayerChannel(source) for index, player in ipairs (nearbyPlayers) do -- Going to lobby exports.voice:setPlayerChannel(player) end -- We clear the table nearbyPlayers = {} end) UNTESTED Link to comment
Wortex Posted October 17, 2012 Author Share Posted October 17, 2012 Check onPlayerChat radius example. local nearbyPlayers = {} addEventHandler( 'onPlayerVoiceStart', root, function() local r = 20 -- We get users' position local posX, posY, posZ = getElementPosition( source ) -- create a sphere of the specified radius in that position local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) -- get a table all player elements inside it nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) -- and destroy the sphere, since we're done with it destroyElement( chatSphere ) -- We create a ColSphere -- We get next Empty channel local empty = exports.voice:getNextEmptyChannel ( ) exports.voice:setPlayerChannel(source, empty) -- We have playerList. Now what? Simple, we set them in a empty channel but first we egt current channel for index, player in ipairs (nearbyPlayers) do -- Supposing they are in the main channel (this wont work if they aren't. or bah, wont' work correctly ;D exports.voice:setPlayerChannel(player, empty) end end) -- So after that... addEventHandler("onPlayerVoiceStop",root, function() -- We set those playas back :3 exports.voice:setPlayerChannel(source) for index, player in ipairs (nearbyPlayers) do -- Going to lobby exports.voice:setPlayerChannel(player) end -- We clear the table nearbyPlayers = {} end) UNTESTED Fixed by changing local r, to chatRadius Link to comment
Wortex Posted October 18, 2012 Author Share Posted October 18, 2012 Yes, it actually works Quite good too. Thing is, its kinda awkward without the smoothing. Image if you'd drive by someone and you'd hear instant screaming. I wonder if its possible to add something like a smoothing effect. The closer you get, the higher the volume of the voice. Link to comment
Renkon Posted October 18, 2012 Share Posted October 18, 2012 Try this Maybe works too and MUCH LESS LINES addEventHandler( 'onPlayerVoiceStart', root, function() local r = 20 -- We get users' position local posX, posY, posZ = getElementPosition( source ) -- create a sphere of the specified radius in that position local chatSphere = createColSphere( posX, posY, posZ, r ) -- get a table all player elements inside it nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) -- and destroy the sphere, since we're done with it destroyElement( chatSphere ) setPlayerVoiceBroadcastTo ( source, nearbyPlayers ) end) About voice, I dont think it's possible. Link to comment
Wortex Posted October 29, 2012 Author Share Posted October 29, 2012 The last one doesn't work Maybe a MTA guru could visit this thread and enlighten me? Still searching for a solution to voice smoothing. 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