fivem scripting I’m working on a radio script I want to use…
- User
fivem scripting I’m working on a radio script I want to use MumbleSetVolumeOverrideByServerId to change the audio when anyone connected to the radio channel talks on the radio set it to 0.4 and when nobody is talking on the radio reset it here is my code
client.lua
local QBCore = exports[‘qb-core’]:GetCoreObject() local PlayerData = QBCore.Functions.GetPlayerData() – Just for resource restart (same as event handler) local radioMenu = false local onRadio = false local RadioChannel = 0 local RadioVolume = 50 local hasRadio = false local radioProp = nil
–Function local function LoadAnimDic(dict) if not HasAnimDictLoaded(dict) then RequestAnimDict(dict) while not HasAnimDictLoaded(dict) do Wait(0) end end end
local function SplitStr(inputstr, sep) if sep == nil then sep = “%s” end local t = {} for str in string.gmatch(inputstr, “([^” … sep … “]+)”) do t[#t+1] = str end return t end
local function connecttoradio(channel) RadioChannel = channel if onRadio then exports[“pma-voice”]:setRadioChannel(0) else onRadio = true exports[“pma-voice”]:setVoiceProperty(“radioEnabled”, true) end exports[“pma-voice”]:setRadioChannel(channel) if SplitStr(tostring(channel), “.”)[2] ~= nil and SplitStr(tostring(channel), “.”)[2] ~= “” then QBCore.Functions.Notify(Config.messages[‘joined_to_radio’] …channel… ’ MHz’, ‘success’) else QBCore.Functions.Notify(Config.messages[‘joined_to_radio’] …channel… ‘.00 MHz’, ‘success’) end end
local function closeEvent() TriggerEvent(“InteractSound_CL:PlayOnOne”,“click”,0.6) end
local function leaveradio() closeEvent() RadioChannel = 0 onRadio = false exports[“pma-voice”]:setRadioChannel(0) exports[“pma-voice”]:setVoiceProperty(“radioEnabled”, false) QBCore.Functions.Notify(Config.messages[‘you_leave’] , ‘error’) end
local function toggleRadioAnimation(pState) LoadAnimDic(“cellphone@”) if pState then TriggerEvent(“attachItemRadio”,“radio01”) TaskPlayAnim(PlayerPedId(), “cellphone@”, “cellphone_text_read_base”, 2.0, 3.0, -1, 49, 0, 0, 0, 0) radioProp = CreateObject(prop_cs_hand_radio, 1.0, 1.0, 1.0, 1, 1, 0) AttachEntityToEntity(radioProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 57005), 0.14, 0.01, -0.02, 110.0, 120.0, -15.0, 1, 0, 0, 0, 2, 1) else StopAnimTask(PlayerPedId(), “cellphone@”, “cellphone_text_read_base”, 1.0) ClearPedTasks(PlayerPedId()) if radioProp ~= 0 then DeleteObject(radioProp) radioProp = 0 end end end
local function toggleRadio(toggle) radioMenu = toggle SetNuiFocus(radioMenu, radioMenu) if radioMenu then toggleRadioAnimation(true) SendNUIMessage({type = “open”}) else toggleRadioAnimation(false) SendNUIMessage({type = “close”}) end end
local function IsRadioOn() return onRadio end
local function DoRadioCheck(PlayerItems) local hasRadio = false
for , item in pairs(PlayerItems) do if item.name == “radio” then hasRadio = true break; end end
hasRadio = hasRadio end
–Exports exports(“IsRadioOn”, IsRadioOn)
- Assistant
In order to change the audio when anyone connected to the radio channel talks on the radio set it to 0.4 and when nobody is talking on the radio reset it, you need to detect when a player starts and stops talking on the radio channel. You can do this by monitoring the voice activity events using
registerPresenceEventsfrom the pma-voice module.First, add the following function to your
client.luafile:local function setVoiceOverride(state) for _, playerId in ipairs(GetActivePlayers()) do local serverId = GetPlayerServerId(playerId) if state then MumbleSetVolumeOverrideByServerId(serverId, 0.4) else MumbleClearVolumeOverrideByServerId(serverId) end end endThen, register the voice activity events and call the function. Add the following code to your file:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.