1
0
Fork 0
forked from Simnation/Main
Main/resources/[inventory]/nordi_vending/client.lua

763 lines
26 KiB
Lua
Raw Normal View History

2025-07-29 07:30:32 +02:00
local QBCore = exports['qb-core']:GetCoreObject()
2025-07-29 22:35:35 +02:00
local nearbyMachine = nil
2025-07-29 23:02:29 +02:00
local machineData = {}
2025-07-29 22:47:43 +02:00
local isInteracting = false
2025-07-29 07:30:32 +02:00
2025-07-29 22:35:35 +02:00
-- Function to draw 3D text in the world
function DrawText3D(x, y, z, text)
2025-07-29 23:02:29 +02:00
-- Calculate distance to reduce computation when far away
local playerCoords = GetEntityCoords(PlayerPedId())
local dist = #(vector3(x, y, z) - playerCoords)
if dist > 5.0 then return end
-- Set text properties
2025-07-29 22:47:43 +02:00
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
2025-07-29 23:02:29 +02:00
SetTextOutline()
2025-07-29 22:47:43 +02:00
SetTextEntry("STRING")
SetTextCentre(1)
AddTextComponentString(text)
SetDrawOrigin(x, y, z, 0)
DrawText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0+0.0125, 0.017+ factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
2025-07-29 22:35:35 +02:00
end
2025-07-29 09:48:16 +02:00
2025-07-29 23:02:29 +02:00
-- Cache machine data to avoid constant callbacks
function GetMachineData(entity)
local entityId = NetworkGetNetworkIdFromEntity(entity)
2025-07-29 10:53:08 +02:00
2025-07-29 23:02:29 +02:00
if not machineData[entityId] then
local coords = GetEntityCoords(entity)
local isRegistered = false
local canManage = false
-- Check if machine is registered
QBCore.Functions.TriggerCallback('vending:server:machineExists', function(exists)
isRegistered = exists
-- Only check management if registered
if isRegistered then
QBCore.Functions.TriggerCallback('vending:server:canManage', function(result)
canManage = result
-- Store data in cache
machineData[entityId] = {
isRegistered = isRegistered,
canManage = canManage,
lastCheck = GetGameTimer()
}
end, coords)
else
-- Store data in cache
machineData[entityId] = {
isRegistered = false,
canManage = false,
lastCheck = GetGameTimer()
}
end
end, coords)
-- Wait for callbacks to complete
local timeout = 0
while not machineData[entityId] and timeout < 50 do
Wait(10)
timeout = timeout + 1
end
2025-07-29 10:53:08 +02:00
end
2025-07-29 23:02:29 +02:00
-- Return cached data or default
return machineData[entityId] or {isRegistered = false, canManage = false}
2025-07-29 10:23:04 +02:00
end
2025-07-29 23:02:29 +02:00
-- Clear cache periodically
CreateThread(function()
while true do
Wait(60000) -- Clear cache every minute
local currentTime = GetGameTimer()
for entityId, data in pairs(machineData) do
if currentTime - data.lastCheck > 60000 then
machineData[entityId] = nil
end
end
2025-07-29 10:53:08 +02:00
end
2025-07-29 23:02:29 +02:00
end)
2025-07-29 08:25:12 +02:00
2025-07-29 22:35:35 +02:00
-- Main thread to detect nearby vending machines
CreateThread(function()
while true do
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local wait = 1000
2025-07-29 22:47:43 +02:00
local foundMachine = false
2025-07-29 22:35:35 +02:00
-- Check for nearby vending machines
for _, propName in ipairs(Config.VendingProps) do
local hash = GetHashKey(propName)
local objects = GetGamePool('CObject')
for _, obj in ipairs(objects) do
if GetEntityModel(obj) == hash then
local objCoords = GetEntityCoords(obj)
local dist = #(playerCoords - objCoords)
if dist < 2.0 then
wait = 0
2025-07-29 22:47:43 +02:00
foundMachine = true
2025-07-29 22:35:35 +02:00
nearbyMachine = obj
2025-07-29 23:02:29 +02:00
-- Get machine data from cache
local data = GetMachineData(obj)
-- Display appropriate text based on machine status
local z = objCoords.z + 1.0
if data.isRegistered then
if data.canManage then
DrawText3D(objCoords.x, objCoords.y, z, "[E] Kaufen | [G] Verwalten")
2025-07-29 22:47:43 +02:00
2025-07-29 23:02:29 +02:00
-- Handle key presses for management
if IsControlJustPressed(0, 38) and not isInteracting then -- E key
isInteracting = true
TriggerEvent('vending:client:openBuyMenu', {entity = obj})
Wait(500) -- Prevent multiple triggers
isInteracting = false
elseif IsControlJustPressed(0, 47) and not isInteracting then -- G key
isInteracting = true
TriggerEvent('vending:client:openOwnerMenu', {entity = obj})
Wait(500) -- Prevent multiple triggers
isInteracting = false
2025-07-29 22:35:35 +02:00
end
2025-07-29 22:47:43 +02:00
else
2025-07-29 23:02:29 +02:00
DrawText3D(objCoords.x, objCoords.y, z, "[E] Kaufen | [G] Aufbrechen")
2025-07-29 22:47:43 +02:00
2025-07-29 23:02:29 +02:00
-- Handle key presses for buying/robbery
if IsControlJustPressed(0, 38) and not isInteracting then -- E key
2025-07-29 22:47:43 +02:00
isInteracting = true
2025-07-29 23:02:29 +02:00
TriggerEvent('vending:client:openBuyMenu', {entity = obj})
Wait(500) -- Prevent multiple triggers
isInteracting = false
elseif IsControlJustPressed(0, 47) and not isInteracting then -- G key
isInteracting = true
TriggerEvent('vending:client:startRobbery', {entity = obj})
2025-07-29 22:47:43 +02:00
Wait(500) -- Prevent multiple triggers
isInteracting = false
end
end
2025-07-29 23:02:29 +02:00
else
DrawText3D(objCoords.x, objCoords.y, z, "[E] Automaten kaufen ($" .. Config.VendingMachinePrice .. ")")
-- Handle key press for buying machine
if IsControlJustPressed(0, 38) and not isInteracting then -- E key
isInteracting = true
TriggerEvent('vending:client:buyMachine', {entity = obj})
Wait(500) -- Prevent multiple triggers
isInteracting = false
end
2025-07-29 22:35:35 +02:00
end
break
end
end
end
2025-07-29 22:47:43 +02:00
if foundMachine then break end
end
2025-07-29 22:35:35 +02:00
Wait(wait)
end
end)
2025-07-29 23:02:29 +02:00
-- Event to refresh machine data when a new machine is registered
RegisterNetEvent('vending:client:refreshTargets', function()
-- Clear cached data
machineData = {}
end)
-- Keep all the existing event handlers and functions below this point
-- They don't need to be modified since they work with ox_lib
2025-07-29 10:53:08 +02:00
-- Buy vending machine
RegisterNetEvent('vending:client:buyMachine', function(data)
local entity = data.entity
local coords = GetEntityCoords(entity)
2025-07-29 07:30:32 +02:00
local model = GetEntityModel(entity)
local prop = nil
-- Find prop name
for i = 1, #Config.VendingProps do
if GetHashKey(Config.VendingProps[i]) == model then
prop = Config.VendingProps[i]
break
end
end
2025-07-29 10:53:08 +02:00
if not prop then return end
2025-07-29 07:30:32 +02:00
2025-07-29 22:55:55 +02:00
lib.registerContext({
id = 'vending_buy_confirm',
title = 'Verkaufsautomat kaufen',
options = {
{
title = 'Bestätigen',
description = 'Automaten für $' .. Config.VendingMachinePrice .. ' kaufen',
icon = 'fas fa-check',
onSelect = function()
TriggerServerEvent('vending:server:registerMachine', coords, prop)
end
},
{
title = 'Abbrechen',
description = 'Kauf abbrechen',
icon = 'fas fa-times'
}
}
})
2025-07-29 22:47:43 +02:00
2025-07-29 22:55:55 +02:00
lib.showContext('vending_buy_confirm')
2025-07-29 10:53:08 +02:00
end)
2025-07-29 07:30:32 +02:00
2025-07-29 10:53:08 +02:00
-- Open buy menu with quantity selection
RegisterNetEvent('vending:client:openBuyMenu', function(data)
local entity = data.entity
local coords = GetEntityCoords(entity)
2025-07-29 07:30:32 +02:00
QBCore.Functions.TriggerCallback('vending:server:getStashItems', function(items)
if #items == 0 then
QBCore.Functions.Notify('Dieser Automat ist leer!', 'error')
return
end
local options = {}
for i = 1, #items do
local item = items[i]
if item.amount > 0 then
2025-07-29 07:51:42 +02:00
local itemLabel = QBCore.Shared.Items[item.name] and QBCore.Shared.Items[item.name].label or item.name
2025-07-29 07:30:32 +02:00
table.insert(options, {
2025-07-29 22:55:55 +02:00
title = itemLabel,
description = 'Preis: $' .. item.price .. ' | Verfügbar: ' .. item.amount,
icon = 'fas fa-shopping-cart',
onSelect = function()
openQuantityDialog(coords, item.name, item.price, item.amount, itemLabel)
end
2025-07-29 07:30:32 +02:00
})
end
end
2025-07-29 10:53:08 +02:00
if #options == 0 then
2025-07-29 08:25:12 +02:00
QBCore.Functions.Notify('Keine Artikel verfügbar!', 'error')
return
end
2025-07-29 22:55:55 +02:00
lib.registerContext({
id = 'vending_buy_menu',
title = 'Verkaufsautomat',
options = options
})
2025-07-29 07:30:32 +02:00
2025-07-29 22:55:55 +02:00
lib.showContext('vending_buy_menu')
2025-07-29 10:53:08 +02:00
end, coords)
end)
2025-07-29 22:55:55 +02:00
-- Open quantity dialog for buying items
function openQuantityDialog(coords, itemName, price, maxAmount, itemLabel)
local input = lib.inputDialog('Menge auswählen', {
{
type = 'number',
label = itemLabel .. ' - $' .. price .. ' pro Stück',
description = 'Wie viele möchtest du kaufen? (Max: ' .. maxAmount .. ')',
required = true,
min = 1,
max = maxAmount,
default = 1
}
})
if input and input[1] then
local amount = tonumber(input[1])
if amount > 0 and amount <= maxAmount then
TriggerServerEvent('vending:server:buyItem', coords, itemName, amount)
else
QBCore.Functions.Notify('Ungültige Menge!', 'error')
end
end
end
2025-07-29 10:53:08 +02:00
-- Open owner menu
RegisterNetEvent('vending:client:openOwnerMenu', function(data)
local entity = data.entity
local coords = GetEntityCoords(entity)
2025-07-29 10:23:04 +02:00
QBCore.Functions.TriggerCallback('vending:server:getMachineByCoords', function(machine)
2025-07-29 08:25:12 +02:00
if not machine then
QBCore.Functions.Notify('Automat nicht gefunden!', 'error')
return
end
2025-07-29 09:02:52 +02:00
local options = {
2025-07-29 22:55:55 +02:00
{
title = 'Inventar verwalten',
description = 'Items hinzufügen/entfernen',
icon = 'fas fa-box',
onSelect = function()
2025-07-29 22:47:43 +02:00
TriggerServerEvent('vending:server:openStash', coords)
2025-07-29 22:55:55 +02:00
end
},
{
title = 'Preise festlegen',
description = 'Verkaufspreise für Items setzen',
icon = 'fas fa-tags',
onSelect = function()
2025-07-29 22:47:43 +02:00
openPriceMenu(coords)
2025-07-29 22:55:55 +02:00
end
},
{
title = 'Geld abheben',
description = 'Verfügbar: $' .. machine.money,
icon = 'fas fa-money-bill',
onSelect = function()
2025-07-29 22:47:43 +02:00
openWithdrawMenu(coords, machine.money)
2025-07-29 22:55:55 +02:00
end
},
{
title = 'Statistiken',
description = 'Verkaufsstatistiken anzeigen',
icon = 'fas fa-chart-bar',
onSelect = function()
2025-07-29 22:47:43 +02:00
openStatsMenu(machine)
2025-07-29 22:55:55 +02:00
end
}
}
-- Add manager options only for owner
if machine.isOwner then
table.insert(options, {
title = 'Verwalter',
description = 'Verwalter hinzufügen/entfernen',
icon = 'fas fa-users-cog',
onSelect = function()
2025-07-29 22:47:43 +02:00
openManagersMenu(coords)
2025-07-29 22:55:55 +02:00
end
})
-- Add sell option only for owner
table.insert(options, {
title = 'Automaten verkaufen',
description = 'Verkaufe den Automaten für ' .. math.floor(Config.VendingMachinePrice * Config.SellBackPercentage / 100) .. '$',
icon = 'fas fa-dollar-sign',
onSelect = function()
2025-07-29 10:53:08 +02:00
sellVendingMachine(coords, machine.id)
2025-07-29 09:20:46 +02:00
end
2025-07-29 22:55:55 +02:00
})
2025-07-29 09:02:52 +02:00
end
2025-07-29 22:55:55 +02:00
lib.registerContext({
id = 'vending_owner_menu',
title = 'Verkaufsautomat Verwaltung',
options = options
})
lib.showContext('vending_owner_menu')
2025-07-29 10:53:08 +02:00
end, coords)
end)
2025-07-29 08:25:12 +02:00
2025-07-29 22:35:35 +02:00
-- Function to sell the vending machine
2025-07-29 10:53:08 +02:00
function sellVendingMachine(coords, machineId)
2025-07-29 22:55:55 +02:00
local input = lib.inputDialog('Automaten verkaufen', {
{
type = 'checkbox',
label = 'Bestätigen',
description = 'Du erhältst ' .. math.floor(Config.VendingMachinePrice * Config.SellBackPercentage / 100) .. '$ zurück. Diese Aktion kann nicht rückgängig gemacht werden!',
required = true
}
})
2025-07-29 22:47:43 +02:00
2025-07-29 22:55:55 +02:00
if input and input[1] then
TriggerServerEvent('vending:server:sellMachine', coords, machineId)
2025-07-29 09:20:46 +02:00
end
end
2025-07-29 08:25:12 +02:00
-- Open price menu
2025-07-29 10:53:08 +02:00
function openPriceMenu(coords)
2025-07-29 08:25:12 +02:00
QBCore.Functions.TriggerCallback('vending:server:getStashItems', function(items)
if #items == 0 then
QBCore.Functions.Notify('Keine Items im Automaten!', 'error')
return
end
local options = {}
for i = 1, #items do
local item = items[i]
local itemLabel = QBCore.Shared.Items[item.name] and QBCore.Shared.Items[item.name].label or item.name
table.insert(options, {
2025-07-29 22:55:55 +02:00
title = itemLabel,
description = 'Aktueller Preis: $' .. item.price,
icon = 'fas fa-tag',
onSelect = function()
setPriceForItem(coords, item.name, itemLabel)
end
2025-07-29 08:25:12 +02:00
})
end
2025-07-29 22:55:55 +02:00
lib.registerContext({
id = 'vending_price_menu',
title = 'Preise festlegen',
menu = 'vending_owner_menu',
options = options
})
2025-07-29 08:25:12 +02:00
2025-07-29 22:55:55 +02:00
lib.showContext('vending_price_menu')
2025-07-29 10:53:08 +02:00
end, coords)
2025-07-29 08:25:12 +02:00
end
-- Set price for specific item
2025-07-29 10:53:08 +02:00
function setPriceForItem(coords, itemName, itemLabel)
2025-07-29 22:55:55 +02:00
local input = lib.inputDialog('Preis festlegen', {
{
type = 'number',
label = 'Preis für ' .. itemLabel,
description = 'Neuen Verkaufspreis eingeben',
required = true,
min = 1,
max = 10000
}
})
2025-07-29 22:47:43 +02:00
2025-07-29 22:55:55 +02:00
if input and input[1] then
TriggerServerEvent('vending:server:setItemPrice', coords, itemName, tonumber(input[1]))
2025-07-29 08:25:12 +02:00
end
end
-- Open withdraw menu
2025-07-29 10:53:08 +02:00
function openWithdrawMenu(coords, availableMoney)
2025-07-29 08:25:12 +02:00
if availableMoney <= 0 then
QBCore.Functions.Notify('Kein Geld im Automaten!', 'error')
return
end
2025-07-29 22:55:55 +02:00
local input = lib.inputDialog('Geld abheben', {
{
type = 'number',
label = 'Betrag (Verfügbar: $' .. availableMoney .. ')',
description = 'Wie viel möchtest du abheben?',
required = true,
min = 1,
max = availableMoney
}
})
2025-07-29 08:25:12 +02:00
2025-07-29 22:55:55 +02:00
if input and input[1] then
TriggerServerEvent('vending:server:withdrawMoney', coords, tonumber(input[1]))
2025-07-29 08:25:12 +02:00
end
end
-- Open stats menu
function openStatsMenu(machine)
2025-07-29 22:55:55 +02:00
lib.registerContext({
id = 'vending_stats_menu',
title = 'Verkaufsstatistiken',
menu = 'vending_owner_menu',
options = {
{
title = 'Gesamteinnahmen',
description = '$' .. machine.money,
icon = 'fas fa-dollar-sign'
},
{
title = 'Automat ID',
description = '#' .. machine.id,
icon = 'fas fa-hashtag'
},
{
title = 'Standort',
description = 'X: ' .. math.floor(machine.coords.x) .. ' Y: ' .. math.floor(machine.coords.y),
icon = 'fas fa-map-marker-alt'
}
}
})
2025-07-29 22:47:43 +02:00
2025-07-29 22:55:55 +02:00
lib.showContext('vending_stats_menu')
2025-07-29 08:25:12 +02:00
end
2025-07-29 09:02:52 +02:00
-- Open managers menu
2025-07-29 10:53:08 +02:00
function openManagersMenu(coords)
-- Get current managers
2025-07-29 09:02:52 +02:00
QBCore.Functions.TriggerCallback('vending:server:getManagers', function(managers)
local options = {
2025-07-29 22:55:55 +02:00
{
title = 'Verwalter hinzufügen',
description = 'Neuen Verwalter hinzufügen',
icon = 'fas fa-user-plus',
onSelect = function()
openAddManagerMenu(coords)
end
}
2025-07-29 09:02:52 +02:00
}
2025-07-29 22:55:55 +02:00
-- Add existing managers with remove option
2025-07-29 09:02:52 +02:00
if #managers > 0 then
for i = 1, #managers do
local manager = managers[i]
table.insert(options, {
2025-07-29 22:55:55 +02:00
title = manager.name,
description = manager.online and 'Online' or 'Offline',
icon = manager.online and 'fas fa-circle text-success' or 'fas fa-circle text-danger',
onSelect = function()
lib.registerContext({
id = 'manager_options',
title = 'Verwalter: ' .. manager.name,
menu = 'managers_menu',
options = {
{
title = 'Entfernen',
description = 'Verwalter entfernen',
icon = 'fas fa-user-minus',
onSelect = function()
TriggerServerEvent('vending:server:removeManager', coords, manager.citizenid)
Wait(500)
openManagersMenu(coords) -- Refresh the menu
end
}
}
})
lib.showContext('manager_options')
end
2025-07-29 09:02:52 +02:00
})
end
else
2025-07-29 22:55:55 +02:00
table.insert(options, {
title = 'Keine Verwalter',
description = 'Es sind keine Verwalter vorhanden',
icon = 'fas fa-info-circle',
disabled = true
})
2025-07-29 09:02:52 +02:00
end
2025-07-29 22:55:55 +02:00
lib.registerContext({
id = 'managers_menu',
title = 'Verwalter verwalten',
menu = 'vending_owner_menu',
options = options
})
2025-07-29 09:02:52 +02:00
2025-07-29 22:55:55 +02:00
lib.showContext('managers_menu')
2025-07-29 10:53:08 +02:00
end, coords)
2025-07-29 09:02:52 +02:00
end
-- Open add manager menu
2025-07-29 10:53:08 +02:00
function openAddManagerMenu(coords)
2025-07-29 09:02:52 +02:00
QBCore.Functions.TriggerCallback('vending:server:getOnlinePlayers', function(players)
if #players == 0 then
QBCore.Functions.Notify('Keine Spieler online!', 'error')
return
end
2025-07-29 22:55:55 +02:00
local options = {}
2025-07-29 09:02:52 +02:00
2025-07-29 22:55:55 +02:00
for i = 1, #players do
local player = players[i]
table.insert(options, {
title = player.name,
description = 'ID: ' .. player.id,
icon = 'fas fa-user',
onSelect = function()
TriggerServerEvent('vending:server:addManager', coords, player.id)
Wait(500)
openManagersMenu(coords) -- Refresh the menu
2025-07-29 09:02:52 +02:00
end
2025-07-29 22:55:55 +02:00
})
2025-07-29 22:47:43 +02:00
end
2025-07-29 22:55:55 +02:00
lib.registerContext({
id = 'add_manager_menu',
title = 'Verwalter hinzufügen',
menu = 'managers_menu',
options = options
})
lib.showContext('add_manager_menu')
2025-07-29 09:02:52 +02:00
end)
end
2025-07-29 10:53:08 +02:00
-- Robbery menu
RegisterNetEvent('vending:client:startRobbery', function(data)
local entity = data.entity
local coords = GetEntityCoords(entity)
2025-07-29 22:55:55 +02:00
lib.registerContext({
id = 'vending_robbery_confirm',
title = 'Verkaufsautomat aufbrechen',
options = {
{
title = 'Aufbrechen',
description = 'Versuche den Automaten aufzubrechen',
icon = 'fas fa-mask',
onSelect = function()
TriggerServerEvent('vending:server:startRobbery', coords)
end
},
{
title = 'Abbrechen',
description = 'Aufbruch abbrechen',
icon = 'fas fa-times'
}
}
})
2025-07-29 10:53:08 +02:00
2025-07-29 22:55:55 +02:00
lib.showContext('vending_robbery_confirm')
2025-07-29 10:53:08 +02:00
end)
2025-07-29 08:25:12 +02:00
-- Start robbery animation and progress
2025-07-29 10:53:08 +02:00
RegisterNetEvent('vending:client:startRobbery', function(coords)
2025-07-29 08:25:12 +02:00
local playerPed = PlayerPedId()
local robberyTime = 10000 -- 10 seconds
-- Animation
RequestAnimDict('anim@heists@fleeca_bank@drilling')
while not HasAnimDictLoaded('anim@heists@fleeca_bank@drilling') do
Wait(100)
end
TaskPlayAnim(playerPed, 'anim@heists@fleeca_bank@drilling', 'drill_straight_idle', 8.0, -8.0, -1, 1, 0, false, false, false)
2025-07-29 22:55:55 +02:00
-- Progress bar
if lib.progressBar then
local success = lib.progressBar({
duration = robberyTime,
label = 'Automat aufbrechen...',
useWhileDead = false,
canCancel = true,
disable = {
car = true,
move = true,
combat = true
}
})
ClearPedTasks(playerPed)
TriggerServerEvent('vending:server:completeRobbery', coords, success)
else
-- Fallback without progress bar
Wait(robberyTime)
ClearPedTasks(playerPed)
TriggerServerEvent('vending:server:completeRobbery', coords, true)
2025-07-29 08:25:12 +02:00
end
end)
-- Police alert
RegisterNetEvent('vending:client:policeAlert', function(coords, streetName)
2025-07-29 22:55:55 +02:00
local alert = {
title = "Verkaufsautomat Aufbruch",
coords = coords,
description = "Ein Verkaufsautomat wird aufgebrochen in " .. streetName
}
2025-07-29 08:25:12 +02:00
-- Add blip
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
SetBlipSprite(blip, 161)
SetBlipColour(blip, 1)
SetBlipScale(blip, 1.0)
SetBlipAsShortRange(blip, false)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Verkaufsautomat Aufbruch")
EndTextCommandSetBlipName(blip)
-- Remove blip after 5 minutes
SetTimeout(300000, function()
RemoveBlip(blip)
end)
QBCore.Functions.Notify('Verkaufsautomat Aufbruch gemeldet: ' .. streetName, 'error', 8000)
end)
2025-07-29 10:53:08 +02:00
-- Management menu (alternative opening method)
RegisterNetEvent('vending:client:openManagement', function(machine)
2025-07-29 22:55:55 +02:00
lib.registerContext({
id = 'vending_management',
title = 'Verkaufsautomat #' .. machine.id,
options = {
{
title = 'Inventar öffnen',
description = 'Items hinzufügen oder entfernen',
icon = 'fas fa-box',
onSelect = function()
TriggerServerEvent('vending:server:openStash', machine.coords)
2025-07-29 10:53:08 +02:00
end
2025-07-29 22:55:55 +02:00
},
{
title = 'Einnahmen: $' .. machine.money,
description = 'Geld abheben',
icon = 'fas fa-money-bill',
onSelect = function()
openWithdrawMenu(machine.coords, machine.money)
end
}
}
})
2025-07-29 10:53:08 +02:00
2025-07-29 22:55:55 +02:00
lib.showContext('vending_management')
2025-07-29 07:30:32 +02:00
end)
2025-07-29 10:53:08 +02:00
-- Debug command to check props
2025-07-29 09:39:15 +02:00
RegisterCommand('checkvendingprops', function()
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local foundProps = 0
for _, propName in ipairs(Config.VendingProps) do
local hash = GetHashKey(propName)
local objects = GetGamePool('CObject')
print("Checking for prop: " .. propName .. " (Hash: " .. hash .. ")")
for _, obj in ipairs(objects) do
if GetEntityModel(obj) == hash then
local objCoords = GetEntityCoords(obj)
local dist = #(playerCoords - objCoords)
if dist < 30.0 then
foundProps = foundProps + 1
2025-07-29 10:53:08 +02:00
print("Found " .. propName .. " at distance: " .. dist)
2025-07-29 09:39:15 +02:00
-- Add a temporary blip
local blip = AddBlipForEntity(obj)
SetBlipSprite(blip, 1)
SetBlipColour(blip, 2)
SetBlipScale(blip, 0.8)
BeginTextCommandSetBlipName("STRING")
2025-07-29 10:23:04 +02:00
AddTextComponentString(propName)
2025-07-29 09:39:15 +02:00
EndTextCommandSetBlipName(blip)
-- Remove blip after 10 seconds
SetTimeout(10000, function()
RemoveBlip(blip)
end)
end
end
end
end
QBCore.Functions.Notify('Found ' .. foundProps .. ' vending machines nearby', 'primary')
end, false)
2025-07-29 09:41:19 +02:00
2025-07-29 10:53:08 +02:00
-- Debug commands
2025-07-29 09:48:16 +02:00
RegisterCommand('vendingdebug', function()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
2025-07-29 09:41:19 +02:00
2025-07-29 10:53:08 +02:00
QBCore.Functions.TriggerCallback('vending:server:getMachineByCoords', function(machine)
if machine then
print('Machine found:', json.encode(machine))
QBCore.Functions.Notify('Machine data logged to console', 'primary')
else
print('No machine found at current location')
QBCore.Functions.Notify('No machine found here', 'error')
2025-07-29 09:48:16 +02:00
end
2025-07-29 10:53:08 +02:00
end, coords)
2025-07-29 09:41:19 +02:00
end, false)