Jump to content

Voice chat "radius"?


Wortex

Recommended Posts

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

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

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

Try this :D

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
  • 2 weeks later...

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