Skip to content

Commit

Permalink
refactor: (esx_society): complete rebuild for esx_society
Browse files Browse the repository at this point in the history
- feat(esx_society) Added boss grade table
- fix(esx_society): Duplicate locale value
- Fix GetOnlinePlayer
  • Loading branch information
bitpredator committed Jan 24, 2024
1 parent 1d9a73e commit c51d8ff
Show file tree
Hide file tree
Showing 25 changed files with 693 additions and 452 deletions.
3 changes: 2 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ fix lint error: unused argument last; accessing undefined variable Invoke; unuse
75. [esx_multicharacter]: refactor: esx_multicharacter @bitpredator
76. [esx_multicharacter]: fix: fixed problem which prevented the menu from opening @bitpredator
77. [esx_notify]: refactor: formatting(all): Format with prettier and lua formatter @bitpredator
78. [esx_progressbar]: refactor: formatting(all): Format with prettier and lua formatter @bitpredator
78. [esx_progressbar]: refactor: formatting(all): Format with prettier and lua formatter @bitpredator
79. [esx_society]: refactor: (esx_society): complete rebuild for esx_society @bitpredator
4 changes: 2 additions & 2 deletions server-data/resources/[esx]/esx_society/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

esx_society
Copyright (C) 2015-2022 Jérémie N'gadi
Copyright (C) 2015-2024 Jérémie N'gadi

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

esx_society Copyright (C) 2015-2022 Jérémie N'gadi
esx_society Copyright (C) 2015-2024 Jérémie N'gadi
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
10 changes: 5 additions & 5 deletions server-data/resources/[esx]/esx_society/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Society management for ESX. Adds employee management (hire, fire, promote / demo

### Using [fvm](https://github.com/qlaffont/fvm-installer)
```
fvm install --save --folder=esx esx-org/esx_society
fvm install --save --folder=esx esx-framework/esx_society
```

### Using Git
Expand All @@ -20,7 +20,7 @@ git clone https://github.com/ESX-Org/esx_society [esx]/esx_society
```

### Manually
- Download https://github.com/ESX-Org/esx_society/archive/master.zip
- Download https://github.com/esx-framework/esx_society/archive/master.zip
- Put it in the `[esx]` directory

## Installation
Expand All @@ -44,16 +44,16 @@ TriggerServerEvent('esx_society:depositMoney', society, amount)
TriggerServerEvent('esx_society:washMoney', society, amount)


TriggerEvent('esx_society:openBossMenu', society, function (data, menu)
menu.close()
TriggerEvent('esx_society:openBossMenu', society, function (menu)
ESX.CloseContext()
end, {wash = false}) -- set custom options, e.g disable washing
```

# Legal
### License
esx_society - societies for ESX

Copyright (C) 2015-2022 Jérémie N'gadi
Copyright (C) 2015-2024 Jérémie N'gadi

This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.

Expand Down
147 changes: 56 additions & 91 deletions server-data/resources/[esx]/esx_society/client/main.lua
Original file line number Diff line number Diff line change
@@ -1,51 +1,4 @@
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
ESX.PlayerData.job = job
RefreshBussHUD()
end)

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
ESX.PlayerData = xPlayer
ESX.PlayerLoaded = true
RefreshBussHUD()
end)

function RefreshBussHUD()
DisableSocietyMoneyHUDElement()

if ESX.PlayerData.job.grade_name == 'boss' then
EnableSocietyMoneyHUDElement()

ESX.TriggerServerCallback('esx_society:getSocietyMoney', function(money)
UpdateSocietyMoneyHUDElement(money)
end, ESX.PlayerData.job.name)
end
end

RegisterNetEvent('esx_addonaccount:setMoney')
AddEventHandler('esx_addonaccount:setMoney', function(society, money)
if ESX.PlayerData.job and ESX.PlayerData.job.grade_name == 'boss' and 'society_' .. ESX.PlayerData.job.name == society then
UpdateSocietyMoneyHUDElement(money)
end
end)

function EnableSocietyMoneyHUDElement()

TriggerEvent('esx_society:toggleSocietyHud', true)
end

function DisableSocietyMoneyHUDElement()

TriggerEvent('esx_society:toggleSocietyHud', false)
end

function UpdateSocietyMoneyHUDElement(money)

TriggerEvent('esx_society:setSocietyMoney', money)
end

function OpenBossMenu(society, _, options)
function OpenBossMenu(society, close, options)
options = options or {}
local elements = {
{unselectable = true, icon = "fas fa-user", title = _U('boss_menu')}
Expand Down Expand Up @@ -96,10 +49,10 @@ function OpenBossMenu(society, _, options)
TriggerServerEvent('esx_society:checkSocietyBalance', society)
elseif element.value == "withdraw_society_money" then
local elements = {
{unselectable = true, icon = "fas fa-wallet", title = _U('withdraw_amount'), description = "Withdraw money from the society account"},
{icon = "fas fa-wallet", title = "Amount", input = true, inputType = "number", inputPlaceholder = "Amount to withdraw..", inputMin = 1, inputMax = 250000, name = "withdraw"},
{icon = "fas fa-check", title = "Confirm", value = "confirm"},
{icon = "fas fa-arrow-left", title = "Return", value = "return"}
{unselectable = true, icon = "fas fa-wallet", title = _U('withdraw_amount'), description = _U('withdraw_description')},
{icon = "fas fa-wallet", title = _U('amount_title'), input = true, inputType = "number", inputPlaceholder = _U('withdraw_amount_placeholder'), inputMin = 1, inputMax = 250000, name = "withdraw"},
{icon = "fas fa-check", title = _U('confirm'), value = "confirm"},
{icon = "fas fa-arrow-left", title = _U('return'), value = "return"}
}
ESX.RefreshContext(elements)
elseif element.value == "confirm" then
Expand All @@ -112,10 +65,10 @@ function OpenBossMenu(society, _, options)
end
elseif element.value == "deposit_money" then
local elements = {
{unselectable = true, icon = "fas fa-wallet", title = _U('deposit_amount'), description = "Deposit some money into the society account"},
{icon = "fas fa-wallet", title = "Amount", input = true, inputType = "number", inputPlaceholder = "Amount to deposit..", inputMin = 1, inputMax = 250000, name = "deposit"},
{icon = "fas fa-check", title = "Confirm", value = "confirm2"},
{icon = "fas fa-arrow-left", title = "Return", value = "return"}
{unselectable = true, icon = "fas fa-wallet", title = _U('deposit_amount'), description = _U('deposit_description')},
{icon = "fas fa-wallet", title = _U('amount_title'), input = true, inputType = "number", inputPlaceholder = _U('deposit_amount_placeholder'), inputMin = 1, inputMax = 250000, name = "deposit"},
{icon = "fas fa-check", title = _U('confirm'), value = "confirm2"},
{icon = "fas fa-arrow-left", title = _U('return'), value = "return"}
}
ESX.RefreshContext(elements)
elseif element.value == "confirm2" then
Expand All @@ -128,10 +81,10 @@ function OpenBossMenu(society, _, options)
end
elseif element.value == "wash_money" then
local elements = {
{unselectable = true, icon = "fas fa-wallet", title = _U('wash_money_amount'), description = "Deposit some money into the money wash"},
{icon = "fas fa-wallet", title = "Amount", input = true, inputType = "number", inputPlaceholder = "Amount to wash..", inputMin = 1, inputMax = 250000, name = "wash"},
{icon = "fas fa-check", title = "Confirm", value = "confirm3"},
{icon = "fas fa-arrow-left", title = "Return", value = "return"}
{unselectable = true, icon = "fas fa-wallet", title = _U('wash_money_amount'), description = _U('wash_money_description')},
{icon = "fas fa-wallet", title = _U('amount_title'), input = true, inputType = "number", inputPlaceholder = _U('money_wash_amount_placeholder'), inputMin = 1, inputMax = 250000, name = "wash"},
{icon = "fas fa-check", title = _U('confirm'), value = "confirm3"},
{icon = "fas fa-arrow-left", title = _U('return'), value = "return"}
}
ESX.RefreshContext(elements)
elseif element.value == "confirm3" then
Expand All @@ -151,7 +104,7 @@ function OpenBossMenu(society, _, options)
elseif element.value == "return" then
OpenBossMenu(society, nil, options)
end
end)
end, close)
end
end, society)
end
Expand All @@ -162,14 +115,14 @@ function OpenManageEmployeesMenu(society, options)
{icon = "fas fa-users", title = _U('employee_list'), value = "employee_list"},
{icon = "fas fa-users", title = _U('recruit'), value = "recruit"}
}

elements[#elements+1] = {icon = "fas fa-arrow-left", title = "Return", value = "return"}

ESX.OpenContext("right", elements, function(_, element)
elements[#elements+1] = {icon = "fas fa-arrow-left", title = _U('return'), value = "return"}
ESX.OpenContext("right", elements, function(menu,element)
if element.value == "employee_list" then
OpenEmployeeList(society, options)
elseif element.value == "recruit" then
OpenRecruitMenu(society, options)
OpenRecruitMenu(society, options)
elseif element.value == "return" then
OpenBossMenu(society, nil, options)
end
Expand All @@ -179,7 +132,7 @@ end
function OpenEmployeeList(society, options)
ESX.TriggerServerCallback('esx_society:getEmployees', function(employees)
local elements = {
{unselectable = true, icon = "fas fa-user", title = "Employees"}
{unselectable = true, icon = "fas fa-user", title = _U('employees_title')}
}

for i=1, #employees, 1 do
Expand All @@ -188,19 +141,19 @@ function OpenEmployeeList(society, options)
elements[#elements+1] = {icon = "fas fa-user", title = employees[i].name .. " | " ..gradeLabel, gradeLabel = gradeLabel, data = employees[i]}
end

elements[#elements+1] = {icon = "fas fa-arrow-left", title = "Return", value = "return"}
elements[#elements+1] = {icon = "fas fa-arrow-left", title = _U('return'), value = "return"}

ESX.OpenContext("right", elements, function(_,element)
ESX.OpenContext("right", elements, function(menu,element)
if element.value == "return" then
OpenManageEmployeesMenu(society, options)
else
local elements2 = {
{unselectable = true, icon = "fas fa-user", title = element.title},
{icon = "fas fa-user", title = "Promote", value = "promote"},
{icon = "fas fa-user", title = "Fire", value = "fire"},
{icon = "fas fa-arrow-left", title = "Return", value = "return"}
{icon = "fas fa-user", title = _U('promote'), value = "promote"},
{icon = "fas fa-user", title = _U('fire'), value = "fire"},
{icon = "fas fa-arrow-left", title = _U('return'), value = "return"}
}
ESX.OpenContext("right", elements2, function(_,element2)
ESX.OpenContext("right", elements2, function(menu2,element2)
local employee = element.data
if element2.value == "promote" then
ESX.CloseContext()
Expand Down Expand Up @@ -232,18 +185,18 @@ function OpenRecruitMenu(society, options)
end
end

elements[#elements+1] = {icon = "fas fa-arrow-left", title = "Return", value = "return"}
elements[#elements+1] = {icon = "fas fa-arrow-left", title = _U('return'), value = "return"}

ESX.OpenContext("right", elements, function(_,element)
ESX.OpenContext("right", elements, function(menu,element)
if element.value == "return" then
OpenManageEmployeesMenu(society, options)
else
local elements2 = {
{unselectable = true, icon = "fas fa-user", title = "Confirm"},
{unselectable = true, icon = "fas fa-user", title = _U('confirm')},
{icon = "fas fa-times", title = _U('no'), value = "no"},
{icon = "fas fa-check", title = _U('yes'), value = "yes"},
}
ESX.OpenContext("right", elements2, function(_,element2)
ESX.OpenContext("right", elements2, function(menu2,element2)
if element2.value == "yes" then
ESX.ShowNotification(_U('you_have_hired', element.name))

Expand All @@ -259,6 +212,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 = _U('promote_employee', employee.name)}
}
Expand All @@ -271,7 +228,7 @@ function OpenPromoteMenu(society, employee, options)

elements[#elements+1] = {icon = "fas fa-arrow-left", title = "Return", value = "return"}

ESX.OpenContext("right", elements, function(_, element)
ESX.OpenContext("right", elements, function(menu,element)
if element.value == "return" then
OpenEmployeeList(society, options)
else
Expand All @@ -281,14 +238,18 @@ function OpenPromoteMenu(society, employee, options)
OpenEmployeeList(society, options)
end, employee.identifier, society, element.value, 'promote')
end
end, function()
end, function(menu)
OpenEmployeeList(society, options)
end)
end, society)
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 = _U('salary_management')}
}
Expand All @@ -302,14 +263,15 @@ function OpenManageSalaryMenu(society, options)
value = job.grades[i].grade
}
end

elements[#elements+1] = {icon = "fas fa-arrow-left", title = "Return", value = "return"}
elements[#elements+1] = {icon = "fas fa-arrow-left", title = _U('return'), value = "return"}

ESX.OpenContext("right", elements, function(menu,element)
local elements = {
{unselectable = true, icon = "fas fa-wallet", title = element.title, description = "Change a grade salary amount", value = element.value},
{icon = "fas fa-wallet", title = "Amount", input = true, inputType = "number", inputPlaceholder = "Amount to change grade salary..", inputMin = 1, inputMax = Config.MaxSalary, name = "gradesalary"},
{icon = "fas fa-check", title = "Confirm", value = "confirm"}
{unselectable = true, icon = "fas fa-wallet", title = element.title, description = _U('change_salary_description'), value = element.value},
{icon = "fas fa-wallet", title = _U('amount_title'), input = true, inputType = "number", inputPlaceholder = _U('change_salary_placeholder'), inputMin = 1, inputMax = Config.MaxSalary, name = "gradesalary"},
{icon = "fas fa-check", title = _U('confirm'), value = "confirm"},
{icon = "fas fa-arrow-left", title = _U('return'), value = "return"}
}

ESX.RefreshContext(elements)
Expand Down Expand Up @@ -337,6 +299,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 = _U('grade_management')}
}
Expand All @@ -346,14 +312,15 @@ function OpenManageGradesMenu(society, options)

elements[#elements+1] = {icon = "fas fa-wallet", title = ('%s'):format(gradeLabel), value = job.grades[i].grade}
end

elements[#elements+1] = {icon = "fas fa-arrow-left", title = "Return", value = "return"}
elements[#elements+1] = {icon = "fas fa-arrow-left", title = _U('return'), value = "return"}

ESX.OpenContext("right", elements, function(menu,element)
local elements = {
{unselectable = true, icon = "fas fa-wallet", title = element.title, description = "Change a grade label", value = element.value},
{icon = "fas fa-wallet", title = "Label", input = true, inputType = "text", inputPlaceholder = "Label to change job grade label..", name = "gradelabel"},
{icon = "fas fa-check", title = "Confirm", value = "confirm"}
{unselectable = true, icon = "fas fa-wallet", title = element.title, description = _U('change_label_description'), value = element.value},
{icon = "fas fa-wallet", title = _U('change_label_title'), input = true, inputType = "text", inputPlaceholder = _U('change_label_placeholder'), name = "gradelabel"},
{icon = "fas fa-check", title = _U('confirm'), value = "confirm"},
{icon = "fas fa-arrow-left", title = _U('return'), value = "return"}
}

ESX.RefreshContext(elements)
Expand All @@ -378,5 +345,3 @@ end
AddEventHandler('esx_society:openBossMenu', function(society, close, options)
OpenBossMenu(society, close, options)
end)

if ESX.PlayerLoaded then RefreshBussHUD() end
9 changes: 8 additions & 1 deletion server-data/resources/[esx]/esx_society/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Config = {}

Config.Locale = 'it'
Config.Locale = 'en'
Config.EnableESXIdentity = true
Config.MaxSalary = 3500

Config.BossGrades = { -- Uncomment and/or add additional grades you want to have access to the boss menu.
['boss'] = true,
--['staff1'] = false,
--['staff2'] = false,
--['staff3'] = false,
}
3 changes: 1 addition & 2 deletions server-data/resources/[esx]/esx_society/esx_society.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ CREATE TABLE `society_moneywash` (
`amount` int NOT NULL,

PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4 changes: 2 additions & 2 deletions server-data/resources/[esx]/esx_society/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ game 'gta5'

description 'ESX Society'
lua54 'yes'
version '0.0.4'
version '1.0.0'

shared_script '@es_extended/imports.lua'

Expand All @@ -26,4 +26,4 @@ client_scripts {
dependencies {
'es_extended',
'esx_addonaccount'
}
}
Loading

0 comments on commit c51d8ff

Please sign in to comment.