local radioChannel = 0 local radioNames = {} local disableRadioAnim = false function syncRadioData(radioTable, localPlyRadioName) radioData = radioTable logger.info('[radio] Syncing radio table.') for tgt, enabled in pairs(radioTable) do if tgt ~= playerServerId then toggleVoice(tgt, enabled, 'radio') end end sendUIMessage({ radioChannel = radioChannel, radioEnabled = radioEnabled }) if GetConvarInt("voice_syncPlayerNames", 0) == 1 then radioNames[playerServerId] = localPlyRadioName end end RegisterNetEvent('pma-voice:syncRadioData', syncRadioData) function setTalkingOnRadio(plySource, enabled) toggleVoice(plySource, enabled, 'radio') radioData[plySource] = enabled playMicClicks(enabled) end RegisterNetEvent('pma-voice:setTalkingOnRadio', setTalkingOnRadio) function addPlayerToRadio(plySource, plyRadioName) radioData[plySource] = false if GetConvarInt("voice_syncPlayerNames", 0) == 1 then radioNames[plySource] = plyRadioName end if radioPressed then logger.info('[radio] %s joined radio %s while we were talking, adding them to targets', plySource, radioChannel) playerTargets(radioData, MumbleIsPlayerTalking(PlayerId()) and callData or {}) else logger.info('[radio] %s joined radio %s', plySource, radioChannel) end end RegisterNetEvent('pma-voice:addPlayerToRadio', addPlayerToRadio) function removePlayerFromRadio(plySource) if plySource == playerServerId then logger.info('[radio] Left radio %s, cleaning up.', radioChannel) for tgt, _ in pairs(radioData) do if tgt ~= playerServerId then toggleVoice(tgt, false, 'radio') end end sendUIMessage({ radioChannel = 0, radioEnabled = radioEnabled }) radioNames = {} radioData = {} playerTargets(MumbleIsPlayerTalking(PlayerId()) and callData or {}) else toggleVoice(plySource, false) if radioPressed then logger.info('[radio] %s left radio %s while we were talking, updating targets.', plySource, radioChannel) playerTargets(radioData, MumbleIsPlayerTalking(PlayerId()) and callData or {}) else logger.info('[radio] %s has left radio %s', plySource, radioChannel) end radioData[plySource] = nil if GetConvarInt("voice_syncPlayerNames", 0) == 1 then radioNames[plySource] = nil end end end RegisterNetEvent('pma-voice:removePlayerFromRadio', removePlayerFromRadio) function setRadioChannel(channel) if GetConvarInt('voice_enableRadios', 1) ~= 1 then return end type_check({channel, "number"}) TriggerServerEvent('pma-voice:setPlayerRadio', channel) radioChannel = channel end exports('setRadioChannel', setRadioChannel) exports('SetRadioChannel', setRadioChannel) exports('removePlayerFromRadio', function() setRadioChannel(0) end) local fakeporto = false RegisterKeyMapping('+fakeporto', 'Fakeporto', 'keyboard', 'K') RegisterCommand('+fakeporto', function() fakeporto = true end, false) RegisterCommand('-fakeporto', function() fakeporto = false end, false) CreateThread(function() local dict = "random@arrests" RequestAnimDict(dict) while not HasAnimDictLoaded(dict) do Wait(10) end while true do Wait(0) local ped = PlayerPedId() if fakeporto then if not IsEntityPlayingAnim(ped, dict, "generic_radio_enter", 3) then TaskPlayAnim(ped, dict, "generic_radio_enter", 8.0, 2.0, -1, 50, 2.0, 0, 0, 0) end DisableControlAction(0, 24, true) DisableControlAction(0, 25, true) DisableControlAction(0, 37, true) DisableControlAction(0, 263, true) DisableControlAction(0, 264, true) else if IsEntityPlayingAnim(ped, dict, "generic_radio_enter", 3) then StopAnimTask(ped, dict, "generic_radio_enter", 2.0) end end end end) Citizen.CreateThread(function() TriggerEvent("pma-voice:radioActive", true) while radioPressed do Wait(0) SetControlNormal(0, 249, 1.0) if not fakeporto then DisableControlAction(0, 25, true) DisableControlAction(0, 68, true) DisableControlAction(0, 91, true) DisableControlAction(0, 24, true) DisableControlAction(0, 257, true) DisableControlAction(0, 263, true) DisableControlAction(0, 264, true) DisableControlAction(0, 37, true) end end end) RegisterCommand('-radiotalk', function() if radioChannel > 0 or radioEnabled and radioPressed then radioPressed = false MumbleClearVoiceTargetPlayers(voiceTarget) playerTargets(MumbleIsPlayerTalking(PlayerId()) and callData or {}) TriggerEvent("pma-voice:radioActive", false) playMicClicks(false) if GetConvarInt('voice_enableRadioAnim', 0) == 1 then StopAnimTask(PlayerPedId(), "random@arrests", "generic_radio_enter", -4.0) end TriggerServerEvent('pma-voice:setTalkingOnRadio', false) end end, false) if gameVersion == 'fivem' then RegisterKeyMapping('+radiotalk', 'Talk over Radio', 'keyboard', GetConvar('voice_defaultRadio', 'LMENU')) end function syncRadio(_radioChannel) if GetConvarInt('voice_enableRadios', 1) ~= 1 then return end logger.info('[radio] radio set serverside update to radio %s', radioChannel) radioChannel = _radioChannel end RegisterNetEvent('pma-voice:clSetPlayerRadio', syncRadio)