mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
Minor cleanup, use RegisterKeyMapping() native, fixed not working on latest esx, closes #34
This commit is contained in:
+13
-23
@@ -1,4 +1,4 @@
|
||||
ESX = nil
|
||||
ESX = nil
|
||||
local isDead = false
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
@@ -9,20 +9,18 @@ Citizen.CreateThread(function()
|
||||
end)
|
||||
|
||||
function ShowBillsMenu()
|
||||
|
||||
ESX.TriggerServerCallback('esx_billing:getBills', function(bills)
|
||||
ESX.UI.Menu.CloseAll()
|
||||
local elements = {}
|
||||
|
||||
for i=1, #bills, 1 do
|
||||
for k,v in ipairs(bills) do
|
||||
table.insert(elements, {
|
||||
label = ('%s - <span style="color:red;">%s</span>'):format(bills[i].label, _U('invoices_item', ESX.Math.GroupDigits(bills[i].amount))),
|
||||
billID = bills[i].id
|
||||
label = ('%s - <span style="color:red;">%s</span>'):format(v.label, _U('invoices_item', ESX.Math.GroupDigits(v.amount))),
|
||||
billId = v.id
|
||||
})
|
||||
end
|
||||
|
||||
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'billing',
|
||||
{
|
||||
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'billing', {
|
||||
title = _U('invoices'),
|
||||
align = 'bottom-right',
|
||||
elements = elements
|
||||
@@ -31,28 +29,20 @@ function ShowBillsMenu()
|
||||
|
||||
ESX.TriggerServerCallback('esx_billing:payBill', function()
|
||||
ShowBillsMenu()
|
||||
end, data.current.billID)
|
||||
end, data.current.billId)
|
||||
end, function(data, menu)
|
||||
menu.close()
|
||||
end)
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
-- Key controls
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
if IsControlJustReleased(0, 168) and not isDead and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'billing') then
|
||||
ShowBillsMenu()
|
||||
end
|
||||
RegisterCommand('showbills', function()
|
||||
if not isDead and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'billing') then
|
||||
ShowBillsMenu()
|
||||
end
|
||||
end)
|
||||
end, false)
|
||||
|
||||
AddEventHandler('esx:onPlayerDeath', function(data)
|
||||
isDead = true
|
||||
end)
|
||||
RegisterKeyMapping('showbills', _U('keymap_showbills'), 'keyboard', 'F7')
|
||||
|
||||
AddEventHandler('playerSpawned', function(spawn)
|
||||
isDead = false
|
||||
end)
|
||||
AddEventHandler('esx:onPlayerDeath', function() isDead = true end)
|
||||
AddEventHandler('playerSpawned', function(spawn) isDead = false end)
|
||||
|
||||
@@ -7,4 +7,5 @@ Locales['br'] = {
|
||||
['player_not_online'] = 'o jogador não está na cidade',
|
||||
['no_money'] = 'você não tem dinheiro suficiente para pagar esta fatura',
|
||||
['target_no_money'] = 'o cidadão ~r~não tem~s~ dinheiro suficiente para pagar a conta!',
|
||||
['keymap_showbills'] = 'open bills menu',
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ Locales['de'] = {
|
||||
['player_not_online'] = 'der Spieler ist nicht online',
|
||||
['no_money'] = 'you do not have enough money to pay this bill',
|
||||
['target_no_money'] = 'the player ~r~does not~s~ have enough money to pay the bill!',
|
||||
['keymap_showbills'] = 'open bills menu',
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ Locales['en'] = {
|
||||
['player_not_online'] = 'the player is not logged in',
|
||||
['no_money'] = 'you do not have enough money to pay this bill',
|
||||
['target_no_money'] = 'the player ~r~does not~s~ have enough money to pay the bill!',
|
||||
['keymap_showbills'] = 'open bills menu',
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ Locales['es'] = {
|
||||
['player_not_online'] = 'el jugador no está conectado',
|
||||
['no_money'] = 'you do not have enough money to pay this bill',
|
||||
['target_no_money'] = 'the player ~r~does not~s~ have enough money to pay the bill!',
|
||||
['keymap_showbills'] = 'open bills menu',
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ Locales['fi'] = {
|
||||
['player_not_online'] = 'pelaaja ei ole sisäänkirjautuneena',
|
||||
['no_money'] = 'sinulla ei ole tarpeeksi rahaa maksaaksesi tätä laskua.',
|
||||
['target_no_money'] = 'pelaajalla ~r~ei ole~s~ tarpeeksi rahaa maksaakseentätä laskua',
|
||||
['keymap_showbills'] = 'open bills menu',
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ Locales['fr'] = {
|
||||
['player_not_online'] = 'le joueur n\'est pas connecté',
|
||||
['no_money'] = 'you do not have enough money to pay this bill',
|
||||
['target_no_money'] = 'the player ~r~does not~s~ have enough money to pay the bill!',
|
||||
['keymap_showbills'] = 'open bills menu',
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ Locales['pl'] = {
|
||||
['player_not_online'] = 'gracz nie jest zalogowany',
|
||||
['no_money'] = 'nie masz wystarczająco pieniędzy aby zapłacić tą fakture',
|
||||
['target_no_money'] = 'gracz ~r~nie posiada~s~ wystarczająco pieniędzy aby zapłacić tą fakture!',
|
||||
['keymap_showbills'] = 'open bills menu',
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ Locales['sv'] = {
|
||||
['player_not_online'] = 'personen är inte online',
|
||||
['no_money'] = 'du har ~r~inte råd~s~ för att kunna betala räkningen',
|
||||
['target_no_money'] = 'personen har ~r~inte råd~s~ för att betala räkningen',
|
||||
['keymap_showbills'] = 'open bills menu',
|
||||
}
|
||||
|
||||
+117
-166
@@ -4,205 +4,156 @@ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
RegisterServerEvent('esx_billing:sendBill')
|
||||
AddEventHandler('esx_billing:sendBill', function(playerId, sharedAccountName, label, amount)
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local xTarget = ESX.GetPlayerFromId(playerId)
|
||||
amount = ESX.Math.Round(amount)
|
||||
amount = ESX.Math.Round(amount)
|
||||
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', sharedAccountName, function(account)
|
||||
|
||||
if amount < 0 then
|
||||
print(('esx_billing: %s attempted to send a negative bill!'):format(xPlayer.identifier))
|
||||
elseif account == nil then
|
||||
|
||||
if xTarget ~= nil then
|
||||
MySQL.Async.execute('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)',
|
||||
{
|
||||
['@identifier'] = xTarget.identifier,
|
||||
['@sender'] = xPlayer.identifier,
|
||||
['@target_type'] = 'player',
|
||||
['@target'] = xPlayer.identifier,
|
||||
['@label'] = label,
|
||||
['@amount'] = amount
|
||||
}, function(rowsChanged)
|
||||
TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_invoice'))
|
||||
end)
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
if xTarget ~= nil then
|
||||
MySQL.Async.execute('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)',
|
||||
{
|
||||
['@identifier'] = xTarget.identifier,
|
||||
['@sender'] = xPlayer.identifier,
|
||||
if amount > 0 and xTarget then
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', sharedAccountName, function(account)
|
||||
if account then
|
||||
MySQL.Async.execute('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)', {
|
||||
['@identifier'] = xTarget.identifier,
|
||||
['@sender'] = xPlayer.identifier,
|
||||
['@target_type'] = 'society',
|
||||
['@target'] = sharedAccountName,
|
||||
['@label'] = label,
|
||||
['@amount'] = amount
|
||||
['@target'] = sharedAccountName,
|
||||
['@label'] = label,
|
||||
['@amount'] = amount
|
||||
}, function(rowsChanged)
|
||||
TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_invoice'))
|
||||
xTarget.showNotification(_U('received_invoice'))
|
||||
end)
|
||||
else
|
||||
MySQL.Async.execute('INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)', {
|
||||
['@identifier'] = xTarget.identifier,
|
||||
['@sender'] = xPlayer.identifier,
|
||||
['@target_type'] = 'player',
|
||||
['@target'] = xPlayer.identifier,
|
||||
['@label'] = label,
|
||||
['@amount'] = amount
|
||||
}, function(rowsChanged)
|
||||
xTarget.showNotification(_U('received_invoice'))
|
||||
end)
|
||||
end
|
||||
|
||||
end
|
||||
end)
|
||||
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_billing:getBills', function(source, cb)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM billing WHERE identifier = @identifier', {
|
||||
MySQL.Async.fetchAll('SELECT amount, id, label FROM billing WHERE identifier = @identifier', {
|
||||
['@identifier'] = xPlayer.identifier
|
||||
}, function(result)
|
||||
local bills = {}
|
||||
for i=1, #result, 1 do
|
||||
table.insert(bills, {
|
||||
id = result[i].id,
|
||||
identifier = result[i].identifier,
|
||||
sender = result[i].sender,
|
||||
targetType = result[i].target_type,
|
||||
target = result[i].target,
|
||||
label = result[i].label,
|
||||
amount = result[i].amount
|
||||
})
|
||||
end
|
||||
|
||||
cb(bills)
|
||||
cb(result)
|
||||
end)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_billing:getTargetBills', function(source, cb, target)
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM billing WHERE identifier = @identifier', {
|
||||
['@identifier'] = xPlayer.identifier
|
||||
}, function(result)
|
||||
local bills = {}
|
||||
for i=1, #result, 1 do
|
||||
table.insert(bills, {
|
||||
id = result[i].id,
|
||||
identifier = result[i].identifier,
|
||||
sender = result[i].sender,
|
||||
targetType = result[i].target_type,
|
||||
target = result[i].target,
|
||||
label = result[i].label,
|
||||
amount = result[i].amount
|
||||
})
|
||||
end
|
||||
|
||||
cb(bills)
|
||||
end)
|
||||
if xPlayer then
|
||||
MySQL.Async.fetchAll('SELECT amount, id, label FROM billing WHERE identifier = @identifier', {
|
||||
['@identifier'] = xPlayer.identifier
|
||||
}, function(result)
|
||||
cb(result)
|
||||
end)
|
||||
else
|
||||
cb({})
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, id)
|
||||
ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, billId)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM billing WHERE id = @id', {
|
||||
['@id'] = id
|
||||
MySQL.Async.fetchAll('SELECT sender, target_type, target, amount FROM billing WHERE id = @id', {
|
||||
['@id'] = billId
|
||||
}, function(result)
|
||||
if result[1] then
|
||||
local amount = result[1].amount
|
||||
local xTarget = ESX.GetPlayerFromIdentifier(result[1].sender)
|
||||
|
||||
local sender = result[1].sender
|
||||
local targetType = result[1].target_type
|
||||
local target = result[1].target
|
||||
local amount = result[1].amount
|
||||
if result[1].target_type == 'player' then
|
||||
if xTarget then
|
||||
if xPlayer.getMoney() >= amount then
|
||||
MySQL.Async.execute('DELETE FROM billing WHERE id = @id', {
|
||||
['@id'] = billId
|
||||
}, function(rowsChanged)
|
||||
if rowsChanged == 1 then
|
||||
xPlayer.removeMoney(amount)
|
||||
xTarget.addMoney(amount)
|
||||
|
||||
local xTarget = ESX.GetPlayerFromIdentifier(sender)
|
||||
xPlayer.showNotification(_U('paid_invoice', ESX.Math.GroupDigits(amount)))
|
||||
xTarget.showNotification(_U('received_payment', ESX.Math.GroupDigits(amount)))
|
||||
end
|
||||
|
||||
if targetType == 'player' then
|
||||
cb()
|
||||
end)
|
||||
elseif xPlayer.getAccount('bank').money >= amount then
|
||||
MySQL.Async.execute('DELETE FROM billing WHERE id = @id', {
|
||||
['@id'] = billId
|
||||
}, function(rowsChanged)
|
||||
if rowsChanged == 1 then
|
||||
xPlayer.removeAccountMoney('bank', amount)
|
||||
xTarget.addAccountMoney('bank', amount)
|
||||
|
||||
if xTarget ~= nil then
|
||||
|
||||
if xPlayer.getMoney() >= amount then
|
||||
|
||||
MySQL.Async.execute('DELETE from billing WHERE id = @id', {
|
||||
['@id'] = id
|
||||
}, function(rowsChanged)
|
||||
xPlayer.removeMoney(amount)
|
||||
xTarget.addMoney(amount)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', ESX.Math.GroupDigits(amount)))
|
||||
TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', ESX.Math.GroupDigits(amount)))
|
||||
xPlayer.showNotification(_U('paid_invoice', ESX.Math.GroupDigits(amount)))
|
||||
xTarget.showNotification(_U('received_payment', ESX.Math.GroupDigits(amount)))
|
||||
end
|
||||
|
||||
cb()
|
||||
end)
|
||||
else
|
||||
xTarget.showNotification(_U('target_no_money'))
|
||||
xPlayer.showNotification(_U('no_money'))
|
||||
cb()
|
||||
end)
|
||||
|
||||
elseif xPlayer.getBank() >= amount then
|
||||
|
||||
MySQL.Async.execute('DELETE from billing WHERE id = @id', {
|
||||
['@id'] = id
|
||||
}, function(rowsChanged)
|
||||
xPlayer.removeAccountMoney('bank', amount)
|
||||
xTarget.addAccountMoney('bank', amount)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', ESX.Math.GroupDigits(amount)))
|
||||
TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', ESX.Math.GroupDigits(amount)))
|
||||
|
||||
cb()
|
||||
end)
|
||||
|
||||
else
|
||||
TriggerClientEvent('esx:showNotification', xTarget.source, _U('target_no_money'))
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money'))
|
||||
|
||||
cb()
|
||||
end
|
||||
|
||||
else
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('player_not_online'))
|
||||
cb()
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', target, function(account)
|
||||
|
||||
if xPlayer.getMoney() >= amount then
|
||||
|
||||
MySQL.Async.execute('DELETE from billing WHERE id = @id', {
|
||||
['@id'] = id
|
||||
}, function(rowsChanged)
|
||||
xPlayer.removeMoney(amount)
|
||||
account.addMoney(amount)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', ESX.Math.GroupDigits(amount)))
|
||||
if xTarget ~= nil then
|
||||
TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', ESX.Math.GroupDigits(amount)))
|
||||
end
|
||||
|
||||
cb()
|
||||
end)
|
||||
|
||||
elseif xPlayer.getBank() >= amount then
|
||||
|
||||
MySQL.Async.execute('DELETE from billing WHERE id = @id', {
|
||||
['@id'] = id
|
||||
}, function(rowsChanged)
|
||||
xPlayer.removeAccountMoney('bank', amount)
|
||||
account.addMoney(amount)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', ESX.Math.GroupDigits(amount)))
|
||||
if xTarget ~= nil then
|
||||
TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', ESX.Math.GroupDigits(amount)))
|
||||
end
|
||||
|
||||
cb()
|
||||
end)
|
||||
|
||||
else
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money'))
|
||||
|
||||
if xTarget ~= nil then
|
||||
TriggerClientEvent('esx:showNotification', xTarget.source, _U('target_no_money'))
|
||||
end
|
||||
|
||||
else
|
||||
xPlayer.showNotification(_U('player_not_online'))
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
else
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', result[1].target, function(account)
|
||||
if xPlayer.getMoney() >= amount then
|
||||
MySQL.Async.execute('DELETE FROM billing WHERE id = @id', {
|
||||
['@id'] = billId
|
||||
}, function(rowsChanged)
|
||||
if rowsChanged == 1 then
|
||||
xPlayer.removeMoney(amount)
|
||||
account.addMoney(amount)
|
||||
|
||||
xPlayer.showNotification(_U('paid_invoice', ESX.Math.GroupDigits(amount)))
|
||||
if xTarget then
|
||||
xTarget.showNotification(_U('received_payment', ESX.Math.GroupDigits(amount)))
|
||||
end
|
||||
end
|
||||
|
||||
cb()
|
||||
end)
|
||||
elseif xPlayer.getAccount('bank').money >= amount then
|
||||
MySQL.Async.execute('DELETE FROM billing WHERE id = @id', {
|
||||
['@id'] = billId
|
||||
}, function(rowsChanged)
|
||||
if rowsChanged == 1 then
|
||||
xPlayer.removeAccountMoney('bank', amount)
|
||||
account.addMoney(amount)
|
||||
xPlayer.showNotification(_U('paid_invoice', ESX.Math.GroupDigits(amount)))
|
||||
|
||||
if xTarget then
|
||||
xTarget.showNotification(_U('received_payment', ESX.Math.GroupDigits(amount)))
|
||||
end
|
||||
end
|
||||
|
||||
cb()
|
||||
end)
|
||||
else
|
||||
if xTarget then
|
||||
xTarget.showNotification(_U('target_no_money'))
|
||||
end
|
||||
|
||||
xPlayer.showNotification(_U('no_money'))
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user