Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ QBConfig.Player.Bloodtypes = {
}

QBConfig.Player.PlayerDefaults = {
userId = function() if QBConfig.Server.StaticId.Enabled then return QBCore.Player.CreatePlayerId() end end,
citizenid = function() return QBCore.Player.CreateCitizenId() end,
cid = 1,
money = function()
Expand Down Expand Up @@ -115,6 +116,11 @@ QBConfig.Server.Discord = '' -- Discord invite link
QBConfig.Server.CheckDuplicateLicense = true -- Check for duplicate rockstar license on join
QBConfig.Server.Permissions = { 'god', 'admin', 'mod' } -- Add as many groups as you want here after creating them in your server.cfg

QBConfig.Server.StaticId = {
Enabled = true, -- Enable or disable the use of static ID's
UseInCommands = false -- Use static ID's in commands like /givecash, /setjob etc. (Requires server restart after changing) ( Applys only if QBConfig.Server.StaticId.Enabled.Enabled is true | Applys only in commands from server/commands.lua )
}

QBConfig.Commands = {} -- Command Configuration
QBConfig.Commands.OOCColor = { 255, 151, 133 } -- RGB color code for the OOC command

Expand Down
36 changes: 29 additions & 7 deletions server/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ end)

-- Register & Refresh Commands

local function ResolvePlayerArg(arg)
local id = tonumber(arg)
if not id then return nil end
if QBCore.Config.Server.StaticId.Enabled and QBCore.Config.Server.StaticId.UseInCommands then
return QBCore.Functions.GetPlayerById(id)
else
return QBCore.Functions.GetPlayer(id)
end
end

local function ResolveSourceArg(arg)
local id = tonumber(arg)
if not id then return nil end
if QBCore.Config.Server.StaticId.Enabled and QBCore.Config.Server.StaticId.UseInCommands then
local p = QBCore.Functions.GetPlayerById(id)
return p and p.PlayerData.source or nil
else
return id
end
end

function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...)
local restricted = true -- Default to restricted for all commands
if not permission then permission = 'user' end -- some commands don't pass permission level
Expand Down Expand Up @@ -84,7 +105,8 @@ end
QBCore.Commands.Add('tp', Lang:t('command.tp.help'), { { name = Lang:t('command.tp.params.x.name'), help = Lang:t('command.tp.params.x.help') }, { name = Lang:t('command.tp.params.y.name'), help = Lang:t('command.tp.params.y.help') }, { name = Lang:t('command.tp.params.z.name'), help = Lang:t('command.tp.params.z.help') } }, false, function(source, args)
if args[1] and not args[2] and not args[3] then
if tonumber(args[1]) then
local target = GetPlayerPed(tonumber(args[1]))
local tgtSrc = ResolveSourceArg(args[1])
local target = tgtSrc and GetPlayerPed(tgtSrc) or 0
if target ~= 0 then
local coords = GetEntityCoords(target)
TriggerClientEvent('QBCore:Command:TeleportToPlayer', source, coords)
Expand Down Expand Up @@ -128,7 +150,7 @@ end, 'admin')
-- Permissions

QBCore.Commands.Add('addpermission', Lang:t('command.addpermission.help'), { { name = Lang:t('command.addpermission.params.id.name'), help = Lang:t('command.addpermission.params.id.help') }, { name = Lang:t('command.addpermission.params.permission.name'), help = Lang:t('command.addpermission.params.permission.help') } }, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
local Player = ResolvePlayerArg(args[1])
local permission = tostring(args[2]):lower()
if Player then
QBCore.Functions.AddPermission(Player.PlayerData.source, permission)
Expand All @@ -138,7 +160,7 @@ QBCore.Commands.Add('addpermission', Lang:t('command.addpermission.help'), { { n
end, 'god')

QBCore.Commands.Add('removepermission', Lang:t('command.removepermission.help'), { { name = Lang:t('command.removepermission.params.id.name'), help = Lang:t('command.removepermission.params.id.help') }, { name = Lang:t('command.removepermission.params.permission.name'), help = Lang:t('command.removepermission.params.permission.help') } }, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
local Player = ResolvePlayerArg(args[1])
local permission = tostring(args[2]):lower()
if Player then
QBCore.Functions.RemovePermission(Player.PlayerData.source, permission)
Expand Down Expand Up @@ -220,7 +242,7 @@ end, 'admin')
-- Money

QBCore.Commands.Add('givemoney', Lang:t('command.givemoney.help'), { { name = Lang:t('command.givemoney.params.id.name'), help = Lang:t('command.givemoney.params.id.help') }, { name = Lang:t('command.givemoney.params.moneytype.name'), help = Lang:t('command.givemoney.params.moneytype.help') }, { name = Lang:t('command.givemoney.params.amount.name'), help = Lang:t('command.givemoney.params.amount.help') } }, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
local Player = ResolvePlayerArg(args[1])
if Player then
Player.Functions.AddMoney(tostring(args[2]), tonumber(args[3]), 'Admin give money')
else
Expand All @@ -229,7 +251,7 @@ QBCore.Commands.Add('givemoney', Lang:t('command.givemoney.help'), { { name = La
end, 'admin')

QBCore.Commands.Add('setmoney', Lang:t('command.setmoney.help'), { { name = Lang:t('command.setmoney.params.id.name'), help = Lang:t('command.setmoney.params.id.help') }, { name = Lang:t('command.setmoney.params.moneytype.name'), help = Lang:t('command.setmoney.params.moneytype.help') }, { name = Lang:t('command.setmoney.params.amount.name'), help = Lang:t('command.setmoney.params.amount.help') } }, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
local Player = ResolvePlayerArg(args[1])
if Player then
Player.Functions.SetMoney(tostring(args[2]), tonumber(args[3]))
else
Expand All @@ -245,7 +267,7 @@ QBCore.Commands.Add('job', Lang:t('command.job.help'), {}, false, function(sourc
end, 'user')

QBCore.Commands.Add('setjob', Lang:t('command.setjob.help'), { { name = Lang:t('command.setjob.params.id.name'), help = Lang:t('command.setjob.params.id.help') }, { name = Lang:t('command.setjob.params.job.name'), help = Lang:t('command.setjob.params.job.help') }, { name = Lang:t('command.setjob.params.grade.name'), help = Lang:t('command.setjob.params.grade.help') } }, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
local Player = ResolvePlayerArg(args[1])
if Player then
Player.Functions.SetJob(tostring(args[2]), tonumber(args[3]))
else
Expand All @@ -261,7 +283,7 @@ QBCore.Commands.Add('gang', Lang:t('command.gang.help'), {}, false, function(sou
end, 'user')

QBCore.Commands.Add('setgang', Lang:t('command.setgang.help'), { { name = Lang:t('command.setgang.params.id.name'), help = Lang:t('command.setgang.params.id.help') }, { name = Lang:t('command.setgang.params.gang.name'), help = Lang:t('command.setgang.params.gang.help') }, { name = Lang:t('command.setgang.params.grade.name'), help = Lang:t('command.setgang.params.grade.help') } }, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
local Player = ResolvePlayerArg(args[1])
if Player then
Player.Functions.SetGang(tostring(args[2]), tonumber(args[3]))
else
Expand Down
13 changes: 13 additions & 0 deletions server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ function QBCore.Functions.GetPlayerByCitizenId(citizenid)
return nil
end

---Get player by id
---@param id number
---@return table?
function QBCore.Functions.GetPlayerById(id)
if not QBConfig.Server.StaticId.Enabled then return nil end
for src in pairs(QBCore.Players) do
if QBCore.Players[src].PlayerData.userId == id then
return QBCore.Players[src]
end
end
return nil
end

---Get offline player by citizen id
---@param citizenid string
---@return table?
Expand Down
25 changes: 25 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,28 @@ local function GetSharedGangs()
return QBShared.Gangs
end
exports('GetSharedGangs', GetSharedGangs)

CreateThread(function()
local col = 'userId'
local tbl = 'players'
local exists = MySQL.prepare.await('SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND COLUMN_NAME = ?', { tbl, col })
if QBConfig.Server.StaticId.Enabled then
if exists == 0 then
MySQL.query.await('ALTER TABLE `players` ADD COLUMN `userId` INT NULL DEFAULT NULL, ADD INDEX `userId_idx` (`userId`)')
end
local rows = MySQL.query.await('SELECT citizenid, userId FROM players')
if rows then
for i = 1, #rows do
local r = rows[i]
if not r.userId or r.userId == 0 then
local newId = QBCore.Player.CreatePlayerId()
MySQL.update.await('UPDATE players SET userId = ? WHERE citizenid = ?', { newId, r.citizenid })
end
end
end
else
if exists > 0 then
MySQL.query.await('ALTER TABLE `players` DROP COLUMN `userId`')
end
end
end)
Loading