Skip to content

Commit

Permalink
Merge pull request #739 from bitpredator/dev
Browse files Browse the repository at this point in the history
refactor: improved formatting + addition of billing via identifier and graphic reworking
  • Loading branch information
bitpredator authored Jun 28, 2024
2 parents 7ef04b9 + 74d1dc0 commit 2bc0319
Show file tree
Hide file tree
Showing 58 changed files with 7,350 additions and 9,092 deletions.
10 changes: 8 additions & 2 deletions server-data/resources/[bpt_addons]/bpt_billing/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ function ShowBillsMenu()
end

ESX.OpenContext("right", elements, function(menu, element)
ESX.TriggerServerCallback("bpt_billing:payBill", function()
local billId = element.billId

ESX.TriggerServerCallback("bpt_billing:payBill", function(resp)
if resp == true then
TriggerEvent("bpt_billing:paidBill", billId)
end

ShowBillsMenu()
end, element.billId)
end, billId)
end)
else
ESX.ShowNotification(TranslateCap("no_invoices"))
Expand Down
96 changes: 69 additions & 27 deletions server-data/resources/[bpt_addons]/bpt_billing/server/main.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,69 @@
RegisterNetEvent("bpt_billing:sendBill", function(playerId, sharedAccountName, label, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local xTarget = ESX.GetPlayerFromId(playerId)
function BillPlayerByIdentifier(targetIdentifier, senderIdentifier, sharedAccountName, label, amount)
local xTarget = ESX.GetPlayerFromIdentifier(targetIdentifier)
amount = ESX.Math.Round(amount)

if amount > 0 and xTarget then
if amount > 0 then
if string.match(sharedAccountName, "society_") then
local jobName = string.gsub(sharedAccountName, "society_", "")
if xPlayer.job.name ~= jobName then
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from a society (^5%s^7), but does not have the correct Job - Possibly Cheats"):format(xPlayer.source, sharedAccountName))
return
end
TriggerEvent("bpt_addonaccount:getSharedAccount", sharedAccountName, function(account)
if account then
MySQL.insert("INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (?, ?, ?, ?, ?, ?)", { xTarget.identifier, xPlayer.identifier, "society", sharedAccountName, label, amount }, function(rowsChanged)
MySQL.insert("INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (?, ?, ?, ?, ?, ?)", { targetIdentifier, senderIdentifier, "society", sharedAccountName, label, amount }, function(rowsChanged)
if not xTarget then
return
end

xTarget.showNotification(TranslateCap("received_invoice"))
end)
else
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from invalid society - ^5%s^7"):format(xPlayer.source, sharedAccountName))
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from invalid society - ^5%s^7"):format(senderIdentifier, sharedAccountName))
end
end)
else
MySQL.insert("INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (?, ?, ?, ?, ?, ?)", { xTarget.identifier, xPlayer.identifier, "player", xPlayer.identifier, label, amount }, function(rowsChanged)
MySQL.insert("INSERT INTO billing (identifier, sender, target_type, target, label, amount) VALUES (?, ?, ?, ?, ?, ?)", { targetIdentifier, senderIdentifier, "player", senderIdentifier, label, amount }, function(rowsChanged)
if not xTarget then
return
end

xTarget.showNotification(TranslateCap("received_invoice"))
end)
end
end
end

function BillPlayer(targetId, senderIdentifier, sharedAccountName, label, amount)
local xTarget = ESX.GetPlayerFromId(targetId)

if not xTarget then
return
end

BillPlayerByIdentifier(xTarget.identifier, senderIdentifier, sharedAccountName, label, amount)
end

RegisterNetEvent("bpt_billing:sendBill", function(targetId, sharedAccountName, label, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local jobName = string.gsub(sharedAccountName, "society_", "")

if xPlayer.job.name ~= jobName then
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from a society (^5%s^7), but does not have the correct Job - Possibly Cheats"):format(xPlayer.source, sharedAccountName))
return
end

BillPlayer(targetId, xPlayer.identifier, sharedAccountName, label, amount)
end)
exports("BillPlayer", BillPlayer)

RegisterNetEvent("bpt_billing:sendBillToIdentifier", function(targetIdentifier, sharedAccountName, label, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local jobName = string.gsub(sharedAccountName, "society_", "")

if xPlayer.job.name ~= jobName then
print(("[^2ERROR^7] Player ^5%s^7 Attempted to Send bill from a society (^5%s^7), but does not have the correct Job - Possibly Cheats"):format(xPlayer.source, sharedAccountName))
return
end

BillPlayerByIdentifier(targetIdentifier, xPlayer.identifier, sharedAccountName, label, amount)
end)
exports("BillPlayerByIdentifier", BillPlayerByIdentifier)

ESX.RegisterServerCallback("bpt_billing:getBills", function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
Expand Down Expand Up @@ -62,33 +100,35 @@ ESX.RegisterServerCallback("bpt_billing:payBill", function(source, cb, billId)
if rowsChanged == 1 then
xPlayer.removeMoney(amount, "Bill Paid")
xTarget.addMoney(amount, "Paid bill")

TriggerEvent("bpt_billing:paidBill", source, billId)
xPlayer.showNotification(TranslateCap("paid_invoice", ESX.Math.GroupDigits(amount)))
xTarget.showNotification(TranslateCap("received_payment", ESX.Math.GroupDigits(amount)))
cb(true)
else
cb(false)
end

cb()
end)
elseif xPlayer.getAccount("bank").money >= amount then
MySQL.update("DELETE FROM billing WHERE id = ?", { billId }, function(rowsChanged)
if rowsChanged == 1 then
xPlayer.removeAccountMoney("bank", amount, "Bill Paid")
xTarget.addAccountMoney("bank", amount, "Paid bill")

TriggerEvent("bpt_billing:paidBill", source, billId)
xPlayer.showNotification(TranslateCap("paid_invoice", ESX.Math.GroupDigits(amount)))
xTarget.showNotification(TranslateCap("received_payment", ESX.Math.GroupDigits(amount)))
cb(true)
else
cb(false)
end

cb()
end)
else
xTarget.showNotification(TranslateCap("target_no_money"))
xPlayer.showNotification(TranslateCap("no_money"))
cb()
cb(false)
end
else
xPlayer.showNotification(TranslateCap("player_not_online"))
cb()
cb(false)
end
else
TriggerEvent("bpt_addonaccount:getSharedAccount", result.target, function(account)
Expand All @@ -97,36 +137,38 @@ ESX.RegisterServerCallback("bpt_billing:payBill", function(source, cb, billId)
if rowsChanged == 1 then
xPlayer.removeMoney(amount, "Bill Paid")
account.addMoney(amount)

TriggerEvent("bpt_billing:paidBill", source, billId)
xPlayer.showNotification(TranslateCap("paid_invoice", ESX.Math.GroupDigits(amount)))
if xTarget then
xTarget.showNotification(TranslateCap("received_payment", ESX.Math.GroupDigits(amount)))
end
cb(true)
else
cb(false)
end

cb()
end)
elseif xPlayer.getAccount("bank").money >= amount then
MySQL.update("DELETE FROM billing WHERE id = ?", { billId }, function(rowsChanged)
if rowsChanged == 1 then
xPlayer.removeAccountMoney("bank", amount, "Bill Paid")
account.addMoney(amount)
xPlayer.showNotification(TranslateCap("paid_invoice", ESX.Math.GroupDigits(amount)))

TriggerEvent("bpt_billing:paidBill", source, billId)
if xTarget then
xTarget.showNotification(TranslateCap("received_payment", ESX.Math.GroupDigits(amount)))
end
cb(true)
else
cb(false)
end

cb()
end)
else
if xTarget then
xTarget.showNotification(TranslateCap("target_no_money"))
end

xPlayer.showNotification(TranslateCap("no_money"))
cb()
cb(false)
end
end)
end
Expand Down
6 changes: 3 additions & 3 deletions server-data/resources/[esx_addons]/esx-qalle-jail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

```lua
elements = {
{label = _U('citizen_interaction'), value = 'citizen_interaction'},
{label = _U('vehicle_interaction'), value = 'vehicle_interaction'},
{label = _U('object_spawner'), value = 'object_spawner'},
{label = TranslateCap('citizen_interaction'), value = 'citizen_interaction'},
{label = TranslateCap('vehicle_interaction'), value = 'vehicle_interaction'},
{label = TranslateCap('object_spawner'), value = 'object_spawner'},
{label = "Jail Menu", value = 'jail_menu'} -- You add this line
}
}, function(data, menu)
Expand Down
Loading

0 comments on commit 2bc0319

Please sign in to comment.