1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-29 09:02:52 +02:00
parent 179f7c0d12
commit c688255b8a
2 changed files with 486 additions and 80 deletions

View file

@ -11,7 +11,7 @@ CreateThread(function()
event = "vending:client:buyMachine",
icon = "fas fa-dollar-sign",
label = "Automaten kaufen ($" .. Config.VendingMachinePrice .. ")",
canInteract = function(entity, distance, data)
canInteract = function(entity)
return not isRegisteredMachine(entity)
end
},
@ -20,7 +20,7 @@ CreateThread(function()
event = "vending:client:openBuyMenu",
icon = "fas fa-shopping-cart",
label = "Kaufen",
canInteract = function(entity, distance, data)
canInteract = function(entity)
return isRegisteredMachine(entity)
end
},
@ -29,8 +29,8 @@ CreateThread(function()
event = "vending:client:openOwnerMenu",
icon = "fas fa-cog",
label = "Verwalten",
canInteract = function(entity, distance, data)
return isOwnerOfMachine(entity)
canInteract = function(entity)
return canManageMachine(entity)
end
},
{
@ -38,8 +38,8 @@ CreateThread(function()
event = "vending:client:startRobbery",
icon = "fas fa-mask",
label = "Aufbrechen",
canInteract = function(entity, distance, data)
return isRegisteredMachine(entity) and not isOwnerOfMachine(entity)
canInteract = function(entity)
return isRegisteredMachine(entity) and not canManageMachine(entity)
end
}
},
@ -66,23 +66,23 @@ function isRegisteredMachine(entity)
return isRegistered
end
-- Check if player owns machine
function isOwnerOfMachine(entity)
-- Check if player can manage machine
function canManageMachine(entity)
local coords = GetEntityCoords(entity)
local isOwner = false
local canManage = false
QBCore.Functions.TriggerCallback('vending:server:isOwner', function(owner)
isOwner = owner
QBCore.Functions.TriggerCallback('vending:server:canManage', function(result)
canManage = result
end, coords)
-- Wait for callback
local timeout = 0
while isOwner == false and timeout < 100 do
while canManage == false and timeout < 100 do
Wait(10)
timeout = timeout + 1
end
return isOwner
return canManage
end
-- Buy vending machine
@ -125,7 +125,7 @@ RegisterNetEvent('vending:client:buyMachine', function(data)
lib.showContext('vending_buy_confirm')
end)
-- Open buy menu
-- Open buy menu with quantity selection
RegisterNetEvent('vending:client:openBuyMenu', function(data)
local entity = data.entity
local coords = GetEntityCoords(entity)
@ -147,7 +147,7 @@ RegisterNetEvent('vending:client:openBuyMenu', function(data)
description = 'Preis: $' .. item.price .. ' | Verfügbar: ' .. item.amount,
icon = 'fas fa-shopping-cart',
onSelect = function()
TriggerServerEvent('vending:server:buyItem', coords, item.name)
openQuantityDialog(coords, item.name, item.price, item.amount, itemLabel)
end
})
end
@ -168,6 +168,30 @@ RegisterNetEvent('vending:client:openBuyMenu', function(data)
end, coords)
end)
-- 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
-- Open owner menu
RegisterNetEvent('vending:client:openOwnerMenu', function(data)
local entity = data.entity
@ -179,43 +203,57 @@ RegisterNetEvent('vending:client:openOwnerMenu', function(data)
return
end
local options = {
{
title = 'Inventar verwalten',
description = 'Items hinzufügen/entfernen',
icon = 'fas fa-box',
onSelect = function()
TriggerServerEvent('vending:server:openStash', coords)
end
},
{
title = 'Preise festlegen',
description = 'Verkaufspreise für Items setzen',
icon = 'fas fa-tags',
onSelect = function()
openPriceMenu(coords)
end
},
{
title = 'Geld abheben',
description = 'Verfügbar: $' .. machine.money,
icon = 'fas fa-money-bill',
onSelect = function()
openWithdrawMenu(coords, machine.money)
end
},
{
title = 'Statistiken',
description = 'Verkaufsstatistiken anzeigen',
icon = 'fas fa-chart-bar',
onSelect = function()
openStatsMenu(machine)
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()
openManagersMenu(coords)
end
})
end
lib.registerContext({
id = 'vending_owner_menu',
title = 'Verkaufsautomat Verwaltung',
options = {
{
title = 'Inventar verwalten',
description = 'Items hinzufügen/entfernen',
icon = 'fas fa-box',
onSelect = function()
TriggerServerEvent('vending:server:openStash', coords)
end
},
{
title = 'Preise festlegen',
description = 'Verkaufspreise für Items setzen',
icon = 'fas fa-tags',
onSelect = function()
openPriceMenu(coords)
end
},
{
title = 'Geld abheben',
description = 'Verfügbar: $' .. machine.money,
icon = 'fas fa-money-bill',
onSelect = function()
openWithdrawMenu(coords, machine.money)
end
},
{
title = 'Statistiken',
description = 'Verkaufsstatistiken anzeigen',
icon = 'fas fa-chart-bar',
onSelect = function()
openStatsMenu(machine)
end
}
}
options = options
})
lib.showContext('vending_owner_menu')
@ -325,7 +363,107 @@ function openStatsMenu(machine)
lib.showContext('vending_stats_menu')
end
-- Start robbery
-- Open managers menu
function openManagersMenu(coords)
-- Get current managers
QBCore.Functions.TriggerCallback('vending:server:getManagers', function(managers)
local options = {
{
title = 'Verwalter hinzufügen',
description = 'Neuen Verwalter hinzufügen',
icon = 'fas fa-user-plus',
onSelect = function()
openAddManagerMenu(coords)
end
}
}
-- Add existing managers with remove option
if #managers > 0 then
for i = 1, #managers do
local manager = managers[i]
table.insert(options, {
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
})
end
else
table.insert(options, {
title = 'Keine Verwalter',
description = 'Es sind keine Verwalter vorhanden',
icon = 'fas fa-info-circle',
disabled = true
})
end
lib.registerContext({
id = 'managers_menu',
title = 'Verwalter verwalten',
menu = 'vending_owner_menu',
options = options
})
lib.showContext('managers_menu')
end, coords)
end
-- Open add manager menu
function openAddManagerMenu(coords)
QBCore.Functions.TriggerCallback('vending:server:getOnlinePlayers', function(players)
if #players == 0 then
QBCore.Functions.Notify('Keine Spieler online!', 'error')
return
end
local options = {}
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
end
})
end
lib.registerContext({
id = 'add_manager_menu',
title = 'Verwalter hinzufügen',
menu = 'managers_menu',
options = options
})
lib.showContext('add_manager_menu')
end)
end
-- Robbery menu
RegisterNetEvent('vending:client:startRobbery', function(data)
local entity = data.entity
local coords = GetEntityCoords(entity)