Locale/oxmysql

MUST UPDATE OXMYSQL TO 1.9 OR HIGHER
This commit is contained in:
Kakarot
2022-01-10 01:52:59 -06:00
parent e151194643
commit d786a3cd07
8 changed files with 115 additions and 81 deletions
+4 -1
View File
@@ -5,6 +5,8 @@ description 'QB-Core'
version '1.0.0'
shared_scripts {
'shared/locale.lua',
'locale/en.lua', -- replace with desired language
'config.lua',
'shared/main.lua',
'shared/items.lua',
@@ -22,6 +24,7 @@ client_scripts {
}
server_scripts {
'@oxmysql/lib/MySQL.lua',
'server/main.lua',
'server/functions.lua',
'server/player.lua',
@@ -44,4 +47,4 @@ dependencies {
'connectqueue'
}
lua54 'yes'
lua54 'yes'
+25
View File
@@ -0,0 +1,25 @@
local Translations = {
error = {
not_online = 'Player not online',
wrong_format = 'Incorrect format',
missing_args = 'Not every argument has been entered (x, y, z)',
missing_args2 = 'All arguments must be filled out!',
no_access = 'No access to this command',
company_too_poor = 'Your employer is broke',
item_exist = 'Item does not exist',
too_heavy = 'Inventory too full'
},
success = {},
info = {
received_paycheck = 'You received your paycheck of $%{value}',
job_info = 'Job: %{value} | Grade: %{value2} | Duty: %{value3}',
gang_info = 'Gang: %{value} | Grade: %{value2}',
on_duty = 'You are now on duty!',
off_duty = 'You are now off duty!'
}
}
Lang = Locale:new({
phrases = Translations,
warnOnMissing = true
})
+12 -12
View File
@@ -50,7 +50,7 @@ QBCore.Commands.Add('tp', 'TP To Player or Coords (Admin Only)', { { name = 'id/
local coords = GetEntityCoords(target)
TriggerClientEvent('QBCore:Command:TeleportToPlayer', src, coords)
else
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
end
else
if args[1] and args[2] and args[3] then
@@ -60,10 +60,10 @@ QBCore.Commands.Add('tp', 'TP To Player or Coords (Admin Only)', { { name = 'id/
if (x ~= 0) and (y ~= 0) and (z ~= 0) then
TriggerClientEvent('QBCore:Command:TeleportToCoords', src, x, y, z)
else
TriggerClientEvent('QBCore:Notify', src, 'Incorrect Format', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.wrong_format'), 'error')
end
else
TriggerClientEvent('QBCore:Notify', src, 'Not every argument has been entered (x, y, z)', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.missing_args'), 'error')
end
end
end, 'admin')
@@ -89,7 +89,7 @@ QBCore.Commands.Add('addpermission', 'Give Player Permissions (God Only)', { { n
if Player then
QBCore.Functions.AddPermission(Player.PlayerData.source, permission)
else
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
end
end, 'god')
@@ -99,7 +99,7 @@ QBCore.Commands.Add('removepermission', 'Remove Players Permissions (God Only)',
if Player then
QBCore.Functions.RemovePermission(Player.PlayerData.source)
else
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
end
end, 'god')
@@ -123,7 +123,7 @@ QBCore.Commands.Add('givemoney', 'Give A Player Money (Admin Only)', { { name =
if Player then
Player.Functions.AddMoney(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
end
end, 'admin')
@@ -133,7 +133,7 @@ QBCore.Commands.Add('setmoney', 'Set Players Money Amount (Admin Only)', { { nam
if Player then
Player.Functions.SetMoney(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
end
end, 'admin')
@@ -142,7 +142,7 @@ end, 'admin')
QBCore.Commands.Add('job', 'Check Your Job', {}, false, function(source)
local src = source
local PlayerJob = QBCore.Functions.GetPlayer(src).PlayerData.job
TriggerClientEvent('QBCore:Notify', src, string.format('[Job]: %s [Grade]: %s [On Duty]: %s', PlayerJob.label, PlayerJob.grade.name, PlayerJob.onduty))
TriggerClientEvent('QBCore:Notify', src, Lang:t('info.job_info', {value = PlayerJob.label, value2 = PlayerJob.grade.name, value3 = PlayerJob.onduty}))
end, 'user')
QBCore.Commands.Add('setjob', 'Set A Players Job (Admin Only)', { { name = 'id', help = 'Player ID' }, { name = 'job', help = 'Job name' }, { name = 'grade', help = 'Grade' } }, true, function(source, args)
@@ -151,7 +151,7 @@ QBCore.Commands.Add('setjob', 'Set A Players Job (Admin Only)', { { name = 'id',
if Player then
Player.Functions.SetJob(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
end
end, 'admin')
@@ -160,7 +160,7 @@ end, 'admin')
QBCore.Commands.Add('gang', 'Check Your Gang', {}, false, function(source)
local src = source
local PlayerGang = QBCore.Functions.GetPlayer(source).PlayerData.gang
TriggerClientEvent('QBCore:Notify', src, string.format('[Gang]: %s [Grade]: %s', PlayerGang.label, PlayerGang.grade.name))
TriggerClientEvent('QBCore:Notify', src, Lang:t('info.gang_info', {value = PlayerGang.label, value2 = PlayerGang.grade.name}))
end, 'user')
QBCore.Commands.Add('setgang', 'Set A Players Gang (Admin Only)', { { name = 'id', help = 'Player ID' }, { name = 'gang', help = 'Name of a gang' }, { name = 'grade', help = 'Grade' } }, true, function(source, args)
@@ -169,7 +169,7 @@ QBCore.Commands.Add('setgang', 'Set A Players Gang (Admin Only)', { { name = 'id
if Player then
Player.Functions.SetGang(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
end
end, 'admin')
@@ -182,7 +182,7 @@ QBCore.Commands.Add('clearinv', 'Clear Players Inventory (Admin Only)', { { name
if Player then
Player.Functions.ClearInventory()
else
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_online'), 'error')
end
end, 'admin')
+6 -6
View File
@@ -26,12 +26,12 @@ AddEventHandler('chatMessage', function(source, n, message)
table.remove(args, 1)
if isGod or hasPerm or isPrincipal then
if (QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and args[#QBCore.Commands.List[command].arguments] == nil) then
TriggerClientEvent('QBCore:Notify', src, 'All arguments must be filled out!', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.missing_args2'), 'error')
else
QBCore.Commands.List[command].callback(src, args)
end
else
TriggerClientEvent('QBCore:Notify', src, 'No Access To This Command', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.no_access'), 'error')
end
end
end
@@ -157,10 +157,10 @@ RegisterNetEvent('QBCore:ToggleDuty', function()
local Player = QBCore.Functions.GetPlayer(src)
if Player.PlayerData.job.onduty then
Player.Functions.SetJobDuty(false)
TriggerClientEvent('QBCore:Notify', src, 'You are now off duty!')
TriggerClientEvent('QBCore:Notify', src, Lang:t('info.off_duty'))
else
Player.Functions.SetJobDuty(true)
TriggerClientEvent('QBCore:Notify', src, 'You are now on duty!')
TriggerClientEvent('QBCore:Notify', src, Lang:t('info.on_duty'))
end
TriggerClientEvent('QBCore:Client:SetDuty', src, Player.PlayerData.job.onduty)
end)
@@ -200,12 +200,12 @@ RegisterNetEvent('QBCore:CallCommand', function(command, args)
local isPrincipal = IsPlayerAceAllowed(src, 'command')
if (QBCore.Commands.List[command].permission == Player.PlayerData.job.name) or isGod or hasPerm or isPrincipal then
if (QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and args[#QBCore.Commands.List[command].arguments] == nil) then
TriggerClientEvent('QBCore:Notify', src, 'All arguments must be filled out!', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.missing_args2'), 'error')
else
QBCore.Commands.List[command].callback(src, args)
end
else
TriggerClientEvent('QBCore:Notify', src, 'No Access To This Command', 'error')
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.no_access'), 'error')
end
end
end
+14 -14
View File
@@ -190,19 +190,19 @@ function PaycheckLoop()
local account = exports['qb-bossmenu']:GetAccount(Player.PlayerData.job.name)
if account ~= 0 then -- Checks if player is employed by a society
if account < payment then -- Checks if company has enough money to pay society
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, 'The company you\'re employed at doesn\'t have enough money to pay for your salary', 'error')
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('error.company_too_poor'), 'error')
else
Player.Functions.AddMoney('bank', payment)
TriggerEvent('qb-bossmenu:server:removeAccountMoney', Player.PlayerData.job.name, payment)
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, ('You received your paycheck of $%s'):format(payment))
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
end
else
Player.Functions.AddMoney('bank', payment)
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, ('You received your paycheck of $%s'):format(payment))
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
end
else
Player.Functions.AddMoney('bank', payment)
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, ('You received your paycheck of $%s'):format(payment))
TriggerClientEvent('QBCore:Notify', Player.PlayerData.source, Lang:t('info.received_paycheck', {value = payment}))
end
end
end
@@ -279,10 +279,10 @@ function QBCore.Functions.IsWhitelisted(source)
local plicense = QBCore.Functions.GetIdentifier(src, 'license')
local identifiers = GetPlayerIdentifiers(src)
if QBCore.Config.Server.whitelist then
local result = exports.oxmysql:executeSync('SELECT * FROM whitelist WHERE license = ?', { plicense })
if result[1] then
local result = MySQL.Sync.fetchSingle('SELECT * FROM whitelist WHERE license = ?', { plicense })
if result then
for _, id in pairs(identifiers) do
if result[1].license == id then
if result.license == id then
return true
end
end
@@ -304,9 +304,9 @@ function QBCore.Functions.AddPermission(source, permission)
license = plicense,
permission = permission:lower(),
}
exports.oxmysql:execute('DELETE FROM permissions WHERE license = ?', { plicense })
MySQL.Async.execute('DELETE FROM permissions WHERE license = ?', { plicense })
exports.oxmysql:insert('INSERT INTO permissions (name, license, permission) VALUES (?, ?, ?)', {
MySQL.Async.insert('INSERT INTO permissions (name, license, permission) VALUES (?, ?, ?)', {
GetPlayerName(src),
plicense,
permission:lower()
@@ -323,7 +323,7 @@ function QBCore.Functions.RemovePermission(source)
local license = Player.PlayerData.license
if Player then
QBCore.Config.Server.PermissionList[license] = nil
exports.oxmysql:execute('DELETE FROM permissions WHERE license = ?', { license })
MySQL.Async.execute('DELETE FROM permissions WHERE license = ?', { license })
Player.Functions.UpdatePlayerData()
end
end
@@ -386,14 +386,14 @@ function QBCore.Functions.IsPlayerBanned(source)
local retval = false
local message = ''
local plicense = QBCore.Functions.GetIdentifier(src, 'license')
local result = exports.oxmysql:executeSync('SELECT * FROM bans WHERE license = ?', { plicense })
if result[1] then
if os.time() < result[1].expire then
local result = MySQL.Sync.fetchSingle('SELECT * FROM bans WHERE license = ?', { plicense })
if result then
if os.time() < result.expire then
retval = true
local timeTable = os.date('*t', tonumber(result.expire))
message = 'You have been banned from the server:\n' .. result[1].reason .. '\nYour ban expires ' .. timeTable.day .. '/' .. timeTable.month .. '/' .. timeTable.year .. ' ' .. timeTable.hour .. ':' .. timeTable.min .. '\n'
else
exports.oxmysql:execute('DELETE FROM bans WHERE id = ?', { result[1].id })
MySQL.Async.execute('DELETE FROM bans WHERE id = ?', { result[1].id })
end
end
return retval, message
+1 -1
View File
@@ -15,7 +15,7 @@ end)
-- Get permissions on server start
CreateThread(function()
local result = exports.oxmysql:executeSync('SELECT * FROM permissions', {})
local result = MySQL.Sync.fetchAll('SELECT * FROM permissions', {})
if result[1] then
for k, v in pairs(result) do
QBCore.Config.Server.PermissionList[v.license] = {
+52 -44
View File
@@ -10,7 +10,7 @@ function QBCore.Player.Login(source, citizenid, newData)
if src then
if citizenid then
local license = QBCore.Functions.GetIdentifier(src, 'license')
local PlayerData = exports.oxmysql:singleSync('SELECT * FROM players where citizenid = ?', { citizenid })
local PlayerData = MySQL.Sync.prepare('SELECT * FROM players where citizenid = ?', { citizenid })
if PlayerData and license == PlayerData.license then
PlayerData.money = json.decode(PlayerData.money)
PlayerData.job = json.decode(PlayerData.job)
@@ -329,7 +329,7 @@ function QBCore.Player.CreatePlayer(PlayerData)
local totalWeight = QBCore.Player.GetTotalWeight(self.PlayerData.items)
local itemInfo = QBCore.Shared.Items[item:lower()]
if itemInfo == nil then
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, 'Item Does Not Exist', 'error')
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, Lang:t('error.item_exist'), 'error')
return
end
local amount = tonumber(amount)
@@ -361,7 +361,7 @@ function QBCore.Player.CreatePlayer(PlayerData)
end
end
else
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, 'Your inventory is too heavy!', 'error')
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, Lang:t('error.too_heavy'), 'error')
end
return false
end
@@ -482,7 +482,7 @@ function QBCore.Player.Save(source)
local pcoords = GetEntityCoords(ped)
local PlayerData = QBCore.Players[src].PlayerData
if PlayerData then
exports.oxmysql:insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
MySQL.Async.insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
citizenid = PlayerData.citizenid,
cid = tonumber(PlayerData.cid),
license = PlayerData.license,
@@ -522,12 +522,22 @@ local playertables = { -- Add tables as needed
function QBCore.Player.DeleteCharacter(source, citizenid)
local src = source
local license = QBCore.Functions.GetIdentifier(src, 'license')
local result = exports.oxmysql:scalarSync('SELECT license FROM players where citizenid = ?', { citizenid })
local result = MySQL.Sync.fetchScalar('SELECT license FROM players where citizenid = ?', { citizenid })
if license == result then
for k, v in pairs(playertables) do
exports.oxmysql:execute('DELETE FROM ' .. v.table .. ' WHERE citizenid = ?', { citizenid })
end
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**' .. GetPlayerName(src) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..')
local query = "DELETE FROM %s WHERE citizenid = ?"
local tableCount = #playertables
local queries = table.create(tableCount, 0)
for i=1, tableCount do
local v = playertables[i]
queries[i] = {query = query:format(v.table), values = { citizenid }}
end
MySQL.Async.transaction(queries, function(result)
if result then
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**' .. GetPlayerName(src) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..')
end
end)
else
DropPlayer(src, 'You Have Been Kicked For Exploitation')
TriggerEvent('qb-log:server:CreateLog', 'anticheat', 'Anti-Cheat', 'white', GetPlayerName(src) .. ' Has Been Dropped For Character Deletion Exploit', false)
@@ -538,31 +548,29 @@ end
QBCore.Player.LoadInventory = function(PlayerData)
PlayerData.items = {}
local result = exports.oxmysql:singleSync('SELECT * FROM players WHERE citizenid = ?', { PlayerData.citizenid })
if result then
if result.inventory then
local plyInventory = json.decode(result.inventory)
if next(plyInventory) then
for _, item in pairs(plyInventory) do
if item then
local itemInfo = QBCore.Shared.Items[item.name:lower()]
if itemInfo then
PlayerData.items[item.slot] = {
name = itemInfo['name'],
amount = item.amount,
info = item.info or '',
label = itemInfo['label'],
description = itemInfo['description'] or '',
weight = itemInfo['weight'],
type = itemInfo['type'],
unique = itemInfo['unique'],
useable = itemInfo['useable'],
image = itemInfo['image'],
shouldClose = itemInfo['shouldClose'],
slot = item.slot,
combinable = itemInfo['combinable']
}
end
local inventory = MySQL.Sync.prepare('SELECT inventory FROM players WHERE citizenid = ?', { PlayerData.citizenid })
if inventory then
inventory = json.decode(inventory)
if next(inventory) then
for _, item in pairs(inventory) do
if item then
local itemInfo = QBCore.Shared.Items[item.name:lower()]
if itemInfo then
PlayerData.items[item.slot] = {
name = itemInfo['name'],
amount = item.amount,
info = item.info or '',
label = itemInfo['label'],
description = itemInfo['description'] or '',
weight = itemInfo['weight'],
type = itemInfo['type'],
unique = itemInfo['unique'],
useable = itemInfo['useable'],
image = itemInfo['image'],
shouldClose = itemInfo['shouldClose'],
slot = item.slot,
combinable = itemInfo['combinable']
}
end
end
end
@@ -589,9 +597,9 @@ QBCore.Player.SaveInventory = function(source)
}
end
end
exports.oxmysql:execute('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode(ItemsJson), PlayerData.citizenid })
MySQL.Async.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode(ItemsJson), PlayerData.citizenid })
else
exports.oxmysql:execute('UPDATE players SET inventory = ? WHERE citizenid = ?', { '[]', PlayerData.citizenid })
MySQL.Async.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { '[]', PlayerData.citizenid })
end
end
end
@@ -636,8 +644,8 @@ function QBCore.Player.CreateCitizenId()
local CitizenId = nil
while not UniqueFound do
CitizenId = tostring(QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(5)):upper()
local result = exports.oxmysql:executeSync('SELECT COUNT(*) as count FROM players WHERE citizenid = ?', { CitizenId })
if result[1].count == 0 then
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE citizenid = ?', { CitizenId })
if result == 0 then
UniqueFound = true
end
end
@@ -650,8 +658,8 @@ function QBCore.Player.CreateFingerId()
while not UniqueFound do
FingerId = tostring(QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(1) .. QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(4))
local query = '%' .. FingerId .. '%'
local result = exports.oxmysql:executeSync('SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE ?', { query })
if result[1].count == 0 then
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE ?', { query })
if result == 0 then
UniqueFound = true
end
end
@@ -664,8 +672,8 @@ function QBCore.Player.CreateWalletId()
while not UniqueFound do
WalletId = 'QB-' .. math.random(11111111, 99999999)
local query = '%' .. WalletId .. '%'
local result = exports.oxmysql:executeSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
if result[1].count == 0 then
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
if result == 0 then
UniqueFound = true
end
end
@@ -678,8 +686,8 @@ function QBCore.Player.CreateSerialNumber()
while not UniqueFound do
SerialNumber = math.random(11111111, 99999999)
local query = '%' .. SerialNumber .. '%'
local result = exports.oxmysql:executeSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
if result[1].count == 0 then
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
if result == 0 then
UniqueFound = true
end
end
+1 -3
View File
@@ -21,9 +21,7 @@ local function translateKey(phrase, subs)
-- Initial Scan over result looking for substituions
for k, v in pairs(subs) do
local templateToFind = '%%{' .. k .. '}'
print('Template to find:', templateToFind)
print('Replace val:', v)
result = result:gsub(templateToFind, v)
result = result:gsub(templateToFind, tostring(v)) -- string to allow all types
end
return result