if salary > 0 then
if job == 'unemployed' then -- unemployed
xPlayer.addAccountMoney('bank', salary)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_help', salary), 'CHAR_BANK_MAZE', 9)
elseif Config.EnableSocietyPayouts then -- possibly a society
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function (society)
if society ~= nil then -- verified society
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function (account)
if account.money >= salary then -- does the society money to pay its employees?
xPlayer.addAccountMoney('bank', salary)
account.removeMoney(salary)
--TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
else
--TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), '', _U('company_nomoney'), 'CHAR_BANK_MAZE', 1)
end
end)
else -- not a society
xPlayer.addAccountMoney('bank', salary)
--TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
end
end)
else -- generic job
xPlayer.addAccountMoney('bank', salary)
--TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
end
end
end
end
end)
end
Assistant
User
here is the full script
code
Assistant
add the notification use ox_lib
To use the ox_lib for notifications in the provided Lua script, you'll need to replace the commented TriggerClientEvent lines with the appropriate ox_lib notification functions. Below is the modified version of your code that includes notifications using ox_lib:
lua
if salary > 0 then
if job == 'unemployed' then -- unemployed
xPlayer.addAccountMoney('bank', salary)
-- Using ox_lib for notification
exports.ox_lib:notify({
title = _U('bank'),
description = _U('received_help', salary),
type = 'inform'
})
elseif Config.EnableSocietyPayouts then -- possibly a society
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function (society)
if society ~= nil then -- verified society
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function (account)
if account.money >= salary then -- does the society money to pay its employees?
xPlayer.addAccountMoney('bank', salary)
account.removeMoney(salary)
-- Notify the player using ox_lib
exports.ox_lib:notify({
title = _U('bank'),
description = _U('received_salary', salary),
type = 'inform'
})
else
-- Notify the player that the company has no money
exports.ox_lib:notify({
title = _U('bank'),
description = _U('company_nomoney'),
type = 'error'
})
end
end)
else -- not a society
xPlayer.addAccountMoney('bank', salary)
-- Notify the player using ox_lib
exports.ox_lib:notify({
title = _U('bank'),
description = _U('received_salary', salary),
type = 'inform'
})
end
end)
else -- generic job
xPlayer.addAccountMoney('bank', salary)
-- Notify the player using ox_lib
exports.ox_lib:notify({
title = _U('bank'),
description = _U('received_salary', salary),
type = 'inform'
})
end
end
Key Changes:
Replaced the commented-out TriggerClientEvent calls with exports.ox_lib:notify() for notifications.
Used appropriate title, description, and type parameters for the notifications.
Make sure to adjust the type (e.g., 'inform', 'error') based on the desired notification severity and check the ox_lib documentation for any specific requirements or options.
StartPayCheck = function()
Citizen.CreateThread(function()
while true do
Citizen.Wait(Config.PaycheckInterval)
local xPlayers = ESX.GetExtendedPlayers()
for _, xPlayer in pairs(xPlayers) do
local job = xPlayer.job.grade_name
local salary = xPlayer.job.grade_salary
if salary > 0 then
if job == 'unemployed' then -- unemployed
xPlayer.addAccountMoney('bank', salary)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_help', salary), 'CHAR_BANK_MAZE', 9)
elseif Config.EnableSocietyPayouts then -- possibly a society
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function (society)
if society ~= nil then -- verified society
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function (account)
if account.money >= salary then -- does the society money to pay its employees?
xPlayer.addAccountMoney('bank', salary)
account.removeMoney(salary)
--TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
else
--TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), '', _U('company_nomoney'), 'CHAR_BANK_MAZE', 1)
end
end)
else -- not a society
xPlayer.addAccountMoney('bank', salary)
--TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
end
end)
else -- generic job
xPlayer.addAccountMoney('bank', salary)
--TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
end
end
end
end
end)
end
``
To integrate ox_lib notifications into the full script you've shared, we will replace the commented-out TriggerClientEvent lines with exports.ox_lib:notify() to provide user feedback. Below is the modified version of your entire script:
lua
StartPayCheck = function()
Citizen.CreateThread(function()
while true do
Citizen.Wait(Config.PaycheckInterval)
local xPlayers = ESX.GetExtendedPlayers()
for _, xPlayer in pairs(xPlayers) do
local job = xPlayer.job.grade_name
local salary = xPlayer.job.grade_salary
if salary > 0 then
if job == 'unemployed' then -- unemployed
xPlayer.addAccountMoney('bank', salary)
-- Notify using ox_lib
exports.ox_lib:notify({
title = _U('bank'),
description = _U('received_help', salary),
type = 'inform'
})
elseif Config.EnableSocietyPayouts then -- possibly a society
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function (society)
if society ~= nil then -- verified society
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function (account)
if account.money >= salary then -- does the society have money to pay its employees?
xPlayer.addAccountMoney('bank', salary)
account.removeMoney(salary)
-- Notify the player using ox_lib
exports.ox_lib:notify({
title = _U('bank'),
description = _U('received_salary', salary),
type = 'inform'
})
else
-- Notify player that the company has no money
exports.ox_lib:notify({
title = _U('bank'),
description = _U('company_nomoney'),
type = 'error'
})
end
end)
else -- not a society
xPlayer.addAccountMoney('bank', salary)
-- Notify using ox_lib
exports.ox_lib:notify({
title = _U('bank'),
description = _U('received_salary', salary),
type = 'inform'
})
end
end)
else -- generic job
xPlayer.addAccountMoney('bank', salary)
-- Notify using ox_lib
exports.ox_lib:notify({
title = _U('bank'),
description = _U('received_salary', salary),
type = 'inform'
})
end
end
end
end
end)
end
Key Changes:
Notifications:
For each case where a player receives their salary, I replaced the commented-out TriggerClientEvent with exports.ox_lib:notify() to provide feedback.
The title, description, and type have been appropriately set based on the context.
Error Handling:
I added error handling to notify the player if the company does not have enough funds to pay their salary.
Now, whenever a player receives their paycheck, they will get a notification through ox_lib, enhancing user experience and providing immediate feedback.