server/function.lua
🇫🇷 Ici, vous allez ajouter les fonctions pour le système de Job2
🇺🇸 Here, you will add the functions for the Job2 system
🇫🇷 Cherchez la fonction
function Core.SavePlayer(xPlayer, cb)
🇺🇸 Find the function
function Core.SavePlayer(xPlayer, cb)
🇫🇷 Puis, remplacez la fonction entière par celle-ci:
🇺🇸 Then, replace the entire function with this one:
function Core.SavePlayer(xPlayer, cb)
if not xPlayer.spawned then
return cb and cb()
end
updateHealthAndArmorInMetadata(xPlayer)
local parameters <const> = {
json.encode(xPlayer.getAccounts(true)),
xPlayer.job.name,
xPlayer.job.grade,
xPlayer.job2.name,
xPlayer.job2.grade,
xPlayer.group,
json.encode(xPlayer.getCoords(false, true)),
json.encode(xPlayer.getInventory(true)),
json.encode(xPlayer.getLoadout(true)),
json.encode(xPlayer.getMeta()),
xPlayer.identifier,
}
MySQL.prepare(
"UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `job2` = ?, `job2_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ?, `metadata` = ? WHERE `identifier` = ?",
parameters,
function(affectedRows)
if affectedRows == 1 then
print(('[^2INFO^7] Saved player ^5"%s^7"'):format(xPlayer.name))
TriggerEvent("esx:playerSaved", xPlayer.playerId, xPlayer)
end
if cb then
cb()
end
end
)
end
🇫🇷 Ensuite, cherchez la fonction:
function Core.SavePlayers(cb)
🇺🇸 Next, find the function:
function Core.SavePlayers(cb)
🇫🇷 Puis, remplacez la fonction entière par celle-ci:
🇺🇸 Then, replace the entire function with this one:
function Core.SavePlayers(cb)
local xPlayers <const> = ESX.Players
if not next(xPlayers) then
return
end
local startTime <const> = os.time()
local parameters = {}
for _, xPlayer in pairs(ESX.Players) do
updateHealthAndArmorInMetadata(xPlayer)
parameters[#parameters + 1] = {
json.encode(xPlayer.getAccounts(true)),
xPlayer.job.name,
xPlayer.job.grade,
xPlayer.job2.name,
xPlayer.job2.grade,
xPlayer.group,
json.encode(xPlayer.getCoords(false, true)),
json.encode(xPlayer.getInventory(true)),
json.encode(xPlayer.getLoadout(true)),
json.encode(xPlayer.getMeta()),
xPlayer.identifier,
}
end
MySQL.prepare(
"UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `job2` = ?, `job2_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ?, `metadata` = ? WHERE `identifier` = ?",
parameters,
function(results)
if not results then
return
end
if type(cb) == "function" then
return cb()
end
print(("[^2INFO^7] Saved ^5%s^7 %s over ^5%s^7 ms"):format(#parameters, #parameters > 1 and "players" or "player", ESX.Math.Round((os.time() - startTime) / 1000000, 2)))
end
)
end
🇫🇷 Ensuite, cherchez la fonction: ESX.GetExtendedPlayers(key, val)
🇺🇸 Next, find the function: ESX.GetExtendedPlayers(key, val)
🇫🇷 Puis, remplacez la fonction entière par celle-ci:
🇺🇸 Then, replace the entire function with this one:
function ESX.GetExtendedPlayers(key, val)
if not key then
return ESX.Table.ToArray(ESX.Players)
end
local xPlayers = {}
if type(val) == "table" then
for _, xPlayer in pairs(ESX.Players) do
checkTable(key, val, xPlayer, xPlayers)
end
return xPlayers
end
for _, xPlayer in pairs(ESX.Players) do
if (key == "job" and xPlayer.job.name == val) or (key == 'job2' and xPlayer.job2.name== val) or xPlayer[key] == val then
xPlayers[#xPlayers + 1] = xPlayer
end
end
return xPlayers
end
🇫🇷 Ensuite, juste après la fonction
ESX.RefreshJobs()
, ajoutez ceci:🇺🇸 Next, just after the function
ESX.RefreshJobs()
, add this:
function ESX.RefreshJobs2()
local Jobs2 = {}
local jobs2 = MySQL.query.await("SELECT * FROM jobs2")
for _, v in ipairs(jobs2) do
Jobs2[v.name] = v
Jobs2[v.name].grades = {}
end
local job2Grades = MySQL.query.await("SELECT * FROM job2_grades")
for _, v in ipairs(job2Grades) do
if Jobs2[v.job2_name] then
Jobs2[v.job2_name].grades[tostring(v.grade)] = v
else
print(('[^3WARNING^7] Ignoring job2 grades for ^5"%s"^0 due to missing job'):format(v.job_name))
end
end
for _, v in pairs(Jobs2) do
if ESX.Table.SizeOf(v.grades) == 0 then
Jobs2[v.name] = nil
print(('[^3WARNING^7] Ignoring job2 ^5"%s"^0 due to no job grades found'):format(v.name))
end
end
if not Jobs2 then
-- Fallback data, if no jobs exist
ESX.Jobs["nogang"] = { label = "Sans gang", grades = { ["0"] = { grade = 0, label = "Sans gang", salary = 200, skin_male = {}, skin_female = {} } } }
else
ESX.Jobs2 = Jobs2
end
end
function ESX.DoesJob2Exist(job2, grade)
return (ESX.Jobs2[job2] and ESX.Jobs2[job2].grades[tostring(grade)] ~= nil) or false
end
function ESX.GetJobs2()
return ESX.Jobs2
end
Last updated