QBcore 🛠️ QB-Core Advanced Permission System

SaifNeon

Administrators
Joined
Apr 25, 2022
Messages
931
Credits
50,185

QBCore-Perms-Edits​

This edit make the perm saves on data and optional based on citizen id or licence

🛠️ QB-Core Advanced Permission System​

Please, Log in or Register to view URLs content!
Please, Log in or Register to view URLs content!


📌 Features​

  • ✅ Persistent permission storage
  • 🔄 Automatic permission synchronization
  • 👮‍♂️ CitizenID or License based (configurable)
  • 📊 MySQL database integration
  • 🔒 ACE permission system support

⚙️ Installation​

1️⃣ Modify QB-Core Functions​

Replace these in qb-core/server/functions.lua:

-- CONFIG: Set to true to use License instead of CitizenID
local USE_LICENSE_ID = false

function QBCore.Functions.AddPermission(source, permission)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end

local identifier, identifierType
if USE_LICENSE_ID then
identifier = GetPlayerIdentifier(src, 'license') or Player.PlayerData.license
identifierType = 'license'
else
identifier = Player.PlayerData.citizenid
identifierType = 'citizenid'
end

QBCore.Config.Server.Permissions[identifier] = {
identifier = identifier,
permission = permission:lower()
}
MySQL.Async.execute('DELETE FROM permissions WHERE identifier = ?', { identifier })
MySQL.Async.insert('INSERT INTO permissions (name, identifier, permission, type) VALUES (?, ?, ?, ?)', {
GetPlayerName(src),
identifier,
permission:lower(),
identifierType
})
ExecuteCommand(('add_principal identifier.%s qbcore.%s'):format(identifier, permission))
QBCore.Commands.Refresh(src)
TriggerClientEvent('QBCore:Client:OnPermissionUpdate', src, permission)
end

function QBCore.Functions.RemovePermission(source, permission)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end

local identifier
if USE_LICENSE_ID then
identifier = GetPlayerIdentifier(src, 'license') or Player.PlayerData.license
MySQL.Async.execute('DELETE FROM permissions WHERE identifier = ? AND permission = ?', { identifier, permission:lower() })
QBCore.Commands.Refresh(src)
end
else
ExecuteCommand(('remove_principal identifier.%s qbcore'):format(identifier))
MySQL.Async.execute('DELETE FROM permissions WHERE identifier = ?', { identifier })
QBCore.Commands.Refresh(src)
end
end

2️⃣ Database Setup​

CREATE TABLE IF NOT EXISTS `permissions` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`identifier` VARCHAR(255) NOT NULL,
`name` VARCHAR(50) DEFAULT NULL,
`permission` VARCHAR(50) DEFAULT 'user',
`type` ENUM('citizenid','license') DEFAULT 'citizenid',
PRIMARY KEY (`id`),
UNIQUE KEY `identifier` (`identifier`),
KEY `permission` (`permission`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
Back
Top Bottom