From d572f1acb075aa9ca7b88f888d12a5ad2511898e Mon Sep 17 00:00:00 2001 From: Csoki Date: Fri, 30 Dec 2022 11:15:36 +0100 Subject: [PATCH 1/6] feat(esx_society): add missing locales --- [esx_addons]/esx_society/locales/hu.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/[esx_addons]/esx_society/locales/hu.lua b/[esx_addons]/esx_society/locales/hu.lua index 1b060793..2721c9cd 100644 --- a/[esx_addons]/esx_society/locales/hu.lua +++ b/[esx_addons]/esx_society/locales/hu.lua @@ -12,10 +12,11 @@ Locales['hu'] = { ['grade'] = 'Fokozat', ['have_deposited'] = 'Sikeresen beraktál ~r~%s $', ['have_withdrawn'] = 'Sikeresen kivettél %s $', + ['check_balance'] = 'egyenleg ~g~%s$', ['invalid_amount'] = 'Érvénytelen mennyiség', ['invalid_amount_max'] = 'Ez az összeg több mint a megengedett', - ['invalid_value'] = 'invalid value', - ['invalid_value_nochanges']= 'invalid value, no changes applied', + ['invalid_value'] = 'érvénytelen érték', + ['invalid_value_nochanges']= 'érvénytelen érték, nem történt változtatás', ['no'] = 'Nem', ['promote'] = 'Elöléptetés', ['promote_employee'] = 'Elöléptetés %s', @@ -23,6 +24,9 @@ Locales['hu'] = { ['recruiting'] = 'Felvétel', ['salary_amount'] = 'Fizetés', ['salary_management'] = 'Fizetések kezelése', + ['grade_management'] = 'Rangok nevének kezelése', + ['grade_label'] = 'Rang név', + ['check_society_balance'] = 'Egyenleg megtekintése', ['wash_money'] = 'Pénz mosás', ['wash_money_amount'] = 'Piszkos pénz mennyiség', ['withdraw_amount'] = 'Pénz mennyiség', From 88bbaa1282eb16d658698c9cb600dbad10f5b185 Mon Sep 17 00:00:00 2001 From: Csoki Date: Fri, 30 Dec 2022 11:27:10 +0100 Subject: [PATCH 2/6] fix(esx_society): fix invalid job bug --- [esx_addons]/esx_society/client/main.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/[esx_addons]/esx_society/client/main.lua b/[esx_addons]/esx_society/client/main.lua index aa735108..2af03b20 100644 --- a/[esx_addons]/esx_society/client/main.lua +++ b/[esx_addons]/esx_society/client/main.lua @@ -276,6 +276,10 @@ end function OpenPromoteMenu(society, employee, options) ESX.TriggerServerCallback('esx_society:getJob', function(job) + if not job then + return + end + local elements = { {unselectable = true, icon = "fas fa-user", title = TranslateCap('promote_employee', employee.name)} } @@ -354,6 +358,10 @@ end function OpenManageGradesMenu(society, options) ESX.TriggerServerCallback('esx_society:getJob', function(job) + if not job then + return + end + local elements = { {unselectable = true, icon = "fas fa-wallet", title = TranslateCap('grade_management')} } From 93d8a11aaf5d50d3afb49dfbf7781a5f95911903 Mon Sep 17 00:00:00 2001 From: Csoki Date: Fri, 30 Dec 2022 11:28:11 +0100 Subject: [PATCH 3/6] feat(esx_policejob): add esx_proprty dependency --- [esx_addons]/esx_policejob/fxmanifest.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/[esx_addons]/esx_policejob/fxmanifest.lua b/[esx_addons]/esx_policejob/fxmanifest.lua index 9a3355d2..86f8ea7c 100644 --- a/[esx_addons]/esx_policejob/fxmanifest.lua +++ b/[esx_addons]/esx_policejob/fxmanifest.lua @@ -27,5 +27,6 @@ client_scripts { dependencies { 'es_extended', 'esx_billing', - 'esx_vehicleshop' + 'esx_vehicleshop', + 'esx_society' } From a759b4d74bc96e5c7db55b901b25e0e8bb1f1c34 Mon Sep 17 00:00:00 2001 From: Csoki Date: Fri, 30 Dec 2022 12:06:00 +0100 Subject: [PATCH 4/6] fix(esx_society): invalid job bug --- [esx_addons]/esx_society/client/main.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/[esx_addons]/esx_society/client/main.lua b/[esx_addons]/esx_society/client/main.lua index 2af03b20..f0797518 100644 --- a/[esx_addons]/esx_society/client/main.lua +++ b/[esx_addons]/esx_society/client/main.lua @@ -310,6 +310,10 @@ end function OpenManageSalaryMenu(society, options) ESX.TriggerServerCallback('esx_society:getJob', function(job) + if not job then + return + end + local elements = { {unselectable = true, icon = "fas fa-wallet", title = TranslateCap('salary_management')} } From 25016e8b4d400b3983ae76d3352ca14399a201cf Mon Sep 17 00:00:00 2001 From: Csoki Date: Fri, 30 Dec 2022 12:06:18 +0100 Subject: [PATCH 5/6] refactor(esx_society): main/server.lua --- [esx_addons]/esx_society/server/main.lua | 181 ++++++++++------------- 1 file changed, 79 insertions(+), 102 deletions(-) diff --git a/[esx_addons]/esx_society/server/main.lua b/[esx_addons]/esx_society/server/main.lua index be5e0d3d..82c084ec 100644 --- a/[esx_addons]/esx_society/server/main.lua +++ b/[esx_addons]/esx_society/server/main.lua @@ -1,33 +1,19 @@ -local Jobs = {} +local Jobs = setmetatable({}, {__index = function(_, key) + return ESX.GetJobs()[key] +end +}) local RegisteredSocieties = {} +local SocietiesByName = {} function GetSociety(name) - for i=1, #RegisteredSocieties, 1 do - if RegisteredSocieties[i].name == name then - return RegisteredSocieties[i] - end - end + return SocietiesByName[name] end -AddEventHandler('onResourceStart', function(resourceName) - if resourceName == GetCurrentResourceName() then - local result = MySQL.query.await('SELECT * FROM jobs') - - for i = 1, #result, 1 do - Jobs[result[i].name] = result[i] - Jobs[result[i].name].grades = {} - end - - local result2 = MySQL.query.await('SELECT * FROM job_grades') - - for i = 1, #result2, 1 do - Jobs[result2[i].job_name].grades[tostring(result2[i].grade)] = result2[i] - end - end -end) - AddEventHandler('esx_society:registerSociety', function(name, label, account, datastore, inventory, data) - local found = false + if SocietiesByName[name] then + print(('[^3WARNING^7] society already registered, name: ^5%s^7'):format(name)) + return + end local society = { name = name, @@ -38,16 +24,8 @@ AddEventHandler('esx_society:registerSociety', function(name, label, account, da data = data } - for i=1, #RegisteredSocieties, 1 do - if RegisteredSocieties[i].name == name then - found, RegisteredSocieties[i] = true, society - break - end - end - - if not found then - table.insert(RegisteredSocieties, society) - end + SocietiesByName[name] = society + table.insert(RegisteredSocieties, society) end) AddEventHandler('esx_society:getSocieties', function(cb) @@ -83,19 +61,19 @@ AddEventHandler('esx_society:withdrawMoney', function(societyName, amount) end local xPlayer = ESX.GetPlayerFromId(source) amount = ESX.Math.Round(tonumber(amount)) - if xPlayer.job.name == society.name then - TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account) - if amount > 0 and account.money >= amount then - account.removeMoney(amount) - xPlayer.addMoney(amount, "Society Withdraw") - xPlayer.showNotification(TranslateCap('have_withdrawn', ESX.Math.GroupDigits(amount))) - else - xPlayer.showNotification(TranslateCap('invalid_amount')) - end - end) - else - print(('[^3WARNING^7] Player ^5%s^7 attempted to withdraw from society - ^5%s^7!'):format(source, society.name)) + if xPlayer.job.name ~= society.name then + return print(('[^3WARNING^7] Player ^5%s^7 attempted to withdraw from society - ^5%s^7!'):format(source, society.name)) end + + TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account) + if amount > 0 and account.money >= amount then + account.removeMoney(amount) + xPlayer.addMoney(amount, "Society Withdraw") + xPlayer.showNotification(TranslateCap('have_withdrawn', ESX.Math.GroupDigits(amount))) + else + xPlayer.showNotification(TranslateCap('invalid_amount')) + end + end) end) RegisterServerEvent('esx_society:depositMoney') @@ -109,18 +87,17 @@ AddEventHandler('esx_society:depositMoney', function(societyName, amount) end amount = ESX.Math.Round(tonumber(amount)) - if xPlayer.job.name == society.name then - if amount > 0 and xPlayer.getMoney() >= amount then - TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account) - xPlayer.removeMoney(amount, "Society Deposit") - xPlayer.showNotification(TranslateCap('have_deposited', ESX.Math.GroupDigits(amount))) - account.addMoney(amount) - end) - else - xPlayer.showNotification(TranslateCap('invalid_amount')) - end + if xPlayer.job.name ~= society.name then + return print(('[^3WARNING^7] Player ^5%s^7 attempted to deposit to society - ^5%s^7!'):format(source, society.name)) + end + if amount > 0 and xPlayer.getMoney() >= amount then + TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account) + xPlayer.removeMoney(amount, "Society Deposit") + xPlayer.showNotification(TranslateCap('have_deposited', ESX.Math.GroupDigits(amount))) + account.addMoney(amount) + end) else - print(('[^3WARNING^7] Player ^5%s^7 attempted to deposit to society - ^5%s^7!'):format(source, society.name)) + xPlayer.showNotification(TranslateCap('invalid_amount')) end end) @@ -131,26 +108,24 @@ AddEventHandler('esx_society:washMoney', function(society, amount) local account = xPlayer.getAccount('black_money') amount = ESX.Math.Round(tonumber(amount)) - if xPlayer.job.name == society then - if amount and amount > 0 and account.money >= amount then - xPlayer.removeAccountMoney('black_money', amount, "Washing") + if xPlayer.job.name ~= society then + return print(('[^3WARNING^7] Player ^5%s^7 attempted to wash money in society - ^5%s^7!'):format(source, society)) + end + if amount and amount > 0 and account.money >= amount then + xPlayer.removeAccountMoney('black_money', amount, "Washing") - MySQL.insert('INSERT INTO society_moneywash (identifier, society, amount) VALUES (?, ?, ?)', {xPlayer.identifier, society, amount}, - function(rowsChanged) - xPlayer.showNotification(TranslateCap('you_have', ESX.Math.GroupDigits(amount))) - end) - else - xPlayer.showNotification(TranslateCap('invalid_amount')) - end + MySQL.insert('INSERT INTO society_moneywash (identifier, society, amount) VALUES (?, ?, ?)', {xPlayer.identifier, society, amount}, + function(rowsChanged) + xPlayer.showNotification(TranslateCap('you_have', ESX.Math.GroupDigits(amount))) + end) else - print(('[^3WARNING^7] Player ^5%s^7 attempted to wash money in society - ^5%s^7!'):format(source, society)) + xPlayer.showNotification(TranslateCap('invalid_amount')) end end) RegisterServerEvent('esx_society:putVehicleInGarage') AddEventHandler('esx_society:putVehicleInGarage', function(societyName, vehicle) local source = source - local xPlayer = ESX.GetPlayerFromId(source) local society = GetSociety(societyName) if not society then print(('[^3WARNING^7] Player ^5%s^7 attempted to put vehicle in non-existing society garage - ^5%s^7!'):format(source, societyName)) @@ -166,7 +141,6 @@ end) RegisterServerEvent('esx_society:removeVehicleFromGarage') AddEventHandler('esx_society:removeVehicleFromGarage', function(societyName, vehicle) local source = source - local xPlayer = ESX.GetPlayerFromId(source) local society = GetSociety(societyName) if not society then print(('[^3WARNING^7] Player ^5%s^7 attempted to remove vehicle from non-existing society garage - ^5%s^7!'):format(source, societyName)) @@ -190,15 +164,14 @@ ESX.RegisterServerCallback('esx_society:getSocietyMoney', function(source, cb, s local society = GetSociety(societyName) if not society then print(('[^3WARNING^7] Player ^5%s^7 attempted to get money from non-existing society - ^5%s^7!'):format(source, societyName)) - return + return cb(0) end - if society then - TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account) - cb(account.money) - end) - else - cb(0) + if not society then + return cb(0) end + TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account) + cb(account.money or 0) + end) end) ESX.RegisterServerCallback('esx_society:getEmployees', function(source, cb, society) @@ -271,6 +244,10 @@ ESX.RegisterServerCallback('esx_society:getEmployees', function(source, cb, soci end) ESX.RegisterServerCallback('esx_society:getJob', function(source, cb, society) + if not Jobs[society] then + return cb(false) + end + local job = json.decode(json.encode(Jobs[society])) local grades = {} @@ -292,33 +269,33 @@ ESX.RegisterServerCallback('esx_society:setJob', function(source, cb, identifier local isBoss = xPlayer.job.grade_name == 'boss' local xTarget = ESX.GetPlayerFromIdentifier(identifier) - if isBoss then - - if xTarget then - xTarget.setJob(job, grade) - - if actionType == 'hire' then - xTarget.showNotification(TranslateCap('you_have_been_hired', job)) - xPlayer.showNotification(TranslateCap("you_have_hired", xTarget.getName())) - elseif actionType == 'promote' then - xTarget.showNotification(TranslateCap('you_have_been_promoted')) - xPlayer.showNotification(TranslateCap("you_have_promoted", xTarget.getName(), xTarget.getJob().label)) - elseif actionType == 'fire' then - xTarget.showNotification(TranslateCap('you_have_been_fired', xTarget.getJob().label)) - xPlayer.showNotification(TranslateCap("you_have_fired", xTarget.getName())) - end - - cb() - else - MySQL.update('UPDATE users SET job = ?, job_grade = ? WHERE identifier = ?', {job, grade, identifier}, - function(rowsChanged) - cb() - end) - end - else + if not isBoss then print(('[^3WARNING^7] Player ^5%s^7 attempted to setJob for Player ^5%s^7!'):format(source, xTarget.source)) - cb() + return cb() end + + if not xTarget then + MySQL.update('UPDATE users SET job = ?, job_grade = ? WHERE identifier = ?', {job, grade, identifier}, + function() + cb() + end) + return + end + + xTarget.setJob(job, grade) + + if actionType == 'hire' then + xTarget.showNotification(TranslateCap('you_have_been_hired', job)) + xPlayer.showNotification(TranslateCap("you_have_hired", xTarget.getName())) + elseif actionType == 'promote' then + xTarget.showNotification(TranslateCap('you_have_been_promoted')) + xPlayer.showNotification(TranslateCap("you_have_promoted", xTarget.getName(), xTarget.getJob().label)) + elseif actionType == 'fire' then + xTarget.showNotification(TranslateCap('you_have_been_fired', xTarget.getJob().label)) + xPlayer.showNotification(TranslateCap("you_have_fired", xTarget.getName())) + end + + cb() end) From 99c8d116b734ca2b3894e8fa712e93710cd521eb Mon Sep 17 00:00:00 2001 From: Csoki Date: Mon, 9 Jan 2023 22:51:27 +0100 Subject: [PATCH 6/6] fix --- [esx_addons]/esx_society/server/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/[esx_addons]/esx_society/server/main.lua b/[esx_addons]/esx_society/server/main.lua index 0439d219..90d3ccf8 100644 --- a/[esx_addons]/esx_society/server/main.lua +++ b/[esx_addons]/esx_society/server/main.lua @@ -27,7 +27,7 @@ function registerSociety(name, label, account, datastore, inventory, data) SocietiesByName[name] = society table.insert(RegisteredSocieties, society) -end) +end AddEventHandler('esx_society:registerSociety', registerSociety) exports("registerSociety", registerSociety)