Jump to content

Voice chat distance


dewu

Recommended Posts

Posted

Hi guys.

I want to use MTA resource call "Voice" to add voice chat communication system to my server, but I want to set it on 3D for some distance.

I really don't know how to do that, but i think it's possible.

If someone know, please help me :)

I find something like this:

  
 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) 
  

And now, how to use it?

Posted

I don't think the code you found allows you to have 3D voice. I think it's more about either letting you hear people or not, based on the distance between them and other players.

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