Merge pull request #40 from taylorrenee1/main

added ox lib compat to input - may have ended up breaking some things sorry jim :^)
This commit is contained in:
Jim Shield
2024-01-09 23:58:10 +00:00
committed by GitHub
3 changed files with 140 additions and 32 deletions

View File

@@ -1,3 +1,6 @@
local QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('QBCore:Client:UpdateObject', function() QBCore = exports['qb-core']:GetCoreObject() end)
PlayerJob = {}
PlayerGang = {}
@@ -56,11 +59,9 @@ end)
RegisterNetEvent('jim-payments:client:Charge', function(data, outside)
--Check if player is using /cashregister command
if not outside and not onDuty and data.gang == nil then triggerNotify(nil, Loc[Config.Lan].error["not_onduty"], "error") return end
local dialog
if not outside and not onDuty and data.gang == nil then triggerNotify(nil, nil, Loc[Config.Lan].error["not_onduty"], "error") return end
local newinputs = {} -- Begin qb-input creation here.
if Config.Usebzzz then
TriggerEvent('animations:client:EmoteCommandStart', {'terminal'})
end
if Config.List then -- If nearby player list is wanted:
--Retrieve a list of nearby players from server
local p = promise.new() QBCore.Functions.TriggerCallback('jim-payments:MakePlayerList', function(cb) p:resolve(cb) end)
@@ -72,42 +73,66 @@ RegisterNetEvent('jim-payments:client:Charge', function(data, outside)
for i = 1, #onlineList do
if onlineList[i].value == GetPlayerServerId(v) then
if v ~= PlayerId() or Config.Debug then
nearbyList[#nearbyList+1] = { value = onlineList[i].value, text = onlineList[i].text..' ('..math.floor(dist+0.05)..'m)' }
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
--If list is empty(no one nearby) show error and stop
if not nearbyList[1] then triggerNotify(nil, Loc[Config.Lan].error["no_one"], "error") return end
newinputs[#newinputs+1] = { text = " ", name = "citizen", type = "select", options = nearbyList }
if not nearbyList[1] then triggerNotify(nil, nil, Loc[Config.Lan].error["no_one"], "error") return end
newinputs[#newinputs+1] = { text = " ", name = "citizen", label = Loc[Config.Lan].menu["cus_id"], type = "select", options = nearbyList }
else -- If Config.List is false, create input text box for ID's
newinputs[#newinputs+1] = { type = 'text', isRequired = true, name = 'citizen', text = Loc[Config.Lan].menu["cus_id"] }
if Config.Menu == "qb" then
newinputs[#newinputs+1] = { type = 'text', isRequired = true, name = 'citizen', text = Loc[Config.Lan].menu["cus_id"] }
elseif Config.Menu == "ox" then
newinputs[#newinputs+1] = {type = 'input', required = true, name = 'citizen', label = Loc[Config.Lan].menu["cus_id"], text = Loc[Config.Lan].menu["cus_id"]}
end
end
--Check if image was given when opening the regsiter
local img = data.img or ""
if not string.find(img, "<") then img = "<center><p><img src="..img.." width=100px></p>" end
--Continue adding payment options to qb-input
if Config.Menu == "qb" then
newinputs[#newinputs+1] = { type = 'radio', name = 'billtype', text = Loc[Config.Lan].menu["type"], options = { { value = "cash", text = Loc[Config.Lan].menu["cash"] }, { value = "bank", text = Loc[Config.Lan].menu["card"] } } }
elseif Config.Menu == "ox" then
newinputs[#newinputs+1] = {type = 'select',
options = {
{ value = 'cash', label = "Cash" },
{ value = 'bank', label = "Bank" }
},
required = true,
label = "Payment Type"
}
end
if Config.Menu == "qb" then
newinputs[#newinputs+1] = { type = 'number', isRequired = true, name = 'price', text = Loc[Config.Lan].menu["amount_charge"] }
elseif Config.Menu == "ox" then
newinputs[#newinputs+1] = {type = 'number', required = true, label = Loc[Config.Lan].menu["amount_charge"], text = Loc[Config.Lan].menu["amount_charge"] }
end
--Grab Player Job name or Gang Name if needed
local label = PlayerJob.label
local gang = false
if data.gang then label = PlayerGang.label gang = true end
local dialog = exports['qb-input']:ShowInput({ header = img..label..Loc[Config.Lan].menu["cash_reg"], submitText = Loc[Config.Lan].menu["send"], inputs = newinputs})
if Config.Menu == "qb" then
dialog = exports['qb-input']:ShowInput({ header = img..label..Loc[Config.Lan].menu["cash_reg"], submitText = Loc[Config.Lan].menu["send"], inputs = newinputs})
elseif Config.Menu == "ox" then
dialog = exports.ox_lib:inputDialog(label..Loc[Config.Lan].menu["cash_reg"], newinputs)
end
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, data.img, outside, gang)
end
if Config.Usebzzz then
ExecuteCommand("e c")
end
local inputs = {
citizen = dialog.citizen or dialog[1],
price = dialog.price or dialog[3],
billtype = dialog.billtype or dialog[2],
}
if not inputs.citizen or not inputs.price then return end
TriggerServerEvent('jim-payments:server:Charge', inputs.citizen, inputs.price, inputs.billtype, data.img, outside, gang)
end
end)
RegisterNetEvent('jim-payments:client:PolCharge', function()
--Check if player is allowed to use /cashregister command
local allowed = false
for k in pairs(Config.FineJobs) do if k == PlayerJob.name then allowed = true end end
if not allowed then triggerNotify(nil, Loc[Config.Lan].error["no_job"], "error") return end
if not allowed then triggerNotify(nil, nil, Loc[Config.Lan].error["no_job"], "error") return end
local newinputs = {} -- Begin qb-input creation here.
if Config.FineJobList then -- If nearby player list is wanted:
@@ -121,34 +146,47 @@ RegisterNetEvent('jim-payments:client:PolCharge', function()
for i = 1, #onlineList do
if onlineList[i].value == GetPlayerServerId(v) then
if v ~= PlayerId() or Config.Debug then
nearbyList[#nearbyList+1] = { value = onlineList[i].value, text = onlineList[i].text..' ('..math.floor(dist+0.05)..'m)' }
nearbyList[#nearbyList+1] = { value = onlineList[i].value, text = onlineList[i].text..' ('..math.floor(dist+0.05)..'m)', label = onlineList[i].text..' ('..math.floor(dist+0.05)..'m)' }
end
end
end
end
--If list is empty(no one nearby) show error and stop
if not nearbyList[1] then triggerNotify(nil, Loc[Config.Lan].error["no_one"], "error") return end
if not nearbyList[1] then triggerNotify(nil, nil, Loc[Config.Lan].error["no_one"], "error") return end
newinputs[#newinputs+1] = { text = " ", name = "citizen", type = "select", options = nearbyList }
else -- If Config.List is false, create input text box for ID's
newinputs[#newinputs+1] = { type = 'text', isRequired = true, name = 'citizen', text = Loc[Config.Lan].menu["person_id"] }
newinputs[#newinputs+1] = { type = 'text', isRequired = true, required = true, name = 'citizen', label = Loc[Config.Lan].menu["person_id"], text = Loc[Config.Lan].menu["person_id"] }
end
--Continue adding payment options to qb-input
if Config.Menu == "qb" then
newinputs[#newinputs+1] = { type = 'number', isRequired = true, name = 'price', text = Loc[Config.Lan].menu["amount_charge"] }
elseif Config.Menu == "ox" then
newinputs[#newinputs+1] = {type = 'number', required = true, label = Loc[Config.Lan].menu["amount_charge"], text = Loc[Config.Lan].menu["amount_charge"] }
end
--Grab Player Job name or Gang Name if needed
local label = PlayerJob.label
local gang = false
local dialog = exports['qb-input']:ShowInput({ header = label..Loc[Config.Lan].menu["charge"], submitText = Loc[Config.Lan].menu["send"], inputs = newinputs})
if dialog then
if not dialog.citizen or not dialog.price then return end
TriggerServerEvent('jim-payments:server:PolCharge', dialog.citizen, dialog.price)
local dialog
if Config.Menu == "qb" then
dialog = exports['qb-input']:ShowInput({ header = label..Loc[Config.Lan].menu["charge"], submitText = Loc[Config.Lan].menu["send"], inputs = newinputs})
elseif Config.Menu == "ox" then
dialog = exports.ox_lib:inputDialog(label..Loc[Config.Lan].menu["charge"], newinputs)
end
if dialog then
local inputs = {
citizen = dialog.citizen or dialog[1],
price = dialog.price or dialog[2],
}
if not inputs.citizen or not inputs.price then return end
TriggerServerEvent('jim-payments:server:PolCharge', dialog.citizen, dialog.price)
end
end)
RegisterNetEvent('jim-payments:Tickets:Menu', function(data)
--Get ticket info
local p = promise.new() QBCore.Functions.TriggerCallback('jim-payments:Ticket:Count', function(cb) p:resolve(cb) end)
local amount = Citizen.Await(p)
if not amount then triggerNotify(nil, Loc[Config.Lan].error["no_ticket"], "error") amount = 0 return else amount = amount.amount end
if not amount then triggerNotify(nil, nil, Loc[Config.Lan].error["no_ticket"], "error") amount = 0 return else amount = amount.amount end
local sellable = false
local name = "" local label = ""
--Check/adjust for job/gang names
@@ -156,32 +194,100 @@ RegisterNetEvent('jim-payments:Tickets:Menu', function(data)
if data.gang then if v.gang and k == PlayerGang.name then name = k label = PlayerGang.label sellable = true end
else if not v.gang and k == PlayerJob.name then name = k label = PlayerJob.label sellable = true end
end
if sellable then -- if info is found then:
exports['qb-menu']:openMenu({
{ isMenuHeader = true, header = "🧾 "..label..Loc[Config.Lan].menu["receipt"], txt = Loc[Config.Lan].menu["trade_confirm"] },
{ isMenuHeader = true, header = "", txt = Loc[Config.Lan].menu["ticket_amount"]..amount..Loc[Config.Lan].menu["total_pay"]..(Config.Jobs[name].PayPerTicket * amount) },
{ icon = "fas fa-circle-check", header = Loc[Config.Lan].menu["yes"], txt = "", params = { event = "jim-payments:Tickets:Sell:yes" } },
{ icon = "fas fa-circle-xmark", header = Loc[Config.Lan].menu["no"], txt = "", params = { event = "jim-payments:Tickets:Sell:no" } },
})
if sellable then -- if info is found then:
if Config.Menu == "qb" then
exports['qb-menu']:openMenu({
{ isMenuHeader = true, header = "🧾 "..label..Loc[Config.Lan].menu["receipt"], txt = Loc[Config.Lan].menu["trade_confirm"] },
{ isMenuHeader = true, header = "", txt = Loc[Config.Lan].menu["ticket_amount"]..amount..Loc[Config.Lan].menu["total_pay"]..(Config.Jobs[name].PayPerTicket * amount) },
{ icon = "fas fa-circle-check", header = Loc[Config.Lan].menu["yes"], txt = "", params = { event = "jim-payments:Tickets:Sell:yes" } },
{ icon = "fas fa-circle-xmark", header = Loc[Config.Lan].menu["no"], txt = "", params = { event = "jim-payments:Tickets:Sell:no" } },
})
elseif Config.Menu == "ox" then
lib.registerContext({
id = 'ticketmenu',
title = "🧾 "..label..Loc[Config.Lan].menu["receipt"],
options = {
{ readOnly = true, title = "🧾 "..label..Loc[Config.Lan].menu["receipt"], description = Loc[Config.Lan].menu["trade_confirm"] },
{ readOnly = true, title = Loc[Config.Lan].menu["ticket_amount"]..amount..Loc[Config.Lan].menu["total_pay"]..(Config.Jobs[name].PayPerTicket * amount), description = "", txt = Loc[Config.Lan].menu["ticket_amount"]..amount..Loc[Config.Lan].menu["total_pay"]..(Config.Jobs[name].PayPerTicket * amount) },
{ icon = "fas fa-circle-check", title = Loc[Config.Lan].menu["yes"], description = "", event = "jim-payments:Tickets:Sell:yes" },
{ icon = "fas fa-circle-xmark", title = Loc[Config.Lan].menu["no"], description = "", event = "jim-payments:Tickets:Sell:no" },
}
})
lib.showContext('ticketmenu')
end
end
end
end)
RegisterNetEvent("jim-payments:client:PayPopup", function(amount, biller, billtype, img, billerjob, gang, outside)
local img = img or ""
if Config.Menu == "qb" then
exports['qb-menu']:openMenu({
{ isMenuHeader = true, header = img.."🧾 "..billerjob..Loc[Config.Lan].menu["payment"], txt = Loc[Config.Lan].menu["accept_payment"] },
{ isMenuHeader = true, header = "", txt = billtype:gsub("^%l", string.upper)..Loc[Config.Lan].menu["payment_amount"]..amount },
{ icon = "fas fa-circle-check", header = Loc[Config.Lan].menu["yes"], txt = "", params = { isServer = true, event = "jim-payments:server:PayPopup", args = { accept = true, amount = amount, biller = biller, billtype = billtype, gang = gang, outside = outside } } },
{ icon = "fas fa-circle-xmark", header = Loc[Config.Lan].menu["no"], txt = "", params = { isServer = true, event = "jim-payments:server:PayPopup", args = { accept = false, amount = amount, biller = biller, billtype = billtype, outside = outside } } }, })
else
lib.registerContext({
id = 'paypopup',
title = "🧾 "..billerjob..Loc[Config.Lan].menu["payment"],
options = {
{
title = billtype:gsub("^%l", string.upper)..Loc[Config.Lan].menu["payment_amount"]..amount,
icon = 'fas fa-money',
readOnly = true,
},
{
title = Loc[Config.Lan].menu["yes"],
icon = "fas fa-circle-check",
serverEvent = "jim-payments:server:PayPopup",
args = {
accept = true,
amount = amount,
biller = biller,
billtype = billtype,
gang = gang,
outside = outside
}
},
{
title = Loc[Config.Lan].menu["no"],
icon = "fas fa-circle-xmark",
serverEvent = "jim-payments:server:PayPopup",
args = {
accept = false,
amount = amount,
biller = biller,
billtype = billtype,
outside = outside
}
}
}
})
lib.showContext('paypopup')
end
end)
RegisterNetEvent("jim-payments:client:PolPopup", function(amount, biller, billerjob)
if Config.Menu == "qb" then
exports['qb-menu']:openMenu({
{ isMenuHeader = true, header = "🧾 "..billerjob..Loc[Config.Lan].menu["payment"], txt = Loc[Config.Lan].menu["accept_charge"] },
{ isMenuHeader = true, header = "", txt = Loc[Config.Lan].menu["bank_charge"]..amount },
{ icon = "fas fa-circle-check", header = Loc[Config.Lan].menu["yes"], txt = "", params = { isServer = true, event = "jim-payments:server:PolPopup", args = { accept = true, amount = amount, biller = biller } } },
{ icon = "fas fa-circle-xmark", header = Loc[Config.Lan].menu["no"], txt = "", params = { isServer = true, event = "jim-payments:server:PolPopup", args = { accept = false, amount = amount, biller = biller } } }, })
else
lib.registerContext({
id = 'polpopup',
title = "🧾 "..billerjob..Loc[Config.Lan].menu["payment"],
options = {
{readOnly = true, title = "🧾 "..billerjob..Loc[Config.Lan].menu["payment"], description = Loc[Config.Lan].menu["accept_charge"] },
{ readOnly = true, title = "", description = Loc[Config.Lan].menu["bank_charge"]..amount },
{ icon = "fas fa-circle-check", title = Loc[Config.Lan].menu["yes"], description = "", serverEvent = "jim-payments:server:PolPopup", args = { accept = true, amount = amount, biller = biller } },
{ icon = "fas fa-circle-xmark", title = Loc[Config.Lan].menu["no"], description = "", serverEvent = "jim-payments:server:PolPopup", args = { accept = false, amount = amount, biller = biller } },
}
})
lib.showContext('polpopup')
end
end)
RegisterNetEvent('jim-payments:Tickets:Sell:yes', function() TriggerServerEvent('jim-payments:Tickets:Sell') end)

View File

@@ -8,6 +8,7 @@ Config = {
Lan = "en",
Debug = false,
Notify = "qb", -- "qb" | "okok" | "t" | "infinity" | "rr"
Menu = "ox"
---------------------------------
-- Default Job Payment Systems --

View File

@@ -9,3 +9,4 @@ lua54 'yes'
shared_scripts { 'config.lua', 'shared/*.lua', 'locales/*.lua' }
client_scripts { 'client/*.lua', }
server_scripts { '@oxmysql/lib/MySQL.lua', 'server/*.lua' }
shared_scripts { '@ox_lib/init.lua','config.lua', 'shared/*.lua', 'locales/*.lua' }