Jump to content

Voice - Radius - Help


Kazaam

Recommended Posts

I am currently hosting a server off my pc to play with a group of friends. We would like there to be a radius to voice chat so that you only hear people using the voice command who are close, or local, to your player. I have searched around a bit for a free resource. Having no luck using the free resource 'AVS' , I was excited to find a user from these forums suggested to use:

      
    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) 

However, I can not seem to figure out how to use this. I have the default voice resource installed on the server. Do I have to paste this into it? Or.. perhaps This must run as a new resource? I have spent time trying to figure this out,( im a newb) with no luck. If anyone knows how I implement these changes, it would be greatly appreciated. :fadein:

Link to comment
  • Moderators

Why export?

why don't you make your own one:

https://wiki.multitheftauto.com/wiki/IsVoiceEnabled

https://wiki.multitheftauto.com/wiki/Se ... roadcastTo

https://wiki.multitheftauto.com/wiki/Se ... IgnoreFrom

and as events:

https://wiki.multitheftauto.com/wiki/OnColShapeHit

https://wiki.multitheftauto.com/wiki/OnColShapeLeave

and just 1 local timer: (to check if this player is still in the colshape, sometimes onColShapeLeave doesn't got triggered because of the lagg)

https://wiki.multitheftauto.com/wiki/SetTimer

and of course tables, ram fasted thing in the world.

Link to comment

I see what you're saying, kind of. Why use exports to the default voice? Can I delete the default voice resource all together? In my case, I was only following this lead because I am very new and don't quite have a grasp on writing scripts. This was the closest I came searching for something finished or 'easy' . Thanks for the info! I will give it a go as I don't see any resources (besides AVS, which didnt work for me ) that do this radius voice chat.

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