Jump to content

Local Voice Chat


Recommended Posts

Posted (edited)

I have default voice chat from mta team, and anybody can hear it, but i want to be only local on 50 meters how i can do it ?

local range = 50 
  
addEventHandler ( "onClientPlayerVoiceStart", root, 
function() 
    if (source and isElement(source) and getElementType(source) == "player") and localPlayer ~= source then 
        local sX, sY, sZ = getElementPosition(localPlayer) 
        local rX, rY, rZ = getElementPosition(source) 
        local distance = getDistanceBetweenPoints3D(sX, sY, sZ, rX, rY, rZ) 
        if distance <= range then 
            voicePlayers[source] = true 
        else 
            voicePlayers[source] = nil 
        end 
    end 
end     
) 

 

Edited by anonimbro
Posted

Seems to me this code only changes when the player's name is shown as if he were talking (the table only stores state whether someone's speaking or not, as far as I'm aware).

Posted
  
local nearbyPlayers = {} 
  
addEventHandler("onPlayerVoiceStart", root, 
    function() 
        local r = 50 
        local posX, posY, posZ = getElementPosition(source) 
        local chatSphere = createColSphere(posX, posY, posZ, r) 
        nearbyPlayers = getElementsWithinColShape(chatSphere, "player") 
        destroyElement(chatSphere) 
        local empty = exports.voice:getNextEmptyChannel() 
        exports.voice:setPlayerChannel(source, empty) 
        for index, player in ipairs(nearbyPlayers) do 
            exports.voice:setPlayerChannel(player, empty) 
        end 
    end 
) 
addEventHandler("onPlayerVoiceStop", root, 
    function() 
        exports.voice:setPlayerChannel(source) 
        for index, player in ipairs(nearbyPlayers) do 
            exports.voice:setPlayerChannel(player) 
        end 
        nearbyPlayers = {} 
    end 
) 

 

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