Permissions.lua

Preview

------------------------------------------------------------------------------------------
PermsType = 'esx' -- 'esx' | 'qb' | 'vrp' | 'license' | 'ace' | 'discordRoles'  -
------------------------------------------------------------------------------------------

function hasPermission(source)
    if PermsType == 'discordRoles' then
        local p = promise.new()
        local hasRole = false

        for _, roleIdOuNome in ipairs(Config.AuthorizedRoles) do
            exports.discordroles:isRolePresent(source, roleIdOuNome, function(isPresent)
                if isPresent then
                    hasRole = true
                    if Config.Debug then
                        print("^2[stoned-reports]^7 Player w/ ID " .. source .. " has perms for reports with role: " .. roleIdOuNome)
                    end
                end
            end)
        end

        Citizen.SetTimeout(1000, function()
            p:resolve(hasRole)
        end)

        local terRole = Citizen.Await(p)
        return terRole

    elseif PermsType == 'qb' then
        local QBCore = exports['qb-core']:GetCoreObject()
        local Player = QBCore.Functions.GetPlayer(source)

        if Player and Player.PlayerData.job.name then
            local group = Player.PlayerData.job.name
            if Config.GroupPermissions[group] ~= nil and Config.GroupPermissions[group] == true then
                return true
            else
                return false
            end
        end
    elseif PermsType == 'vrp' then
        for c, d in pairs(Config.GroupPermissions) do
            if vRP.hasPermission({vRP.getUserId({source}), c}) then 
                return true
            end
        end
        return false
    elseif PermsType == 'ace' then
        for c, d in pairs(Config.GroupPermissions) do
            if IsPlayerAceAllowed(source, c) then
                return true
            end
        end
        return false
    elseif PermsType == 'license' then
        for i, a in ipairs(Config.AdminList) do
            for x, b in ipairs(GetPlayerIdentifiers(source)) do
                if string.lower(b) == string.lower(a) then
                    return true
                end
            end
        end
        return false
    elseif PermsType == 'esx' then
        if Config.Debug then
            print("in ESX Framework")
        end
        ESX = exports["es_extended"]:getSharedObject()
    
        Citizen.Wait(100)
    
        local Player = ESX.GetPlayerFromId(source)
    
        if not Player then
            if Config.Debug then
                print("Player not found, trying again in 1 second...")
            end
            Citizen.Wait(1000)
            Player = ESX.GetPlayerFromId(source)
            if not Player then
                if Config.Debug then
                    print("Failed to get player after second try")
                end
                return false
            end
        end
    
        if Config.PermissionsByJob == true then
            if Player.job.name == Config.Jobname then
                if Config.Debug then
                    print("you have the job")
                end
                return true
            else
                return false
            end
        end
    
        local group = Player.getGroup()
    
        if Config.GroupPermissions[group] ~= nil and Config.GroupPermissions[group] == true then
            return true
        else
            return false
        end
    end
    
    
end

Last updated

Was this helpful?