[FIXED]Rp-radio frequency job lock

Hey guys,

I am trying to lock station 1-4 for specific jobs, in the clients.lua of the radio I have:

Citizen.CreateThread(function()

    -- ESX - do not touch
    while ESX == nil do
        TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
        Citizen.Wait(0)
    end

    if ESX.PlayerData.job.name == 'police' then -- police
        exports["rp-radio"]:GivePlayerAccessToFrequencies(1)
    elseif ESX.PlayerData.job.name == 'ambulance' then --EMS
        exports["rp-radio"]:GivePlayerAccessToFrequencies(2)
    elseif ESX.PlayerData.job.name == 'sheriff' then --sheriffs department
        exports["rp-radio"]:GivePlayerAccessToFrequencies(3)        
    elseif ESX.PlayerData.job.name == 'mecano' then --mechanic
        exports["rp-radio"]:GivePlayerAccessToFrequencies(4)
    else
        exports["rp-radio"]:RemovePlayerAccessToFrequencies(1, 2, 3, 4)
    end 

    GenerateFrequencyList()

end)
Frequency = {
        Private = { -- List of private frequencies
            [1] = true,
            [2] = true,
            [3] = true,
            [4] = true,
        }, -- List of private frequencies
        Current = 1, -- Don't touch
        CurrentIndex = 1, -- Don't touch
        Min = 1, -- Minimum frequency
        Max = 1024, -- Max number of frequencies
        List = {}, -- Frequency list, Don't touch
        Access = {}, -- List of freqencies a player has access to
    },
    AllowRadioWhenClosed = true -- Allows the radio to be used when not open (uses police radio animation) 

In the config, I have set those to private, however the script doesn’t error out, it doesn’t work as well. It won’t allow me to switch to those stations. Can you please provide some insight as to what I’m doing wrong?

EDIT: If I remove them from private frequencies in the config, everybody can join those frequencies.

I fixed! Here’s what I did:

1.) Made frequency 1-4 private in the config.lua
2.) In client.lua at the top I have: ESX = nil
3.) At the bottom of client.lua I have the following function

Citizen.CreateThread(function()

    -- ESX - do not touch
    while ESX == nil do
        TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
        Citizen.Wait(0)
    end

    while true do
        Citizen.Wait(500)
        if ESX.PlayerData.job.name == 'police' then -- police
            exports["rp-radio"]:GivePlayerAccessToFrequencies(1)
        elseif ESX.PlayerData.job.name == 'ambulance' then --EMS
            exports["rp-radio"]:GivePlayerAccessToFrequencies(2)
        elseif ESX.PlayerData.job.name == 'sheriff' then --sheriffs department
            exports["rp-radio"]:GivePlayerAccessToFrequencies(3)        
        elseif ESX.PlayerData.job.name == 'mecano' then --mechanic
            exports["rp-radio"]:GivePlayerAccessToFrequencies(4)
        else
            exports["rp-radio"]:RemovePlayerAccessToFrequencies(1, 2, 3, 4)
        end
    end

    GenerateFrequencyList()

end)

The 500 is the milliseconds the script will refresh. If you wish, you can make it less, however that will put more load on the server to loop through all players and check them.

Additionally, you can edit the jobs and channels to whatever you like.

1 Like

Hi! I have a Problem

hi where you able to get this to work?

Are you even running ESX? If yes, you should have a job field in your ‘users’ table. Make sure that ESX and es_extended are up to date.

Do you know how to change this into vRP format with it being connected to discord ace perms??

Absolutely no idea how to turn this into the vRP radio script, especially while using discord ace perms.

Well it was worth a shot, thank you!

where do you use theme?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.