2022-02-05 15:44:29 +00:00
local QBCore = exports [ 'qb-core' ]: GetCoreObject ()
PlayerJob = {}
local onDuty = false
2022-04-24 11:06:12 +01:00
local BankPed = {}
2022-05-21 11:36:51 +01:00
RegisterNetEvent ( 'QBCore:Client:OnPlayerLoaded' , function () QBCore.Functions . GetPlayerData ( function ( PlayerData ) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang end ) end )
RegisterNetEvent ( 'QBCore:Client:OnJobUpdate' , function ( JobInfo ) PlayerJob = JobInfo onDuty = PlayerJob.onduty end )
RegisterNetEvent ( 'QBCore:Client:SetDuty' , function ( duty ) onDuty = duty end )
RegisterNetEvent ( 'QBCore:Client:OnGangUpdate' , function ( GangInfo ) PlayerGang = GangInfo end )
2022-02-14 23:07:18 +00:00
2022-02-05 15:44:29 +00:00
--Keeps track of duty on script restarts
2022-05-21 11:36:51 +01:00
AddEventHandler ( 'onResourceStart' , function ( resource ) if GetCurrentResourceName () ~= resource then return end
QBCore.Functions . GetPlayerData ( function ( PlayerData ) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang onDuty = PlayerJob.onduty end )
end )
2022-02-05 15:44:29 +00:00
2022-04-24 11:06:12 +01:00
CreateThread ( function ()
2022-02-05 15:44:29 +00:00
local jobroles = {}
2022-06-21 15:11:31 +01:00
local gangroles = {}
for k , v in pairs ( Config.Jobs ) do if v.gang then gangroles [ tostring ( k )] = 0 else jobroles [ tostring ( k )] = 0 end end
2022-04-20 13:52:32 +01:00
exports [ 'qb-target' ]: AddCircleZone ( "JimBank" , vector3 ( Config.CashInLocation . x , Config.CashInLocation . y , Config.CashInLocation . z ), 2.0 , { name = "JimBank" , debugPoly = Config.Debug , useZ = true , },
2022-06-21 15:11:31 +01:00
{ options = {
{ event = "jim-payments:Tickets:Menu" , icon = "fas fa-receipt" , label = "Cash in Job Receipts" , job = jobroles , },
{ event = "jim-payments:Tickets:Menu" , icon = "fas fa-receipt" , label = "Cash in Gang Receipts" , gang = gangroles , } },
distance = 2.0 })
2022-04-20 13:52:32 +01:00
if Config.Peds then
local i = math.random ( 1 , # Config.PedPool )
RequestModel ( Config.PedPool [ i ]) while not HasModelLoaded ( Config.PedPool [ i ]) do Wait ( 0 ) end
2022-04-24 11:06:12 +01:00
if not BankPed [ 1 ] then BankPed [ 1 ] = CreatePed ( 0 , Config.PedPool [ i ], vector3 ( Config.CashInLocation . x , Config.CashInLocation . y , Config.CashInLocation . z - 1 ), Config.CashInLocation [ 4 ], false , false ) end
2022-04-20 13:52:32 +01:00
if Config.Debug then print ( "Ped Created for Ticket Trade" ) end
end
2022-02-05 15:44:29 +00:00
end )
2022-05-05 21:34:34 +01:00
RegisterNetEvent ( 'jim-payments:client:Charge' , function ( data , outside )
if outside == nil then outside = false end
2022-06-21 15:11:31 +01:00
if not outside and not onDuty and data.gang == nil then TriggerEvent ( "QBCore:Notify" , "Not Clocked in!" , "error" ) return end -- Require to be on duty when making a payment
2022-02-17 12:43:15 +00:00
local onlineList = {}
local nearbyList = {}
2022-05-05 21:34:34 +01:00
local p = promise.new ()
QBCore.Functions . TriggerCallback ( 'jim-payments:MakePlayerList' , function ( cb ) p : resolve ( cb ) end )
onlineList = Citizen.Await ( p )
for k , v in pairs ( QBCore.Functions . GetPlayersFromCoords ( GetEntityCoords ( PlayerPedId ()), Config.PaymentRadius )) do
local dist = # ( GetEntityCoords ( GetPlayerPed ( v )) - GetEntityCoords ( PlayerPedId ()))
for i = 1 , # onlineList do
if onlineList [ i ]. value == GetPlayerServerId ( v ) then
2022-06-21 15:11:31 +01:00
if v ~= PlayerId () or Config.Debug then
2022-05-05 21:34:34 +01:00
nearbyList [ # nearbyList + 1 ] = { value = onlineList [ i ]. value , text = onlineList [ i ]. text .. ' (' .. math.floor ( dist + 0.05 ) .. 'm)' }
2022-02-14 23:07:18 +00:00
end
2022-02-17 12:43:15 +00:00
end
2022-02-05 15:44:29 +00:00
end
2022-05-05 21:34:34 +01:00
dist = nil
end
if not data.img then img = "" else img = data.img end
if nearbyList [ # nearbyList ] == nil then TriggerEvent ( "QBCore:Notify" , "No one near by to charge" , "error" ) return end
local newinputs = {}
if Config.List then newinputs [ # newinputs + 1 ] = { text = " " , name = "citizen" , type = "select" , options = nearbyList } end
if not Config.List then newinputs [ # newinputs + 1 ] = { type = 'text' , isRequired = true , name = 'citizen' , text = '# Customer ID #' } end
newinputs [ # newinputs + 1 ] = { type = 'radio' , name = 'billtype' , text = 'Payment Type' , options = { { value = "cash" , text = "Cash" }, { value = "bank" , text = "Card" } } }
newinputs [ # newinputs + 1 ] = { type = 'number' , isRequired = true , name = 'price' , text = '💵 Amount to Charge' }
2022-06-21 15:11:31 +01:00
if data.job then label = PlayerJob.label gang = false elseif data.gang then label = PlayerGang.label gang = true end
local dialog = exports [ 'qb-input' ]: ShowInput ({ header = img .. label .. " Cash Register" , submitText = "Send" , inputs = newinputs })
2022-05-05 21:34:34 +01:00
if dialog then
if not dialog.citizen or not dialog.price then return end
2022-06-21 15:11:31 +01:00
TriggerServerEvent ( 'jim-payments:server:Charge' , dialog.citizen , dialog.price , dialog.billtype , data.img , outside , gang )
2022-05-05 21:34:34 +01:00
end
2022-02-05 16:10:11 +00:00
end )
2022-02-09 12:54:06 +00:00
2022-06-21 15:11:31 +01:00
RegisterNetEvent ( 'jim-payments:Tickets:Menu' , function ( data )
2022-04-24 11:06:12 +01:00
local amount = 0
2022-04-11 18:59:47 +01:00
local p = promise.new () QBCore.Functions . TriggerCallback ( 'jim-payments:Ticket:Count' , function ( cb ) p : resolve ( cb ) end ) amount = Citizen.Await ( p )
2022-04-24 11:06:12 +01:00
if amount == 0 or amount == nil then TriggerEvent ( "QBCore:Notify" , "You don't have any tickets to trade" , "error" ) return end
2022-06-21 15:11:31 +01:00
local sellable = false
local name = "" local label = ""
for k , v in pairs ( Config.Jobs ) do
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
exports [ 'qb-menu' ]: openMenu ({
{ isMenuHeader = true , header = "🧾 " .. label .. " Receipts 🧾" , txt = "Do you want trade your receipts for payment?" },
{ isMenuHeader = true , header = "" , txt = "Amount of Tickets: " .. amount .. "<br>Total Payment: $" .. ( Config.Jobs [ name ]. PayPerTicket * amount ) },
{ icon = "fas fa-circle-check" , header = "Yes" , txt = "" , params = { event = "jim-payments:Tickets:Sell:yes" } },
2022-05-21 11:01:47 +01:00
{ icon = "fas fa-circle-xmark" , header = "No" , txt = "" , params = { event = "jim-payments:Tickets:Sell:no" } }, })
2022-02-06 15:47:07 +00:00
end
end
end )
2022-06-21 15:11:31 +01:00
RegisterNetEvent ( "jim-payments:client:PayPopup" , function ( amount , biller , billtype , img , billerjob , gang )
2022-04-24 11:06:12 +01:00
if not img then img = "" end
2022-03-11 00:30:49 +00:00
exports [ 'qb-menu' ]: openMenu ({
2022-04-12 21:09:44 +01:00
{ isMenuHeader = true , header = img .. "🧾 " .. billerjob .. " Payment 🧾" , txt = "Do you want accept the payment?" },
2022-03-11 00:30:49 +00:00
{ isMenuHeader = true , header = "" , txt = billtype : gsub ( "^%l" , string.upper ) .. " Payment: $" .. amount },
2022-06-21 15:11:31 +01:00
{ icon = "fas fa-circle-check" , header = "Yes" , txt = "" , params = { isServer = true , event = "jim-payments:server:PayPopup" , args = { accept = true , amount = amount , biller = biller , billtype = billtype , gang = gang } } },
2022-05-21 11:01:47 +01:00
{ icon = "fas fa-circle-xmark" , header = "No" , txt = "" , params = { isServer = true , event = "jim-payments:server:PayPopup" , args = { accept = false , amount = amount , biller = biller , billtype = billtype } } }, })
2022-03-11 00:30:49 +00:00
end )
2022-02-06 15:47:07 +00:00
RegisterNetEvent ( 'jim-payments:Tickets:Sell:yes' , function () TriggerServerEvent ( 'jim-payments:Tickets:Sell' ) end )
2022-04-19 21:26:43 +01:00
RegisterNetEvent ( 'jim-payments:Tickets:Sell:no' , function () exports [ 'qb-menu' ]: closeMenu () end )
2022-05-21 11:36:51 +01:00
AddEventHandler ( 'onResourceStop' , function ( resource ) if resource ~= GetCurrentResourceName () then return end
exports [ 'qb-target' ]: RemoveZone ( "JimBank" ) DeletePed ( BankPed [ 1 ])
2022-04-19 21:26:43 +01:00
end )