mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
Add files
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
|
||||
|
||||
description 'ESX Billing'
|
||||
|
||||
server_scripts {
|
||||
'@mysql-async/lib/MySQL.lua',
|
||||
'server/main.lua'
|
||||
}
|
||||
|
||||
client_scripts {
|
||||
'client/main.lua'
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
local Keys = {
|
||||
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
|
||||
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
|
||||
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
|
||||
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
|
||||
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
|
||||
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
|
||||
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
|
||||
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
|
||||
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
|
||||
}
|
||||
|
||||
ESX = nil
|
||||
local GUI = {}
|
||||
GUI.Time = 0
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while ESX == nil do
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
Citizen.Wait(0)
|
||||
end
|
||||
end)
|
||||
|
||||
function ShowBillsMenu()
|
||||
|
||||
ESX.TriggerServerCallback('esx_billing:getBills', function(bills)
|
||||
|
||||
ESX.UI.Menu.CloseAll()
|
||||
|
||||
local elements = {}
|
||||
|
||||
for i=1, #bills, 1 do
|
||||
table.insert(elements, {label = bills[i].label .. ' $' .. bills[i].amount, value = bills[i].id})
|
||||
end
|
||||
|
||||
ESX.UI.Menu.Open(
|
||||
'default', GetCurrentResourceName(), 'billing',
|
||||
{
|
||||
title = 'Factures',
|
||||
elements = elements
|
||||
},
|
||||
function(data, menu)
|
||||
|
||||
local billId = data.current.value
|
||||
|
||||
ESX.TriggerServerCallback('esx_billing:payBill', function()
|
||||
ShowBillsMenu()
|
||||
end, billId)
|
||||
|
||||
end,
|
||||
function(data, menu)
|
||||
menu.close()
|
||||
end
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
-- Key controls
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
|
||||
Wait(0)
|
||||
|
||||
if IsControlPressed(0, Keys["F7"]) and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'billing') and (GetGameTimer() - GUI.Time) > 150 then
|
||||
ShowBillsMenu()
|
||||
GUI.Time = GetGameTimer()
|
||||
end
|
||||
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE `billing` (
|
||||
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`identifier` varchar(255) NOT NULL,
|
||||
`sender` varchar(255) NOT NULL,
|
||||
`target_type` varchar(50) NOT NULL,
|
||||
`target` varchar(255) NOT NULL,
|
||||
`label` varchar(255) NOT NULL,
|
||||
`amount` int(11) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
ESX = nil
|
||||
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
RegisterServerEvent('esx_billing:sendBill')
|
||||
AddEventHandler('esx_billing:sendBill', function(playerId, sharedAccountName, label, amount)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local xPlayers = ESX.GetPlayers()
|
||||
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', sharedAccountName, function(account)
|
||||
|
||||
if account == nil then
|
||||
|
||||
for k, v in pairs(xPlayers) do
|
||||
if v.source == playerId then
|
||||
|
||||
MySQL.Async.execute(
|
||||
'INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)',
|
||||
{
|
||||
['@identifier'] = v.identifier,
|
||||
['@sender'] = xPlayer.identifier,
|
||||
['@target_type'] = 'player',
|
||||
['@target'] = xPlayer.identifier,
|
||||
['@label'] = label,
|
||||
['@amount'] = amount
|
||||
},
|
||||
function(rowsChanged)
|
||||
TriggerClientEvent('esx:showNotification', v.source, 'Vous avez ~r~reçu~s~ une facture')
|
||||
end
|
||||
)
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
for k, v in pairs(xPlayers) do
|
||||
|
||||
if v.source == playerId then
|
||||
|
||||
MySQL.Async.execute(
|
||||
'INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (@identifier, @sender, @target_type, @target, @label, @amount)',
|
||||
{
|
||||
['@identifier'] = v.identifier,
|
||||
['@sender'] = xPlayer.identifier,
|
||||
['@target_type'] = 'society',
|
||||
['@target'] = sharedAccountName,
|
||||
['@label'] = label,
|
||||
['@amount'] = amount
|
||||
},
|
||||
function(rowsChanged)
|
||||
TriggerClientEvent('esx:showNotification', v.source, 'Vous avez ~r~reçu~s~ une facture')
|
||||
end
|
||||
)
|
||||
|
||||
break
|
||||
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',
|
||||
{
|
||||
['@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
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
|
||||
ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, id)
|
||||
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM billing WHERE id = @id',
|
||||
{
|
||||
['@id'] = id
|
||||
},
|
||||
function(result)
|
||||
|
||||
local sender = result[1].sender
|
||||
local targetType = result[1].target_type
|
||||
local target = result[1].target
|
||||
local amount = result[1].amount
|
||||
local xPlayers = ESX.GetPlayers()
|
||||
local foundPlayer = nil
|
||||
|
||||
for k,v in pairs(xPlayers) do
|
||||
if v.identifier == sender then
|
||||
foundPlayer = v
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if targetType == 'player' then
|
||||
|
||||
if foundPlayer ~= nil then
|
||||
|
||||
if xPlayer.get('money') >= amount then
|
||||
|
||||
MySQL.Async.execute(
|
||||
'DELETE from billing WHERE id = @id',
|
||||
{
|
||||
['@id'] = id
|
||||
},
|
||||
function(rowsChanged)
|
||||
|
||||
xPlayer.removeMoney(amount)
|
||||
foundPlayer.addMoney(amount)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, 'Vous avez ~g~payé~s~ une facture de ~r~$' .. amount)
|
||||
TriggerClientEvent('esx:showNotification', foundPlayer.source, 'Vous avez ~g~reçu~s~ un paiement de ~g~$' .. amount)
|
||||
|
||||
cb()
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
else
|
||||
TriggerClientEvent('esx:showNotification', _source, 'Le joueur n\'est pas connecté')
|
||||
cb()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
TriggerEvent('esx_addonaccount:getSharedAccount', target, function(account)
|
||||
|
||||
MySQL.Async.execute(
|
||||
'DELETE from billing WHERE id = @id',
|
||||
{
|
||||
['@id'] = id
|
||||
},
|
||||
function(rowsChanged)
|
||||
|
||||
xPlayer.removeMoney(amount)
|
||||
account.addMoney(amount)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', xPlayer.source, 'Vous avez ~g~payé~s~ une facture de ~r~$' .. amount)
|
||||
|
||||
if foundPlayer ~= nil then
|
||||
TriggerClientEvent('esx:showNotification', foundPlayer.source, 'Vous avez ~g~reçu~s~ un paiement de ~g~$' .. amount)
|
||||
end
|
||||
|
||||
cb()
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end)
|
||||
Reference in New Issue
Block a user