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.