Skip to content

Commit

Permalink
feat: add different "voice states"
Browse files Browse the repository at this point in the history
- "voice states" due to a lack of a better word voice mode is already used :(
- useful for lobby/team voice chats
  • Loading branch information
AvarianKnight committed Jan 12, 2022
1 parent 4d6134b commit 8932aac
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
29 changes: 16 additions & 13 deletions client/events.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
AddEventHandler('mumbleConnected', function(address, isReconnecting)
logger.info('Connected to mumble server with address of %s, is this a reconnect %s', GetConvarInt('voice_hideEndpoints', 1) == 1 and 'HIDDEN' or address, isReconnecting)

logger.log('Connecting to mumble, setting targets.')
-- don't try to set channel instantly, we're still getting data.
function handleInitialState()
local voiceModeData = Cfg.voiceModes[mode]
-- sets how far the player can talk
MumbleSetAudioInputDistance(voiceModeData[1] + 0.0)
LocalPlayer.state:set('proximity', {
index = mode,
distance = voiceModeData[1],
mode = voiceModeData[2],
}, true)

MumbleSetTalkerProximity(voiceModeData[1] + 0.0)
MumbleClearVoiceTarget(voiceTarget)
MumbleSetVoiceTarget(voiceTarget)
Expand All @@ -24,6 +12,21 @@ AddEventHandler('mumbleConnected', function(address, isReconnecting)
MumbleAddVoiceTargetChannel(voiceTarget, playerServerId)

addNearbyPlayers()
end

AddEventHandler('mumbleConnected', function(address, isReconnecting)
logger.info('Connected to mumble server with address of %s, is this a reconnect %s', GetConvarInt('voice_hideEndpoints', 1) == 1 and 'HIDDEN' or address, isReconnecting)

logger.log('Connecting to mumble, setting targets.')
-- don't try to set channel instantly, we're still getting data.
local voiceModeData = Cfg.voiceModes[mode]
LocalPlayer.state:set('proximity', {
index = mode,
distance = voiceModeData[1],
mode = voiceModeData[2],
}, true)

handleInitialState()

logger.log('Finished connection logic')
end)
Expand Down
35 changes: 29 additions & 6 deletions client/init/proximity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ end)
-- cache talking status so we only send a nui message when its not the same as what it was before
local lastTalkingStatus = false
local lastRadioStatus = false
local voiceState = "proximity"
Citizen.CreateThread(function()
TriggerEvent('chat:addSuggestion', '/muteply', 'Mutes the player with the specified id', {
{ name = "player id", help = "the player to toggle mute" },
Expand All @@ -108,18 +109,40 @@ Citizen.CreateThread(function()
})
end
end
addNearbyPlayers()
local isSpectating = NetworkIsInSpectatorMode()
if isSpectating and not isListenerEnabled then
setSpectatorMode(true)
elseif not isSpectating and isListenerEnabled then
setSpectatorMode(false)

if voiceState == "proximity" then
addNearbyPlayers()
local isSpectating = NetworkIsInSpectatorMode()
if isSpectating and not isListenerEnabled then
setSpectatorMode(true)
elseif not isSpectating and isListenerEnabled then
setSpectatorMode(false)
end
end

Wait(GetConvarInt('voice_refreshRate', 200))
end
end)

exports("setVoiceState", function(_voiceState, channel)
if _voiceState ~= "proximity" and _voiceState ~= "channel" then
logger.error("Didn't get a proper voice state, expected proximity or channel, got %s", _voiceState)
end
voiceState = _voiceState
if voiceState == "channel" then
type_check({channel, "number"})
-- 65535 is the highest a client id can go, so we add that to the base channel so we don't manage to get onto a players channel
channel = channel + 65535
MumbleSetVoiceChannel(channel)
while MumbleGetVoiceChannelFromServerId(playerServerId) ~= channel do
Wait(250)
end
MumbleAddVoiceTargetChannel(voiceTarget, channel)
elseif voiceState == "proximity" then
handleInitialState()
end
end)


AddEventHandler("onClientResourceStop", function(resource)
if type(addProximityCheck) == "table" then
Expand Down
2 changes: 0 additions & 2 deletions shared.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Cfg = {}

voiceTarget = 1
radioTarget = 2
callTarget = 3

gameVersion = GetGameName()

Expand Down

0 comments on commit 8932aac

Please sign in to comment.