1
0
Fork 0
forked from Simnation/Main

Update billing_client.lua

This commit is contained in:
Nordi98 2025-08-05 11:16:01 +02:00
parent 35facf8123
commit b43fa3c75e

View file

@ -1,3 +1,4 @@
-- Initialize QBCore
local QBCore = exports['qb-core']:GetCoreObject() local QBCore = exports['qb-core']:GetCoreObject()
local isUiOpen = false local isUiOpen = false
@ -51,23 +52,32 @@ function OpenBillingMenu()
}) })
end end
-- Create player options for selection -- Show the list of nearby players first
local playerOptions = {} local playerOptions = {}
for _, player in ipairs(players) do for _, player in ipairs(players) do
table.insert(playerOptions, { table.insert(playerOptions, {
value = player.id, title = player.name,
label = player.name .. ' (ID: ' .. player.id .. ')' description = 'ID: ' .. player.id,
onSelect = function()
-- When a player is selected, show the billing form
ShowBillingForm(player, accountOptions)
end
}) })
end end
-- Create the input dialog -- Register and show the player selection menu
local input = lib.inputDialog('Create Bill', { lib.registerContext({
{ id = 'nearby_players_menu',
type = 'select', title = 'Select Player to Bill',
label = 'Select Player', options = playerOptions
options = playerOptions, })
required = true
}, lib.showContext('nearby_players_menu')
end
-- Function to show the billing form after selecting a player
function ShowBillingForm(selectedPlayer, accountOptions)
local input = lib.inputDialog('Create Bill for ' .. selectedPlayer.name, {
{ {
type = 'number', type = 'number',
label = 'Amount ($)', label = 'Amount ($)',
@ -99,16 +109,16 @@ function OpenBillingMenu()
-- Send the bill -- Send the bill
local success = lib.callback.await('billing:server:sendBill', false, { local success = lib.callback.await('billing:server:sendBill', false, {
playerId = input[1], playerId = selectedPlayer.id,
amount = input[2], amount = input[1],
reason = input[3], reason = input[2],
account = input[4] account = input[3]
}) })
if success then if success then
lib.notify({ lib.notify({
title = 'Billing System', title = 'Billing System',
description = 'Bill sent successfully', description = 'Bill sent successfully to ' .. selectedPlayer.name,
type = 'success' type = 'success'
}) })
@ -196,22 +206,25 @@ end, false)
-- Helper function to get nearby players -- Helper function to get nearby players
function GetNearbyPlayers() function GetNearbyPlayers()
local playerPed = PlayerPedId() local playerPed = PlayerPedId()
local players = QBCore.Functions.GetPlayers() local playerCoords = GetEntityCoords(playerPed)
local nearbyPlayers = {} local players = {}
for _, player in ipairs(players) do -- Get all players
local allPlayers = GetActivePlayers()
for _, player in ipairs(allPlayers) do
local targetPed = GetPlayerPed(player) local targetPed = GetPlayerPed(player)
local targetCoords = GetEntityCoords(targetPed) local targetCoords = GetEntityCoords(targetPed)
local distance = #(GetEntityCoords(playerPed) - targetCoords) local distance = #(playerCoords - targetCoords)
if distance <= 5.0 and targetPed ~= playerPed then if distance <= 5.0 and targetPed ~= playerPed then
local targetId = GetPlayerServerId(player) local targetId = GetPlayerServerId(player)
local targetName = GetPlayerName(player) local targetName = GetPlayerName(player)
table.insert(nearbyPlayers, {id = targetId, name = targetName}) table.insert(players, {id = targetId, name = targetName})
end end
end end
return nearbyPlayers return players
end end
-- Animation function -- Animation function