Files
jim-payments/client/charge.lua

168 lines
6.3 KiB
Lua
Raw Permalink Normal View History

2024-01-27 21:57:05 +00:00
local BankPed = nil
local Till = {}
function spawnCustomRegisters()
2025-04-13 13:14:20 +01:00
Wait(1000)
2024-01-27 21:57:05 +00:00
for k, v in pairs(Config.CustomCashRegisters) do
for i = 1, #v do
local job, gang = v[i].gang and nil or k, v[i].gang and k or nil
2025-02-22 13:23:43 +00:00
createBoxTarget({"CustomRegister: "..k..i, v[i].coords.xyz, 0.47, 0.34, { name="CustomRegister: "..k..i, heading = v[i].coords[4], debugPoly=debugMode, minZ=v[i].coords.z-0.1, maxZ=v[i].coords.z+0.4}}, {
{ onSelect = function() TriggerEvent(getScript()..":client:Charge", { job = job, gang = gang, img = ""}) end, icon = "fas fa-credit-card", label = locale("target", "charge"), }
2024-01-27 21:57:05 +00:00
}, 2.0)
if v[i].prop then makeProp({prop = "prop_till_03", coords = v[i].coords}, 1, false) end
end
end
end
2025-02-21 13:54:49 +00:00
onPlayerLoaded(function() spawnCustomRegisters() end, true)
2024-01-27 21:57:05 +00:00
local billPrev = "cash"
2025-02-21 13:54:49 +00:00
RegisterNetEvent(getScript()..":client:Charge", function(data, outside)
2025-02-22 13:23:43 +00:00
--if not outside and not onDuty and data.gang == nil then triggerNotify(nil, locale("error", "not_onduty") return end
2024-01-27 21:57:05 +00:00
local newinputs = {} -- Begin qb-input creation here.
local nearbyList = {}
if Config.General.List then -- If nearby player list is wanted:
--Retrieve a list of nearby players from server
2025-02-21 13:54:49 +00:00
local onlineList = triggerCallback(getScript()..":MakePlayerList")
2024-01-27 21:57:05 +00:00
--Convert list of players nearby into one qb-input understands + add distance info
2025-02-22 13:23:43 +00:00
local playerCoords = GetEntityCoords(PlayerPedId())
for _, v in ipairs(GetPlayersFromCoords(playerCoords, Config.General.PaymentRadius)) do
local ped = GetPlayerPed(v)
local dist = #(GetEntityCoords(ped) - playerCoords)
for i = 1, #onlineList do
if onlineList[i].value == GetPlayerServerId(v) then
if v ~= PlayerId() or debugMode then
nearbyList[#nearbyList+1] = {
value = onlineList[i].value,
label = onlineList[i].text .. ' (' .. math.floor(dist+0.05) .. 'm)',
text = onlineList[i].text .. ' (' .. math.floor(dist+0.05) .. 'm)'
}
end
end
end
end
2024-01-27 21:57:05 +00:00
--If list is empty(no one nearby) show error and stop
if not nearbyList[1] then
triggerNotify(nil, locale("error" ,"no_one"), "error")
return
end
newinputs[#newinputs+1] = {
type = "select",
text = locale("menu", "cus_id"),
name = "citizen",
label = locale("menu", "cus_id"),
default = 1,
options = nearbyList
}
2024-01-28 12:29:14 +00:00
else -- If Config.List is false, create input text box for ID's
newinputs[#newinputs+1] = {
type = 'text',
isRequired = true,
required = true,
name = 'citizen',
label = locale("menu", "cus_id"),
text = locale("menu", "cus_id")
}
2024-01-28 12:29:14 +00:00
end
2025-02-22 13:23:43 +00:00
2024-01-27 21:57:05 +00:00
--Grab Player Job name or Gang Name if needed
2025-02-22 13:23:43 +00:00
local getInfo = getPlayer()
--Check if image was given when opening the regsiter
local img = data.img ~= nil and (Config.System.Menu == "qb" and "<center><img src="..(data.img).." width=200px></center>") or Jobs[getInfo.job].label
2024-01-27 21:57:05 +00:00
newinputs[#newinputs+1] = {
type = 'select',
name = 'billtype',
2025-02-22 13:23:43 +00:00
text = locale("menu" ,"type"),
2024-01-27 21:57:05 +00:00
default = billPrev,
options = {
2025-02-22 13:23:43 +00:00
{ value = "cash", text = locale("menu" ,"cash"), label = locale("menu" ,"cash") },
{ value = "bank", text = locale("menu" ,"card"), label = locale("menu" ,"card") }
2024-01-27 21:57:05 +00:00
}
}
2025-02-22 13:23:43 +00:00
newinputs[#newinputs+1] = { type = 'number', isRequired = true, name = 'price', text = locale("menu" ,"amount_charge") }
2024-01-27 21:57:05 +00:00
local dialog = createInput(img, newinputs)
if dialog then
if dialog[1] then -- if ox menu, auto adjust values
if dialog[1] == "" then
TriggerEvent(getScript()..":client:Charge", data, outside)
return
end
2024-01-27 21:57:05 +00:00
dialog.citizen = dialog[1]
dialog.billtype = dialog[2]
dialog.price = dialog[3]
end
billPrev = dialog.billtype
2025-02-21 13:54:49 +00:00
TriggerServerEvent(getScript()..":server:Charge", dialog.citizen, dialog.price, dialog.billtype, data.img, outside, gang)
2024-01-27 21:57:05 +00:00
end
end)
2025-02-21 13:54:49 +00:00
RegisterNetEvent(getScript()..":client:PayPopup", function(amount, biller, billtype, img, billerjob, gang, outside)
2024-01-27 21:57:05 +00:00
local setimage = ""
2025-02-22 13:23:43 +00:00
if not img then
setimage = billerjob
else
if Config.System.Menu == "qb" then
setimage = "<center><img src="..(img and img or "").." width=200px></center>"
elseif Config.System.Menu == "ox" then
setimage = '!['..''.. ']('..(img and img or "")..')'
end
2024-01-27 21:57:05 +00:00
end
local Menu = {}
Menu[#Menu+1] = {
isMenuHeader = true,
2025-02-22 13:23:43 +00:00
header = "🧾 "..locale("menu" ,"payment"),
txt = locale("menu" ,"accept_payment")
2024-01-27 21:57:05 +00:00
}
Menu[#Menu+1] = {
isMenuHeader = true,
header = "",
2025-02-22 13:23:43 +00:00
txt = billtype:gsub("^%l", string.upper)..locale("menu" ,"payment_amount")..amount
2024-01-27 21:57:05 +00:00
}
Menu[#Menu+1] = {
icon = "fas fa-circle-check",
2025-02-22 13:23:43 +00:00
header = locale("menu" ,"yes"),
2024-01-27 21:57:05 +00:00
txt = "",
onSelect = function()
2025-02-21 13:54:49 +00:00
TriggerServerEvent(getScript()..":server:PayPopup", {
2024-01-27 21:57:05 +00:00
accept = true,
amount = amount,
biller = biller,
billtype = billtype,
outside = outside
})
end,
}
Menu[#Menu+1] = {
icon = "fas fa-circle-xmark",
2025-02-22 13:23:43 +00:00
header = locale("menu" ,"no"),
2024-01-27 21:57:05 +00:00
onSelect = function()
2025-02-21 13:54:49 +00:00
TriggerServerEvent(getScript()..":server:PayPopup", {
2024-01-27 21:57:05 +00:00
accept = false,
amount = amount,
biller = biller,
billtype = billtype,
outside = outside
})
end,
}
2024-01-27 21:57:05 +00:00
openMenu(Menu, {
header = setimage,
onExit = function()
2025-02-21 13:54:49 +00:00
TriggerServerEvent(getScript()..":server:PayPopup", {
2024-01-27 21:57:05 +00:00
accept = false,
amount = amount,
biller = biller,
billtype = billtype,
outside = outside
})
end,
})
end)