From 2b92f749b5471fad20c6a9071826494656bc567d Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Mon, 12 May 2025 10:49:00 +0100 Subject: [PATCH] Refactor a couple files for readability --- client/charge.lua | 38 ++++++++++++++++++------ client/polcharge.lua | 59 ++++++++++++++++++++++++++++++-------- server/polchargeserver.lua | 4 +-- 3 files changed, 78 insertions(+), 23 deletions(-) diff --git a/client/charge.lua b/client/charge.lua index 5f31400..4635320 100644 --- a/client/charge.lua +++ b/client/charge.lua @@ -43,9 +43,34 @@ RegisterNetEvent(getScript()..":client:Charge", function(data, outside) end end --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 + 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 + } 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" ,"person_id"), text = locale("menu" ,"person_id") } + newinputs[#newinputs+1] = { + type = 'text', + isRequired = true, + required = true, + name = 'citizen', + label = locale("menu" ,"person_id"), + text = locale("menu" ,"person_id") + } + newinputs[#newinputs+1] = { + type = 'text', + isRequired = true, + name = 'citizen', + text = locale("menu" ,"cus_id") + } end --Grab Player Job name or Gang Name if needed @@ -53,11 +78,6 @@ RegisterNetEvent(getScript()..":client:Charge", function(data, outside) --Check if image was given when opening the regsiter local img = data.img ~= nil and (Config.System.Menu == "qb" and "
") or Jobs[getInfo.job].label - if Config.General.List then - newinputs[#newinputs+1] = { type = "select", text = locale("menu" ,"cus_id"), name = "citizen", label = locale("menu" ,"cus_id"), default = 1, options = nearbyList } - else - newinputs[#newinputs+1] = { type = 'text', isRequired = true, name = 'citizen', text = locale("menu" ,"cus_id") } - end newinputs[#newinputs+1] = { type = 'select', name = 'billtype', @@ -73,7 +93,7 @@ RegisterNetEvent(getScript()..":client:Charge", function(data, outside) local dialog = createInput(img, newinputs) if dialog then - if dialog[1] then + if dialog[1] then -- if ox menu, auto adjust values dialog.citizen = dialog[1] dialog.billtype = dialog[2] dialog.price = dialog[3] @@ -134,7 +154,7 @@ RegisterNetEvent(getScript()..":client:PayPopup", function(amount, biller, billt }) end, } - debugPrint(setimage) + openMenu(Menu, { header = setimage, onExit = function() diff --git a/client/polcharge.lua b/client/polcharge.lua index 5075f78..854d08d 100644 --- a/client/polcharge.lua +++ b/client/polcharge.lua @@ -2,38 +2,69 @@ RegisterNetEvent(getScript()..":client:PolCharge", function() local Playerinfo = getPlayer() --Check if player is allowed to use /cashregister command local allowed = false - for k in pairs(Config.PolCharge.FineJobs) do if k == Playerinfo.job then allowed = true end end - if not allowed then triggerNotify(nil, locale("error", "no_job"), "error") return end + for k in pairs(Config.PolCharge.FineJobs) do + if k == Playerinfo.job then + allowed = true + break + end + end + if not allowed then + triggerNotify(nil, locale("error", "no_job"), "error") + return + end local newinputs = {} -- Begin qb-input creation here. local nearbyList = {} if Config.PolCharge.FineJobList then -- If nearby player list is wanted: - --Retrieve a list of nearby players from server + -- Retrieve a list of nearby players from server local onlineList = triggerCallback(getScript()..":MakePlayerList") - --Convert list of players nearby into one qb-input understands + add distance info + -- Convert list of players nearby into one an input script understands + add distance info for _, v in pairs(Core.Functions.GetPlayersFromCoords(GetEntityCoords(PlayerPedId()), Config.General.PaymentRadius)) do local dist = #(GetEntityCoords(GetPlayerPed(v)) - GetEntityCoords(PlayerPedId())) 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)' } + 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, locale("error" ,"no_one"), "error") return end - end + if not nearbyList[1] then + triggerNotify(nil, locale("error" ,"no_one"), "error") + return + end - if Config.PolCharge.FineJobList then - newinputs[#newinputs+1] = { type = "select", text = locale("menu" ,"cus_id"), name = "citizen", label = locale("menu" ,"cus_id"), default = 1, options = nearbyList } + newinputs[#newinputs+1] = { + type = "select", + text = locale("menu" ,"cus_id"), + name = "citizen", + label = locale("menu" ,"cus_id"), + default = 1, + options = nearbyList + } else - newinputs[#newinputs+1] = { type = 'text', isRequired = true, name = 'citizen', text = locale("menu" ,"cus_id") } + newinputs[#newinputs+1] = { + type = 'text', + isRequired = true, + name = 'citizen', + text = locale("menu" ,"cus_id") + } end - newinputs[#newinputs+1] = { type = 'number', isRequired = true, name = 'price', text = locale("menu" ,"amount_charge") } + newinputs[#newinputs+1] = { + type = 'number', + isRequired = true, + name = 'price', + text = locale("menu" ,"amount_charge") + } local dialog = createInput(Jobs[Playerinfo.job].label, newinputs) if dialog then + jsonPrint(dialog) if dialog[1] then dialog.citizen = dialog[1] dialog.price = dialog[2] @@ -44,7 +75,11 @@ end) RegisterNetEvent(getScript()..":client:PolPopup", function(amount, biller, billerjob) local Menu = {} - Menu[#Menu+1] = { isMenuHeader = true, header = "", txt = locale("menu" ,"bank_charge")..amount } + Menu[#Menu+1] = { + isMenuHeader = true, + header = "", + txt = locale("menu" ,"bank_charge")..amount + } Menu[#Menu+1] = { icon = "fas fa-circle-check", header = locale("menu" ,"yes"), diff --git a/server/polchargeserver.lua b/server/polchargeserver.lua index e62aeb8..7ecacf5 100644 --- a/server/polchargeserver.lua +++ b/server/polchargeserver.lua @@ -16,10 +16,10 @@ RegisterServerEvent(getScript()..":server:PolCharge", function(citizen, price) commPercent = Config.PolCharge.FineJobs[biller.job].Commission else commPercent = 0.25 - print("Can't find job in 'FineJobs', defaulting to 0.25 (25% commission)") + print("^3Warning^7: ^2Can't find player's job in ^7'Config.Polcharge.FineJobs', ^2defaulting to 0.25 (25% commission)^7") end local commission = math.floor(price * commPercent) - + print(commission) if price > 0 then if not Config.PolCharge.FineJobConfirmation then polCharge({