1
0
Fork 0
forked from Simnation/Main

Update server.lua

This commit is contained in:
Nordi98 2025-07-29 08:30:01 +02:00
parent f0ffad0cb4
commit 59fc858611

View file

@ -90,7 +90,7 @@ RegisterNetEvent('vending:server:openManagement', function(coords)
TriggerClientEvent('vending:client:openManagement', src, machine) TriggerClientEvent('vending:client:openManagement', src, machine)
end) end)
-- Open stash (korrekt für tgiann-inventory) -- Open stash (korrigiert für tgiann-inventory)
RegisterNetEvent('vending:server:openStash', function(coords) RegisterNetEvent('vending:server:openStash', function(coords)
local src = source local src = source
local Player = QBCore.Functions.GetPlayer(src) local Player = QBCore.Functions.GetPlayer(src)
@ -105,12 +105,11 @@ RegisterNetEvent('vending:server:openStash', function(coords)
return return
end end
-- Korrekte tgiann-inventory Methode -- Verwende TriggerEvent statt TriggerClientEvent für tgiann-inventory
TriggerClientEvent('tgiann-inventory:client:openStash', src, { TriggerEvent('tgiann-inventory:server:openStash', src, machine.stash, {
stashId = machine.stash,
stashLabel = 'Vending Machine #' .. machine.id,
maxweight = Config.MaxWeight, maxweight = Config.MaxWeight,
slots = Config.MaxSlots slots = Config.MaxSlots,
label = 'Vending Machine #' .. machine.id
}) })
end) end)
@ -165,7 +164,7 @@ RegisterNetEvent('vending:server:withdrawMoney', function(coords, amount)
TriggerClientEvent('QBCore:Notify', src, 'Du hast $' .. amount .. ' abgehoben!', 'success') TriggerClientEvent('QBCore:Notify', src, 'Du hast $' .. amount .. ' abgehoben!', 'success')
end) end)
-- Buy item from vending machine -- Buy item from vending machine (korrigiert)
RegisterNetEvent('vending:server:buyItem', function(coords, itemName) RegisterNetEvent('vending:server:buyItem', function(coords, itemName)
local src = source local src = source
local Player = QBCore.Functions.GetPlayer(src) local Player = QBCore.Functions.GetPlayer(src)
@ -183,8 +182,8 @@ RegisterNetEvent('vending:server:buyItem', function(coords, itemName)
return return
end end
-- Get stash items using tgiann-inventory -- Use callback to get stash items
local stashItems = exports['tgiann-inventory']:getStashItems(machine.stash) QBCore.Functions.TriggerCallback('tgiann-inventory:server:getStashItems', function(stashItems)
local hasItem = false local hasItem = false
if stashItems then if stashItems then
@ -208,11 +207,12 @@ RegisterNetEvent('vending:server:buyItem', function(coords, itemName)
machine.money = machine.money + price machine.money = machine.money + price
MySQL.update('UPDATE vending_machines SET money = ? WHERE id = ?', {machine.money, machineId}) MySQL.update('UPDATE vending_machines SET money = ? WHERE id = ?', {machine.money, machineId})
-- Remove item from stash and add to player -- Remove item from stash and add to player using events
exports['tgiann-inventory']:removeItemFromStash(machine.stash, itemName, 1) TriggerEvent('tgiann-inventory:server:removeItemFromStash', machine.stash, itemName, 1)
exports['tgiann-inventory']:addItem(src, itemName, 1) TriggerEvent('tgiann-inventory:server:addItem', src, itemName, 1)
TriggerClientEvent('QBCore:Notify', src, 'Artikel gekauft für $' .. price .. '!', 'success') TriggerClientEvent('QBCore:Notify', src, 'Artikel gekauft für $' .. price .. '!', 'success')
end, src, machine.stash)
end) end)
-- Start robbery -- Start robbery
@ -226,9 +226,9 @@ RegisterNetEvent('vending:server:startRobbery', function(coords)
local machine = vendingMachines[machineId] local machine = vendingMachines[machineId]
-- Check if player has required item -- Check if player has required item using callback
local hasItem = exports['tgiann-inventory']:getItemByName(src, Config.RobberyItem) QBCore.Functions.TriggerCallback('tgiann-inventory:server:getItemByName', function(item)
if not hasItem or hasItem.amount < 1 then if not item or item.amount < 1 then
TriggerClientEvent('QBCore:Notify', src, 'Du benötigst einen ' .. Config.RobberyItem, 'error') TriggerClientEvent('QBCore:Notify', src, 'Du benötigst einen ' .. Config.RobberyItem, 'error')
return return
end end
@ -259,6 +259,7 @@ RegisterNetEvent('vending:server:startRobbery', function(coords)
end end
TriggerClientEvent('vending:client:startRobbery', src, coords) TriggerClientEvent('vending:client:startRobbery', src, coords)
end, src, Config.RobberyItem)
end) end)
-- Complete robbery -- Complete robbery
@ -286,7 +287,7 @@ RegisterNetEvent('vending:server:completeRobbery', function(coords, success)
-- Remove robbery item with chance -- Remove robbery item with chance
if math.random(1, 100) <= Config.RobberyItemBreakChance then if math.random(1, 100) <= Config.RobberyItemBreakChance then
exports['tgiann-inventory']:removeItem(src, Config.RobberyItem, 1) TriggerEvent('tgiann-inventory:server:removeItem', src, Config.RobberyItem, 1)
TriggerClientEvent('QBCore:Notify', src, 'Dein ' .. Config.RobberyItem .. ' ist kaputt gegangen!', 'error') TriggerClientEvent('QBCore:Notify', src, 'Dein ' .. Config.RobberyItem .. ' ist kaputt gegangen!', 'error')
end end
else else
@ -315,7 +316,7 @@ QBCore.Functions.CreateCallback('vending:server:getMachineByCoords', function(so
end end
end) end)
-- Get stash items for vending machine menu -- Get stash items for vending machine menu (korrigiert)
QBCore.Functions.CreateCallback('vending:server:getStashItems', function(source, cb, coords) QBCore.Functions.CreateCallback('vending:server:getStashItems', function(source, cb, coords)
local machineId = getMachineIdByCoords(coords) local machineId = getMachineIdByCoords(coords)
if not machineId then if not machineId then
@ -324,7 +325,9 @@ QBCore.Functions.CreateCallback('vending:server:getStashItems', function(source,
end end
local machine = vendingMachines[machineId] local machine = vendingMachines[machineId]
local stashItems = exports['tgiann-inventory']:getStashItems(machine.stash)
-- Use tgiann-inventory callback to get stash items
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getStashItems', function(stashItems)
local items = {} local items = {}
if stashItems then if stashItems then
@ -337,6 +340,7 @@ QBCore.Functions.CreateCallback('vending:server:getStashItems', function(source,
end end
cb(items) cb(items)
end, source, machine.stash)
end) end)
-- Check if player owns machine -- Check if player owns machine
@ -362,3 +366,13 @@ QBCore.Functions.CreateCallback('vending:server:machineExists', function(source,
local machineId = getMachineIdByCoords(coords) local machineId = getMachineIdByCoords(coords)
cb(machineId ~= nil) cb(machineId ~= nil)
end) end)
-- Debug command
RegisterCommand('vendingdebug', function(source, args)
if source == 0 then -- Server console
print('[Vending] Loaded machines:')
for id, machine in pairs(vendingMachines) do
print('ID:', id, 'Owner:', machine.owner, 'Money:', machine.money)
end
end
end, true)