diff --git a/atms.lua b/atms.lua index d36e62c..4de767f 100644 --- a/atms.lua +++ b/atms.lua @@ -3,7 +3,6 @@ local QBCore = exports['qb-core']:GetCoreObject() -- This script is a simple replacement for QB-Banking and QB-ATMs -- It uses QB-Input and server callbacks to retreive info about accounts and cash -- This requires QB-Target and has the location of every ATM, ATM prop and bank window --- If Config.useATM = false, then none of this load Config.ATMModels = {"prop_atm_01", "prop_atm_02", "prop_atm_03", "prop_fleeca_atm" } @@ -88,7 +87,6 @@ Config.BankLocations = { --vector3(252.41, 221.41, 106.29) } - local function cv(amount) local formatted = amount while true do @@ -161,14 +159,15 @@ Citizen.CreateThread(function() end end end - end + end end if Config.useATM then exports['qb-target']:AddTargetModel(Config.ATMModels, { options = { { event = "jim-payments:Client:ATM:use", icon = "fas fa-money-check-alt", label = "Use ATM", id = "atm" },}, distance = 1.5, }) for k,v in pairs(Config.ATMLocations) do exports['qb-target']:AddCircleZone("jimatm"..k, vector3(tonumber(v.x), tonumber(v.y), tonumber(v.z)+0.2), 0.5, { name="jimatm"..k, debugPoly=false, useZ=true, }, { options = { { event = "jim-payments:Client:ATM:use", icon = "fas fa-money-check-alt", label = "Use ATM", id = "atm" }, - --[[{ event = "jim-payments:Client:ATM:use", icon = "fas fa-arrow-right-arrow-left", label = "Transfer Money", id = "transfer" },]] }, distance = 1.5 }) + --[[{ event = "jim-payments:Client:ATM:use", icon = "fas fa-arrow-right-arrow-left", label = "Transfer Money", id = "transfer" },]] + }, distance = 1.5 }) end end if Config.useBanks then @@ -198,26 +197,29 @@ local function PlayATMAnimation(animation) end end +local function GrabAccount(type, job) + local p = promise.new() + QBCore.Functions.TriggerCallback('jim-payments:ManageWrapper', function(cb) p:resolve(cb) end, type, job) + return Citizen.Await(p) +end + RegisterNetEvent('jim-payments:Client:ATM:use', function(data) --this grabs all the info from names to savings account numbers in the databases while name == nil do QBCore.Functions.TriggerCallback('jim-payments:ATM:Find', function(cb1, cb2, cb3, cb4, cb5, cb6, cb7) name = cb1 cash = cb2 bank = cb3 account = cb4 cid = cb5 savbal = cb6 aid = cb7 end) Citizen.Wait(100) end - while society == nil do - QBCore.Functions.TriggerCallback('qb-bossmenu:server:GetAccount', function(cb) society = cb end, PlayerJob.name) - Citizen.Wait(100) - end - while gsociety == nil do - QBCore.Functions.TriggerCallback('qb-gangmenu:server:GetAccount', function(cb) gsociety = cb end, PlayerGang.name) - Citizen.Wait(100) - end + + society = GrabAccount("GetAccount", PlayerJob.name) + Wait(200) + gsociety = GrabAccount("GetGangAccount", PlayerGang.name) + local atmbartime = 2500 local setoptions = {} if data.id == "atm" then setoptions = { { value = "withdraw", text = "Withdrawl" }, } - setview = "Welcome back, "..name.."

- Citizen ID -
"..cid.."

- Balances -
🏦Bank - $"..cv(bank).."
💵Cash - $"..cv(cash)..'

- Options -' + setview = "

Welcome back, "..name.."

- Citizen ID -
"..cid.."

- Balances -
🏦Bank - $"..cv(bank).."
💵Cash - $"..cv(cash)..'

- Options -' setheader = "💵 ATM Banking 💵" setinputs = { { type = 'radio', name = 'billtype', text = setview, options = setoptions }, { type = 'number', isRequired = true, name = 'amount', text = '💵 Amount to transfer' }, } @@ -372,4 +374,4 @@ RegisterNetEvent('jim-payments:client:ATM:give', function() TriggerServerEvent('jim-payments:server:ATM:give', dialog.citizen, dialog.price) end end) -end) +end) \ No newline at end of file diff --git a/atmserver.lua b/atmserver.lua index ac9e024..746fecd 100644 --- a/atmserver.lua +++ b/atmserver.lua @@ -13,6 +13,16 @@ end ---- BANK STUFF +QBCore.Functions.CreateCallback('jim-payments:ManageWrapper', function(source, cb, type, account) + local result = nil + if type == "GetAccount" then result = exports["qb-management"]:GetAccount(account) end + if type == "GetGangAccount" then result = exports["qb-management"]:GetGangAccount(account) end + + print(type.." "..account.." "..result) + + cb(result) +end) + RegisterServerEvent('jim-payments:server:ATM:use', function(amount, billtype, baccount, account, society, gsociety) local src = source local Player = QBCore.Functions.GetPlayer(src) @@ -72,12 +82,14 @@ RegisterServerEvent('jim-payments:server:ATM:use', function(amount, billtype, ba elseif tonumber(society) >= amount then TriggerClientEvent("QBCore:Notify", src, "Withdrew $"..cv(amount).." from the "..Player.PlayerData.job.label.." account", "success") Player.Functions.AddMoney('bank', amount) - TriggerEvent("qb-bossmenu:server:removeAccountMoney", tostring(Player.PlayerData.job.name), amount) + exports["qb-management"]:RemoveMoney(tostring(Player.PlayerData.job.name), amount) + --TriggerEvent("qb-bossmenu:server:removeAccountMoney", tostring(Player.PlayerData.job.name), amount) end elseif billtype == "deposit" then if bankB < amount then TriggerClientEvent("QBCore:Notify", src, "Not enough money in your bank", "error") elseif bankB >= amount then - TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(Player.PlayerData.job.name), amount) + exports["qb-management"]:AddMoney(tostring(Player.PlayerData.job.name), amount) + --TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(Player.PlayerData.job.name), amount) Player.Functions.RemoveMoney('bank', amount) Wait(1500) TriggerClientEvent("QBCore:Notify", src, "Deposited $"..cv(amount).." into the "..Player.PlayerData.job.label.." account", "success") end @@ -100,7 +112,8 @@ RegisterServerEvent('jim-payments:server:ATM:use', function(amount, billtype, ba local result = MySQL.Sync.fetchAll('SELECT * FROM players WHERE charinfo LIKE ?', {query}) if result[1] ~= nil then local Reciever = QBCore.Functions.GetPlayerByCitizenId(result[1].citizenid) - TriggerEvent("qb-bossmenu:server:removeAccountMoney", tostring(Player.PlayerData.job.name), amount) + exports["qb-management"]:RemoveMoney(tostring(Player.PlayerData.job.name), amount) + --TriggerEvent("qb-bossmenu:server:removeAccountMoney", tostring(Player.PlayerData.job.name), amount) if Reciever ~= nil then Reciever.Functions.AddMoney('bank', amount) TriggerClientEvent("QBCore:Notify", src, "Sent $"..amount.." to "..Reciever.PlayerData.charinfo.firstname.." "..Reciever.PlayerData.charinfo.lastname, "success") @@ -121,12 +134,14 @@ RegisterServerEvent('jim-payments:server:ATM:use', function(amount, billtype, ba elseif tonumber(gsociety) >= amount then TriggerClientEvent("QBCore:Notify", src, "Withdrew $"..cv(amount).." from the "..Player.PlayerData.gang.label.." account", "success") Player.Functions.AddMoney('bank', amount) - TriggerEvent("qb-gangmenu:server:removeAccountMoney", tostring(Player.PlayerData.gang.name), amount) + exports["qb-management"]:RemoveGangMoney(tostring(Player.PlayerData.gang.name), amount) + --TriggerEvent("qb-gangmenu:server:removeAccountMoney", tostring(Player.PlayerData.gang.name), amount) end elseif billtype == "deposit" then if bankB < amount then TriggerClientEvent("QBCore:Notify", src, "Not enough money in your bank", "error") elseif bankB >= amount then - TriggerEvent("qb-gangmenu:server:addAccountMoney", tostring(Player.PlayerData.gang.name), amount) + exports["qb-management"]:AddGangMoney(tostring(Player.PlayerData.gang.name), amount) + --TriggerEvent("qb-gangmenu:server:addAccountMoney", tostring(Player.PlayerData.gang.name), amount) Player.Functions.RemoveMoney('bank', amount) Wait(1500) TriggerClientEvent("QBCore:Notify", src, "Deposited $"..cv(amount).." into the "..Player.PlayerData.gang.label.." account", "success") end @@ -149,7 +164,8 @@ RegisterServerEvent('jim-payments:server:ATM:use', function(amount, billtype, ba local result = MySQL.Sync.fetchAll('SELECT * FROM players WHERE charinfo LIKE ?', {query}) if result[1] ~= nil then local Reciever = QBCore.Functions.GetPlayerByCitizenId(result[1].citizenid) - TriggerEvent("qb-bossmenu:server:removeAccountMoney", tostring(Player.PlayerData.gang.name), amount) + exports["qb-management"]:RemoveGangMoney(tostring(Player.PlayerData.gang.name), amount) + --TriggerEvent("qb-bossmenu:server:removeAccountMoney", tostring(Player.PlayerData.gang.name), amount) if Reciever ~= nil then Reciever.Functions.AddMoney('bank', amount) TriggerClientEvent("QBCore:Notify", src, "Sent $"..amount.." to "..Reciever.PlayerData.charinfo.firstname.." "..Reciever.PlayerData.charinfo.lastname, "success") @@ -233,9 +249,9 @@ RegisterServerEvent("jim-payments:server:ATM:give", function(citizen, price) Player.Functions.RemoveMoney('cash', amount) TriggerClientEvent("QBCore:Notify", source, "You gave "..Reciever.PlayerData.charinfo.firstname.." $"..cv(amount), "success") Reciever.Functions.AddMoney('cash', amount) - TriggerClientEvent("QBCore:Notify", tonumber(citizen), "You got $"..cv(amount).." from "..Player.PlayerData.charinfo.firstname, "success") + TriggerClientEvent("QBCore:Notify", tonumber(citizen), "You got $"..cv(amount).." from "..Reciever.PlayerData.charinfo.firstname, "success") elseif balance < amount then TriggerClientEvent("QBCore:Notify", source, "You don't have enough cash to give", "error") end else TriggerClientEvent('QBCore:Notify', source, "You can't give $0", 'error') end -end) +end) \ No newline at end of file diff --git a/client.lua b/client.lua index d391f53..3565bba 100644 --- a/client.lua +++ b/client.lua @@ -27,9 +27,9 @@ RegisterNetEvent('jim-payments:client:Charge', function(data) local dist = #(GetEntityCoords(GetPlayerPed(v)) - GetEntityCoords(PlayerPedId())) for i = 1, #onlineList do if onlineList[i].value == GetPlayerServerId(v) then - if v ~= PlayerId() then + -- if v ~= PlayerId() then nearbyList[#nearbyList+1] = { value = onlineList[i].value, text = onlineList[i].text..' ('..math.floor(dist+0.05)..'m)' } - end + -- end end end dist = nil @@ -44,7 +44,7 @@ RegisterNetEvent('jim-payments:client:Charge', function(data) }) if dialog then if not dialog.citizen or not dialog.price then return end - TriggerServerEvent('jim-payments:server:Charge', dialog.citizen, dialog.price, dialog.billtype) + TriggerServerEvent('jim-payments:server:Charge', dialog.citizen, dialog.price, dialog.billtype, data.img) end end) end) @@ -62,9 +62,9 @@ RegisterNetEvent('jim-payments:Tickets:Menu', function() end end) -RegisterNetEvent("jim-payments:client:PayPopup", function(amount, biller, billtype) +RegisterNetEvent("jim-payments:client:PayPopup", function(amount, biller, billtype, img) exports['qb-menu']:openMenu({ - { isMenuHeader = true, header = "🧾 "..PlayerJob.label.." Payment 🧾", txt = "Do you want accept the payment?" }, + { isMenuHeader = true, header = img.."🧾 "..PlayerJob.label.." Payment 🧾", txt = "Do you want accept the payment?" }, { isMenuHeader = true, header = "", txt = billtype:gsub("^%l", string.upper).." Payment: $"..amount }, { header = "✅ Yes", txt = "", params = { isServer = true, event = "jim-payments:server:PayPopup", args = { accept = true, amount = amount, biller = biller, billtype = billtype } } }, { header = "❌ No", txt = "", params = { isServer = true, event = "jim-payments:server:PayPopup", args = { accept = false, amount = amount, biller = biller, billtype = billtype } } }, }) diff --git a/fxmanifest.lua b/fxmanifest.lua index 673b140..f2b84d8 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -7,7 +7,8 @@ game "gta5" dependencies { 'qb-input', - 'qb-target' + 'qb-target', + 'qb-management' } client_scripts { diff --git a/server.lua b/server.lua index fca07e2..1036759 100644 --- a/server.lua +++ b/server.lua @@ -11,6 +11,9 @@ local function cv(amount) return formatted end +AddEventHandler('onResourceStart', function(resource) if GetCurrentResourceName() == resource then + print(exports["qb-management"]:GetAccount("police")) end end) + --QBCore.Commands.Add("cashregister", "Use mobile cash register", {}, false, function(source) TriggerClientEvent("jim-payments:client:Charge", source, true) end) RegisterServerEvent('jim-payments:Tickets:Give', function(amount, job) @@ -51,7 +54,7 @@ QBCore.Functions.CreateCallback('jim-payments:Ticket:Count', function(source, cb cb(amount) end) -RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype) +RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype, img) local src = source local biller = QBCore.Functions.GetPlayer(src) local billed = QBCore.Functions.GetPlayer(tonumber(citizen)) @@ -59,14 +62,14 @@ RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billt if amount and amount > 0 then if billtype == "cash" then balance = billed.Functions.GetMoney(billtype) if balance >= amount then - TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype) + TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype, img) elseif balance < amount then TriggerClientEvent("QBCore:Notify", src, "Customer doesn't have enough cash to pay", "error") TriggerClientEvent("QBCore:Notify", tonumber(citizen), "You don't have enough cash to pay", "error") end elseif billtype == "card" then if Config.PhoneBank == false then - TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype) + TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype, img) else MySQL.Async.insert( 'INSERT INTO phone_invoices (citizenid, amount, society, sender, sendercitizenid) VALUES (?, ?, ?, ?, ?)', @@ -81,13 +84,13 @@ end) RegisterServerEvent("jim-payments:server:PayPopup", function(data) local src = source - local billtype = data.billtype - local billed = QBCore.Functions.GetPlayer(src) - local biller = QBCore.Functions.GetPlayer(tonumber(data.biller)) - if billtype == "card" then billtype = "bank" end + local billed = QBCore.Functions.GetPlayer(src) + local biller = QBCore.Functions.GetPlayer(tonumber(data.biller)) if data.accept == true then - billed.Functions.RemoveMoney(tostring(billtype), data.amount) TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), data.amount) - TriggerEvent('jim-payments:Tickets:Give', data.amount, tostring(biller.PlayerData.job.name)) + billed.Functions.RemoveMoney(tostring(data.billtype), data.amount) + exports["qb-management"]:AddMoney(tostring(biller.PlayerData.job.name), data.amount) + --TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), data.amount) + TriggerEvent('jim-payments:Tickets:Give', data.amount, tostring(billed.PlayerData.job.name)) TriggerClientEvent("QBCore:Notify", data.biller, billed.PlayerData.charinfo.firstname.." accepted the payment", "success") elseif data.accept == false then TriggerClientEvent("QBCore:Notify", src, "You declined the payment") @@ -102,4 +105,4 @@ QBCore.Functions.CreateCallback('jim-payments:MakePlayerList', function(source, onlineList[#onlineList+1] = { value = tonumber(v), text = "["..v.."] - "..P.PlayerData.charinfo.firstname..' '..P.PlayerData.charinfo.lastname } end cb(onlineList) -end) +end) \ No newline at end of file