Fixed lua executing boss menu, tab indent

This commit is contained in:
ElPumpo
2018-08-25 14:48:45 +02:00
parent 003d604739
commit b4ce61a75c
7 changed files with 440 additions and 515 deletions
+232 -276
View File
@@ -32,333 +32,296 @@ function UpdateSocietyMoneyHUDElement(money)
end
function OpenBossMenu(society, close, options)
local isBoss = nil
local options = options or {}
local elements = {}
local options = options or {}
local elements = {}
ESX.TriggerServerCallback('esx_society:isBoss', function(result)
isBoss = result
end, society)
local defaultOptions = {
withdraw = true,
deposit = true,
wash = true,
employees = true,
grades = true
}
while isBoss == nil do
Citizen.Wait(100)
end
for k,v in pairs(defaultOptions) do
if options[k] == nil then
options[k] = v
end
end
if not isBoss then
return
end
if options.withdraw then
table.insert(elements, {label = _U('withdraw_society_money'), value = 'withdraw_society_money'})
end
local defaultOptions = {
withdraw = true,
deposit = true,
wash = true,
employees = true,
grades = true
}
if options.deposit then
table.insert(elements, {label = _U('deposit_society_money'), value = 'deposit_money'})
end
for k,v in pairs(defaultOptions) do
if options[k] == nil then
options[k] = v
end
end
if options.wash then
table.insert(elements, {label = _U('wash_money'), value = 'wash_money'})
end
if options.withdraw then
table.insert(elements, {label = _U('withdraw_society_money'), value = 'withdraw_society_money'})
end
if options.employees then
table.insert(elements, {label = _U('employee_management'), value = 'manage_employees'})
end
if options.deposit then
table.insert(elements, {label = _U('deposit_society_money'), value = 'deposit_money'})
end
if options.grades then
table.insert(elements, {label = _U('salary_management'), value = 'manage_grades'})
end
if options.wash then
table.insert(elements, {label = _U('wash_money'), value = 'wash_money'})
end
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'boss_actions_' .. society,
{
title = 'Patron',
align = 'top-left',
elements = elements
},
function(data, menu)
if options.employees then
table.insert(elements, {label = _U('employee_management'), value = 'manage_employees'})
end
if data.current.value == 'withdraw_society_money' then
if options.grades then
table.insert(elements, {label = _U('salary_management'), value = 'manage_grades'})
end
ESX.UI.Menu.Open(
'dialog', GetCurrentResourceName(), 'withdraw_society_money_amount_' .. society,
{
title = _U('withdraw_amount')
},
function(data, menu)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boss_actions_' .. society,
{
title = _U('boss_menu'),
align = 'top-left',
elements = elements
}, function(data, menu)
local amount = tonumber(data.value)
if data.current.value == 'withdraw_society_money' then
if amount == nil then
ESX.ShowNotification(_U('invalid_amount'))
else
menu.close()
TriggerServerEvent('esx_society:withdrawMoney', society, amount)
end
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'withdraw_society_money_amount_' .. society,
{
title = _U('withdraw_amount')
}, function(data, menu)
end,
function(data, menu)
menu.close()
end
)
local amount = tonumber(data.value)
end
if amount == nil then
ESX.ShowNotification(_U('invalid_amount'))
else
menu.close()
TriggerServerEvent('esx_society:withdrawMoney', society, amount)
end
if data.current.value == 'deposit_money' then
end, function(data, menu)
menu.close()
end)
ESX.UI.Menu.Open(
'dialog', GetCurrentResourceName(), 'deposit_money_amount_' .. society,
{
title = _U('deposit_amount')
},
function(data, menu)
elseif data.current.value == 'deposit_money' then
local amount = tonumber(data.value)
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'deposit_money_amount_' .. society,
{
title = _U('deposit_amount')
}, function(data, menu)
if amount == nil then
ESX.ShowNotification(_U('invalid_amount'))
else
menu.close()
TriggerServerEvent('esx_society:depositMoney', society, amount)
end
local amount = tonumber(data.value)
end,
function(data, menu)
menu.close()
end
)
if amount == nil then
ESX.ShowNotification(_U('invalid_amount'))
else
menu.close()
TriggerServerEvent('esx_society:depositMoney', society, amount)
end
end
end, function(data, menu)
menu.close()
end)
if data.current.value == 'wash_money' then
elseif data.current.value == 'wash_money' then
ESX.UI.Menu.Open(
'dialog', GetCurrentResourceName(), 'wash_money_amount_' .. society,
{
title = _U('wash_money_amount')
},
function(data, menu)
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'wash_money_amount_' .. society,
{
title = _U('wash_money_amount')
}, function(data, menu)
local amount = tonumber(data.value)
local amount = tonumber(data.value)
if amount == nil then
ESX.ShowNotification(_U('invalid_amount'))
else
menu.close()
TriggerServerEvent('esx_society:washMoney', society, amount)
end
if amount == nil then
ESX.ShowNotification(_U('invalid_amount'))
else
menu.close()
TriggerServerEvent('esx_society:washMoney', society, amount)
end
end,
function(data, menu)
menu.close()
end
)
end, function(data, menu)
menu.close()
end)
end
elseif data.current.value == 'manage_employees' then
OpenManageEmployeesMenu(society)
elseif data.current.value == 'manage_grades' then
OpenManageGradesMenu(society)
end
if data.current.value == 'manage_employees' then
OpenManageEmployeesMenu(society)
end
if data.current.value == 'manage_grades' then
OpenManageGradesMenu(society)
end
end,
function(data, menu)
if close then
close(data, menu)
end
end
)
end, function(data, menu)
if close then
close(data, menu)
end
end)
end
function OpenManageEmployeesMenu(society)
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'manage_employees_' .. society,
{
title = _U('employee_management'),
align = 'top-left',
elements = {
{label = _U('employee_list'), value = 'employee_list'},
{label = _U('recruit'), value = 'recruit'},
}
},
function(data, menu)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'manage_employees_' .. society,
{
title = _U('employee_management'),
align = 'top-left',
elements = {
{label = _U('employee_list'), value = 'employee_list'},
{label = _U('recruit'), value = 'recruit'},
}
}, function(data, menu)
if data.current.value == 'employee_list' then
OpenEmployeeList(society)
end
if data.current.value == 'employee_list' then
OpenEmployeeList(society)
end
if data.current.value == 'recruit' then
OpenRecruitMenu(society)
end
end,
function(data, menu)
menu.close()
end
)
if data.current.value == 'recruit' then
OpenRecruitMenu(society)
end
end, function(data, menu)
menu.close()
end)
end
function OpenEmployeeList(society)
ESX.TriggerServerCallback('esx_society:getEmployees', function(employees)
ESX.TriggerServerCallback('esx_society:getEmployees', function(employees)
local elements = {
head = {_U('employee'), _U('grade'), _U('actions')},
rows = {}
}
local elements = {
head = {_U('employee'), _U('grade'), _U('actions')},
rows = {}
}
for i=1, #employees, 1 do
for i=1, #employees, 1 do
local gradeLabel = (employees[i].job.grade_label == '' and employees[i].job.label or employees[i].job.grade_label)
local gradeLabel = (employees[i].job.grade_label == '' and employees[i].job.label or employees[i].job.grade_label)
table.insert(elements.rows, {
data = employees[i],
cols = {
employees[i].name,
gradeLabel,
'{{' .. _U('promote') .. '|promote}} {{' .. _U('fire') .. '|fire}}'
}
})
end
table.insert(elements.rows, {
data = employees[i],
cols = {
employees[i].name,
gradeLabel,
'{{' .. _U('promote') .. '|promote}} {{' .. _U('fire') .. '|fire}}'
}
})
end
ESX.UI.Menu.Open(
'list', GetCurrentResourceName(), 'employee_list_' .. society,
elements,
function(data, menu)
ESX.UI.Menu.Open('list', GetCurrentResourceName(), 'employee_list_' .. society, elements, function(data, menu)
local employee = data.data
local employee = data.data
if data.value == 'promote' then
menu.close()
OpenPromoteMenu(society, employee)
end
if data.value == 'promote' then
menu.close()
OpenPromoteMenu(society, employee)
end
if data.value == 'fire' then
if data.value == 'fire' then
TriggerEvent('esx:showNotification', _U('you_have_fired', employee.name))
TriggerEvent('esx:showNotification', _U('you_have_fired', employee.name))
ESX.TriggerServerCallback('esx_society:setJob', function()
OpenEmployeeList(society)
end, employee.identifier, 'unemployed', 0, 'fire')
ESX.TriggerServerCallback('esx_society:setJob', function()
OpenEmployeeList(society)
end, employee.identifier, 'unemployed', 0, 'fire')
end
end
end, function(data, menu)
menu.close()
OpenManageEmployeesMenu(society)
end)
end,
function(data, menu)
menu.close()
OpenManageEmployeesMenu(society)
end
)
end, society)
end, society)
end
function OpenRecruitMenu(society)
ESX.TriggerServerCallback('esx_society:getOnlinePlayers', function(players)
ESX.TriggerServerCallback('esx_society:getOnlinePlayers', function(players)
local elements = {}
local elements = {}
for i=1, #players, 1 do
if players[i].job.name ~= society then
table.insert(elements, {label = players[i].name, value = players[i].source, name = players[i].name, identifier = players[i].identifier})
end
end
for i=1, #players, 1 do
if players[i].job.name ~= society then
table.insert(elements, {label = players[i].name, value = players[i].source, name = players[i].name, identifier = players[i].identifier})
end
end
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'recruit_' .. society,
{
title = _U('recruiting'),
align = 'top-left',
elements = elements
},
function(data, menu)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'recruit_' .. society,
{
title = _U('recruiting'),
align = 'top-left',
elements = elements
}, function(data, menu)
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'recruit_confirm_' .. society,
{
title = _U('do_you_want_to_recruit', data.current.name),
align = 'top-left',
elements = {
{label = _U('no'), value = 'no'},
{label = _U('yes'), value = 'yes'}
}
},
function(data2, menu2)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'recruit_confirm_' .. society,
{
title = _U('do_you_want_to_recruit', data.current.name),
align = 'top-left',
elements = {
{label = _U('no'), value = 'no'},
{label = _U('yes'), value = 'yes'}
}
}, function(data2, menu2)
menu2.close()
menu2.close()
if data2.current.value == 'yes' then
if data2.current.value == 'yes' then
TriggerEvent('esx:showNotification', _U('you_have_hired', data.current.name))
TriggerEvent('esx:showNotification', _U('you_have_hired', data.current.name))
ESX.TriggerServerCallback('esx_society:setJob', function()
OpenRecruitMenu(society)
end, data.current.identifier, society, 0, 'hire')
ESX.TriggerServerCallback('esx_society:setJob', function()
OpenRecruitMenu(society)
end, data.current.identifier, society, 0, 'hire')
end
end
end,
function(data2, menu2)
menu2.close()
end
)
end, function(data2, menu2)
menu2.close()
end)
end,
function(data, menu)
menu.close()
end
)
end, function(data, menu)
menu.close()
end)
end)
end)
end
function OpenPromoteMenu(society, employee)
ESX.TriggerServerCallback('esx_society:getJob', function(job)
ESX.TriggerServerCallback('esx_society:getJob', function(job)
local elements = {}
local elements = {}
for i=1, #job.grades, 1 do
local gradeLabel = (job.grades[i].label == '' and job.label or job.grades[i].label)
table.insert(elements, {label = gradeLabel, value = job.grades[i].grade, selected = (employee.job.grade == job.grades[i].grade)})
end
for i=1, #job.grades, 1 do
local gradeLabel = (job.grades[i].label == '' and job.label or job.grades[i].label)
table.insert(elements, {label = gradeLabel, value = job.grades[i].grade, selected = (employee.job.grade == job.grades[i].grade)})
end
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'promote_employee_' .. society,
{
title = _U('promote_employee', employee.name),
align = 'top-left',
elements = elements
},
function(data, menu)
menu.close()
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'promote_employee_' .. society,
{
title = _U('promote_employee', employee.name),
align = 'top-left',
elements = elements
}, function(data, menu)
menu.close()
TriggerEvent('esx:showNotification', _U('you_have_promoted', employee.name, data.current.label))
TriggerEvent('esx:showNotification', _U('you_have_promoted', employee.name, data.current.label))
ESX.TriggerServerCallback('esx_society:setJob', function()
OpenEmployeeList(society)
end, employee.identifier, society, data.current.value, 'promote')
ESX.TriggerServerCallback('esx_society:setJob', function()
OpenEmployeeList(society)
end, employee.identifier, society, data.current.value, 'promote')
end,
function(data, menu)
menu.close()
OpenEmployeeList(society)
end
)
end, function(data, menu)
menu.close()
OpenEmployeeList(society)
end)
end, society)
end, society)
end
@@ -392,7 +355,7 @@ function OpenManageGradesMenu(society)
if amount == nil then
ESX.ShowNotification(_U('invalid_amount'))
elseif amount >= Config.MaxSalary then
elseif amount > Config.MaxSalary then
ESX.ShowNotification(_U('invalid_amount_max'))
else
menu2.close()
@@ -416,51 +379,44 @@ end
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
PlayerData = xPlayer
PlayerData = xPlayer
DisableSocietyMoneyHUDElement()
DisableSocietyMoneyHUDElement()
if PlayerData.job.grade_name == 'boss' then
EnableSocietyMoneyHUDElement()
ESX.TriggerServerCallback('esx_society:getSocietyMoney', function(money)
UpdateSocietyMoneyHUDElement(money)
end, PlayerData.job.name)
end
if PlayerData.job.grade_name == 'boss' then
EnableSocietyMoneyHUDElement()
ESX.TriggerServerCallback('esx_society:getSocietyMoney', function(money)
UpdateSocietyMoneyHUDElement(money)
end, PlayerData.job.name)
end
end)
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
PlayerData.job = job
PlayerData.job = job
DisableSocietyMoneyHUDElement()
DisableSocietyMoneyHUDElement()
if PlayerData.job.grade_name == 'boss' then
EnableSocietyMoneyHUDElement()
ESX.TriggerServerCallback('esx_society:getSocietyMoney', function(money)
UpdateSocietyMoneyHUDElement(money)
end, PlayerData.job.name)
if PlayerData.job.grade_name == 'boss' then
EnableSocietyMoneyHUDElement()
ESX.TriggerServerCallback('esx_society:getSocietyMoney', function(money)
UpdateSocietyMoneyHUDElement(money)
end, PlayerData.job.name)
end
end
end)
RegisterNetEvent('esx_addonaccount:setMoney')
AddEventHandler('esx_addonaccount:setMoney', function(society, money)
if PlayerData.job ~= nil and PlayerData.job.grade_name == 'boss' and 'society_' .. PlayerData.job.name == society then
UpdateSocietyMoneyHUDElement(money)
end
if PlayerData.job ~= nil and PlayerData.job.grade_name == 'boss' and 'society_' .. PlayerData.job.name == society then
UpdateSocietyMoneyHUDElement(money)
end
end)
AddEventHandler('esx_society:openBossMenu', function(society, close, options)
OpenBossMenu(society, close, options)
OpenBossMenu(society, close, options)
end)
+1
View File
@@ -1,5 +1,6 @@
Locales['en'] = {
['actions'] = 'actions',
['boss_menu'] = 'boss menu',
['deposit_amount'] = 'deposit amount',
['deposit_society_money'] = 'deposit society money',
['do_you_want_to_recruit'] = 'do you want to recruit %s?',
+1
View File
@@ -1,5 +1,6 @@
Locales['fi'] = {
['actions'] = 'toiminnot',
['boss_menu'] = 'boss menu',
['deposit_amount'] = 'talletus summa',
['deposit_society_money'] = 'talleta yritykselle rahaa',
['do_you_want_to_recruit'] = 'do you want to recruit %s?',
+1
View File
@@ -1,5 +1,6 @@
Locales['fr'] = {
['actions'] = 'actions',
['boss_menu'] = 'patron',
['deposit_amount'] = 'montant du dépôt',
['deposit_society_money'] = 'déposer argent société',
['do_you_want_to_recruit'] = 'Voulez-vous recruter %s?',
+1
View File
@@ -1,5 +1,6 @@
Locales['pl'] = {
['actions'] = 'akcje',
['boss_menu'] = 'boss menu',
['deposit_amount'] = 'ilość depozytu',
['deposit_society_money'] = 'zdeponuj społeczne pieniądze',
['do_you_want_to_recruit'] = 'czy chcesz zrekrutować %s?',
+3 -2
View File
@@ -1,8 +1,9 @@
Locales['sv'] = {
['actions'] = 'handlingar ',
['actions'] = 'handlingar',
['boss_menu'] = 'chefmeny',
['deposit_amount'] = 'insättningsbelopp',
['deposit_society_money'] = 'insätt samhälls pengar',
['do_you_want_to_recruit'] = 'vill du anlita %s?',
['do_you_want_to_recruit'] = 'vill du anställa %s?',
['employee'] = 'anställd',
['employee_list'] = 'anställningslista',
['employee_management'] = 'medarbetarhantering',
+201 -237
View File
@@ -5,258 +5,227 @@ RegisteredSocieties = {}
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
function GetSociety(name)
for i=1, #RegisteredSocieties, 1 do
if RegisteredSocieties[i].name == name then
return RegisteredSocieties[i]
end
end
for i=1, #RegisteredSocieties, 1 do
if RegisteredSocieties[i].name == name then
return RegisteredSocieties[i]
end
end
end
AddEventHandler('onMySQLReady', function()
local result = MySQL.Sync.fetchAll('SELECT * FROM jobs', {})
local result = MySQL.Sync.fetchAll('SELECT * FROM jobs', {})
for i=1, #result, 1 do
Jobs[result[i].name] = result[i]
Jobs[result[i].name].grades = {}
end
for i=1, #result, 1 do
Jobs[result[i].name] = result[i]
Jobs[result[i].name].grades = {}
end
local result2 = MySQL.Sync.fetchAll('SELECT * FROM job_grades', {})
for i=1, #result2, 1 do
Jobs[result2[i].job_name].grades[tostring(result2[i].grade)] = result2[i]
end
local result2 = MySQL.Sync.fetchAll('SELECT * FROM job_grades', {})
for i=1, #result2, 1 do
Jobs[result2[i].job_name].grades[tostring(result2[i].grade)] = result2[i]
end
end)
AddEventHandler('esx_society:registerSociety', function(name, label, account, datastore, inventory, data)
local found = false
local found = false
local society = {
name = name,
label = label,
account = account,
datastore = datastore,
inventory = inventory,
data = data,
}
local society = {
name = name,
label = label,
account = account,
datastore = datastore,
inventory = inventory,
data = data,
}
for i=1, #RegisteredSocieties, 1 do
if RegisteredSocieties[i].name == name then
found = true
RegisteredSocieties[i] = society
break
end
end
if not found then
table.insert(RegisteredSocieties, society)
end
for i=1, #RegisteredSocieties, 1 do
if RegisteredSocieties[i].name == name then
found = true
RegisteredSocieties[i] = society
break
end
end
if not found then
table.insert(RegisteredSocieties, society)
end
end)
AddEventHandler('esx_society:getSocieties', function(cb)
cb(RegisteredSocieties)
cb(RegisteredSocieties)
end)
AddEventHandler('esx_society:getSociety', function(name, cb)
cb(GetSociety(name))
cb(GetSociety(name))
end)
RegisterServerEvent('esx_society:withdrawMoney')
AddEventHandler('esx_society:withdrawMoney', function(society, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local society = GetSociety(society)
local xPlayer = ESX.GetPlayerFromId(source)
local society = GetSociety(society)
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
if amount > 0 and account.money >= amount then
account.removeMoney(amount)
xPlayer.addMoney(amount)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_withdrawn', amount))
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
end)
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
if amount > 0 and account.money >= amount then
account.removeMoney(amount)
xPlayer.addMoney(amount)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_withdrawn', amount))
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
end)
end)
RegisterServerEvent('esx_society:depositMoney')
AddEventHandler('esx_society:depositMoney', function(society, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local society = GetSociety(society)
local xPlayer = ESX.GetPlayerFromId(source)
local society = GetSociety(society)
if amount > 0 and xPlayer.get('money') >= amount then
if amount > 0 and xPlayer.get('money') >= amount then
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
xPlayer.removeMoney(amount)
account.addMoney(amount)
end)
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
xPlayer.removeMoney(amount)
account.addMoney(amount)
end)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', amount))
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_deposited', amount))
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
end)
RegisterServerEvent('esx_society:washMoney')
AddEventHandler('esx_society:washMoney', function(society, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local account = xPlayer.getAccount('black_money')
amount = tonumber(amount)
if amount and amount > 0 and account.money >= amount then
local xPlayer = ESX.GetPlayerFromId(source)
local account = xPlayer.getAccount('black_money')
xPlayer.removeAccountMoney('black_money', amount)
if amount > 0 and account.money >= amount then
MySQL.Async.execute('INSERT INTO society_moneywash (identifier, society, amount) VALUES (@identifier, @society, @amount)',
{
['@identifier'] = xPlayer.identifier,
['@society'] = society,
['@amount'] = amount
}, function(rowsChanged)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('you_have', amount))
end)
xPlayer.removeAccountMoney('black_money', amount)
MySQL.Async.execute(
'INSERT INTO society_moneywash (identifier, society, amount) VALUES (@identifier, @society, @amount)',
{
['@identifier'] = xPlayer.identifier,
['@society'] = society,
['@amount'] = amount
},
function(rowsChanged)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('you_have', amount))
end
)
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_amount'))
end
end)
RegisterServerEvent('esx_society:putVehicleInGarage')
AddEventHandler('esx_society:putVehicleInGarage', function(societyName, vehicle)
local society = GetSociety(societyName)
local society = GetSociety(societyName)
TriggerEvent('esx_datastore:getSharedDataStore', society.datastore, function(store)
local garage = store.get('garage') or {}
table.insert(garage, vehicle)
store.set('garage', garage)
end)
TriggerEvent('esx_datastore:getSharedDataStore', society.datastore, function(store)
local garage = store.get('garage') or {}
table.insert(garage, vehicle)
store.set('garage', garage)
end)
end)
RegisterServerEvent('esx_society:removeVehicleFromGarage')
AddEventHandler('esx_society:removeVehicleFromGarage', function(societyName, vehicle)
local society = GetSociety(societyName)
local society = GetSociety(societyName)
TriggerEvent('esx_datastore:getSharedDataStore', society.datastore, function(store)
local garage = store.get('garage') or {}
TriggerEvent('esx_datastore:getSharedDataStore', society.datastore, function(store)
local garage = store.get('garage') or {}
for i=1, #garage, 1 do
if garage[i].plate == vehicle.plate then
table.remove(garage, i)
break
end
end
store.set('garage', garage)
end)
for i=1, #garage, 1 do
if garage[i].plate == vehicle.plate then
table.remove(garage, i)
break
end
end
store.set('garage', garage)
end)
end)
ESX.RegisterServerCallback('esx_society:getSocietyMoney', function(source, cb, societyName)
local society = GetSociety(societyName)
local society = GetSociety(societyName)
if society ~= nil then
if society ~= nil then
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
cb(account.money)
end)
else
cb(0)
end
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
cb(account.money)
end)
else
cb(0)
end
end)
ESX.RegisterServerCallback('esx_society:getEmployees', function(source, cb, society)
if Config.EnableESXIdentity then
if Config.EnableESXIdentity then
MySQL.Async.fetchAll(
'SELECT * FROM users WHERE job = @job ORDER BY job_grade DESC',
{ ['@job'] = society },
function (results)
local employees = {}
MySQL.Async.fetchAll('SELECT * FROM users WHERE job = @job ORDER BY job_grade DESC', {
['@job'] = society
}, function (results)
local employees = {}
for i=1, #results, 1 do
table.insert(employees, {
name = results[i].firstname .. ' ' .. results[i].lastname,
identifier = results[i].identifier,
job = {
name = results[i].job,
label = Jobs[results[i].job].label,
grade = results[i].job_grade,
grade_name = Jobs[results[i].job].grades[tostring(results[i].job_grade)].name,
grade_label = Jobs[results[i].job].grades[tostring(results[i].job_grade)].label,
}
})
end
for i=1, #results, 1 do
table.insert(employees, {
name = results[i].firstname .. ' ' .. results[i].lastname,
identifier = results[i].identifier,
job = {
name = results[i].job,
label = Jobs[results[i].job].label,
grade = results[i].job_grade,
grade_name = Jobs[results[i].job].grades[tostring(results[i].job_grade)].name,
grade_label = Jobs[results[i].job].grades[tostring(results[i].job_grade)].label,
}
})
end
cb(employees)
end
)
else
MySQL.Async.fetchAll(
'SELECT * FROM users WHERE job = @job ORDER BY job_grade DESC',
{ ['@job'] = society },
function (result)
local employees = {}
cb(employees)
end)
else
MySQL.Async.fetchAll('SELECT * FROM users WHERE job = @job ORDER BY job_grade DESC', {
['@job'] = society
}, function (result)
local employees = {}
for i=1, #result, 1 do
table.insert(employees, {
name = result[i].name,
identifier = result[i].identifier,
job = {
name = result[i].job,
label = Jobs[result[i].job].label,
grade = result[i].job_grade,
grade_name = Jobs[result[i].job].grades[tostring(result[i].job_grade)].name,
grade_label = Jobs[result[i].job].grades[tostring(result[i].job_grade)].label,
}
})
end
for i=1, #result, 1 do
table.insert(employees, {
name = result[i].name,
identifier = result[i].identifier,
job = {
name = result[i].job,
label = Jobs[result[i].job].label,
grade = result[i].job_grade,
grade_name = Jobs[result[i].job].grades[tostring(result[i].job_grade)].name,
grade_label = Jobs[result[i].job].grades[tostring(result[i].job_grade)].label,
}
})
end
cb(employees)
end
)
end
cb(employees)
end)
end
end)
ESX.RegisterServerCallback('esx_society:getJob', function(source, cb, society)
local job = json.decode(json.encode(Jobs[society]))
local grades = {}
local job = json.decode(json.encode(Jobs[society]))
local grades = {}
for k,v in pairs(job.grades) do
table.insert(grades, v)
end
for k,v in pairs(job.grades) do
table.insert(grades, v)
end
table.sort(grades, function(a, b)
return a.grade < b.grade
end)
job.grades = grades
cb(job)
table.sort(grades, function(a, b)
return a.grade < b.grade
end)
job.grades = grades
cb(job)
end)
@@ -274,90 +243,85 @@ ESX.RegisterServerCallback('esx_society:setJob', function(source, cb, identifier
elseif type == 'fire' then
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('you_have_been_fired', xPlayer.getJob().label))
end
end
else
MySQL.Async.execute(
'UPDATE users SET job = @job, job_grade = @job_grade WHERE identifier = @identifier',
MySQL.Async.execute('UPDATE users SET job = @job, job_grade = @job_grade WHERE identifier = @identifier',
{
['@job'] = job,
['@job_grade'] = grade,
['@identifier'] = identifier
},
function(rowsChanged)
}, function(rowsChanged)
cb()
end
)
end)
end
end)
ESX.RegisterServerCallback('esx_society:setJobSalary', function(source, cb, job, grade, salary)
MySQL.Async.execute(
'UPDATE job_grades SET salary = @salary WHERE job_name = @job_name AND grade = @grade',
{
['@salary'] = salary,
['@job_name'] = job,
['@grade'] = grade
},
function(rowsChanged)
MySQL.Async.execute('UPDATE job_grades SET salary = @salary WHERE job_name = @job_name AND grade = @grade',
{
['@salary'] = salary,
['@job_name'] = job,
['@grade'] = grade
}, function(rowsChanged)
Jobs[job].grades[tostring(grade)].salary = salary
Jobs[job].grades[tostring(grade)].salary = salary
local xPlayers = ESX.GetPlayers()
local xPlayers = ESX.GetPlayers()
for i=1, #xPlayers, 1 do
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.name == job and xPlayer.job.grade == grade then
xPlayer.setJob(job, grade)
end
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
end
if xPlayer.job.name == job and xPlayer.job.grade == grade then
xPlayer.setJob(job, grade)
end
end
cb()
end
)
cb()
end)
end)
ESX.RegisterServerCallback('esx_society:getOnlinePlayers', function(source, cb)
local xPlayers = ESX.GetPlayers()
local players = {}
local xPlayers = ESX.GetPlayers()
local players = {}
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
table.insert(players, {
source = xPlayer.source,
identifier = xPlayer.identifier,
name = xPlayer.name,
job = xPlayer.job
})
end
cb(players)
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
table.insert(players, {
source = xPlayer.source,
identifier = xPlayer.identifier,
name = xPlayer.name,
job = xPlayer.job
})
end
cb(players)
end)
ESX.RegisterServerCallback('esx_society:getVehiclesInGarage', function(source, cb, societyName)
local society = GetSociety(societyName)
TriggerEvent('esx_datastore:getSharedDataStore', society.datastore, function(store)
local garage = store.get('garage') or {}
cb(garage)
end)
local society = GetSociety(societyName)
TriggerEvent('esx_datastore:getSharedDataStore', society.datastore, function(store)
local garage = store.get('garage') or {}
cb(garage)
end)
end)
function WashMoneyCRON()
MySQL.Async.fetchAll(
'SELECT * FROM society_moneywash', {},
function(result)
ESX.RegisterServerCallback('esx_society:isBoss', function(source, cb, jobName)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.job.name == jobName and xPlayer.job.grade_name == 'boss' then
cb(true)
else
print(('esx_society: %s attempted open a society boss menu!'):format(xPlayer.identifier))
cb(false)
end
end)
function WashMoneyCRON(d, h, m)
MySQL.Async.fetchAll('SELECT * FROM society_moneywash', {}, function(result)
for i=1, #result, 1 do
-- add society money