Personal salaries
If usePersonalSalary is enabled, ensure all steps are completed. For installation issues, please open a ticket in my Discord server.
QB-Core
Navigate to qb-core/server/player.lua
Insert the following code over self.Functions.SetJob(job, grade)
function self.Functions.ChangeSalary(payment)
if not payment then return false end
self.PlayerData.job.payment = payment
self.Functions.UpdatePlayerData()
return true
end
ESX
Execute the following SQL code in your database
ALTER TABLE users ADD job_salary int(11) NOT NULL DEFAULT 0;
Navigate to es_extended/server/classes/player.lua
Look for 'self.setJob' and once located, include the function to add salary data within it, as shown below:
function self.setJob(newJob, grade, salary)
Once that's completed, insert this code into the function
if salary then
self.job.salary = salary
else
self.job.salary = gradeObject.salary
end
Make sure its underneath this code:
local jobObject, gradeObject = ESX.Jobs[newJob], ESX.Jobs[newJob].grades[grade]
After that navigate to es_extended/server/main.lua
Find this:
local loadPlayer = 'SELECT `accounts`, `job`, `job_grade`, `group`, `position`, `inventory`, `skin`, `loadout`, `metadata`'
And replace with this:
local loadPlayer = 'SELECT `accounts`, `job`, `job_grade`, `job_salary` = ?, `group`, `position`, `inventory`, `skin`, `loadout`, `metadata`'
Find the loadESXPlayer function in the same file as above
When you have find the function go down til you find userData.job.label = jobObject.label and underneath that code paste in this code:
userData.job.salary = result.job_salary
After that navigate to es_extended/server/functions.lua
Find the functions Core.SavePlayer(xPlayer, cb) and Core.SavePlayers(cb) and replace them with the following:
function Core.SavePlayer(xPlayer, cb)
updateHealthAndArmorInMetadata(xPlayer)
local parameters <const> = {
json.encode(xPlayer.getAccounts(true)),
xPlayer.job.name,
xPlayer.job.grade,
xPlayer.job.salary,
xPlayer.group,
json.encode(xPlayer.getCoords()),
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` = ?, `job_salary` = ?, `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
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.job.salary,
xPlayer.group,
json.encode(xPlayer.getCoords()),
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` = ?, `job_salary` = ?, `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
If you're using an older ESX version, simply open a ticket, and I'll assist you promptly.
Last step, navigate to es_extended/server/paycheck.lua
Replace this
local salary = xPlayer.job.grade_salary
With this
local salary = xPlayer.job.salary
Last updated