forked from Simnation/Main
Update server.lua
This commit is contained in:
parent
75740691bc
commit
ab8f61b35b
1 changed files with 93 additions and 86 deletions
|
@ -90,7 +90,7 @@ RegisterNetEvent('vending:server:openManagement', function(coords)
|
|||
TriggerClientEvent('vending:client:openManagement', src, machine)
|
||||
end)
|
||||
|
||||
-- Open stash (korrigiert für tgiann-inventory)
|
||||
-- Open stash (mit korrektem tgiann-inventory Export)
|
||||
RegisterNetEvent('vending:server:openStash', function(coords)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
|
@ -105,12 +105,8 @@ RegisterNetEvent('vending:server:openStash', function(coords)
|
|||
return
|
||||
end
|
||||
|
||||
-- Verwende TriggerEvent statt TriggerClientEvent für tgiann-inventory
|
||||
TriggerEvent('tgiann-inventory:server:openStash', src, machine.stash, {
|
||||
maxweight = Config.MaxWeight,
|
||||
slots = Config.MaxSlots,
|
||||
label = 'Vending Machine #' .. machine.id
|
||||
})
|
||||
-- Korrekte tgiann-inventory Stash öffnen
|
||||
exports['tgiann-inventory']:OpenStash(src, machine.stash, 'Vending Machine #' .. machine.id, Config.MaxWeight, Config.MaxSlots)
|
||||
end)
|
||||
|
||||
-- Set item price
|
||||
|
@ -164,7 +160,7 @@ RegisterNetEvent('vending:server:withdrawMoney', function(coords, amount)
|
|||
TriggerClientEvent('QBCore:Notify', src, 'Du hast $' .. amount .. ' abgehoben!', 'success')
|
||||
end)
|
||||
|
||||
-- Buy item from vending machine (korrigiert)
|
||||
-- Buy item from vending machine (mit korrekten Exports)
|
||||
RegisterNetEvent('vending:server:buyItem', function(coords, itemName)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
|
@ -182,14 +178,16 @@ RegisterNetEvent('vending:server:buyItem', function(coords, itemName)
|
|||
return
|
||||
end
|
||||
|
||||
-- Use callback to get stash items
|
||||
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getStashItems', function(stashItems)
|
||||
-- Get stash items using correct export
|
||||
local stashItems = exports['tgiann-inventory']:GetStashItems(machine.stash)
|
||||
local hasItem = false
|
||||
local itemAmount = 0
|
||||
|
||||
if stashItems then
|
||||
for slot, item in pairs(stashItems) do
|
||||
if item.name == itemName and item.amount > 0 then
|
||||
hasItem = true
|
||||
itemAmount = item.amount
|
||||
break
|
||||
end
|
||||
end
|
||||
|
@ -207,12 +205,11 @@ RegisterNetEvent('vending:server:buyItem', function(coords, itemName)
|
|||
machine.money = machine.money + price
|
||||
MySQL.update('UPDATE vending_machines SET money = ? WHERE id = ?', {machine.money, machineId})
|
||||
|
||||
-- Remove item from stash and add to player using events
|
||||
TriggerEvent('tgiann-inventory:server:removeItemFromStash', machine.stash, itemName, 1)
|
||||
TriggerEvent('tgiann-inventory:server:addItem', src, itemName, 1)
|
||||
-- Remove item from stash and add to player
|
||||
exports['tgiann-inventory']:RemoveItemFromStash(machine.stash, itemName, 1)
|
||||
exports['tgiann-inventory']:AddItem(src, itemName, 1)
|
||||
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Artikel gekauft für $' .. price .. '!', 'success')
|
||||
end, src, machine.stash)
|
||||
end)
|
||||
|
||||
-- Start robbery
|
||||
|
@ -226,9 +223,9 @@ RegisterNetEvent('vending:server:startRobbery', function(coords)
|
|||
|
||||
local machine = vendingMachines[machineId]
|
||||
|
||||
-- Check if player has required item using callback
|
||||
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getItemByName', function(item)
|
||||
if not item or item.amount < 1 then
|
||||
-- Check if player has required item using correct export
|
||||
local hasItem = exports['tgiann-inventory']:GetItemByName(src, Config.RobberyItem)
|
||||
if not hasItem or hasItem.amount < 1 then
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Du benötigst einen ' .. Config.RobberyItem, 'error')
|
||||
return
|
||||
end
|
||||
|
@ -259,7 +256,6 @@ RegisterNetEvent('vending:server:startRobbery', function(coords)
|
|||
end
|
||||
|
||||
TriggerClientEvent('vending:client:startRobbery', src, coords)
|
||||
end, src, Config.RobberyItem)
|
||||
end)
|
||||
|
||||
-- Complete robbery
|
||||
|
@ -287,7 +283,7 @@ RegisterNetEvent('vending:server:completeRobbery', function(coords, success)
|
|||
|
||||
-- Remove robbery item with chance
|
||||
if math.random(1, 100) <= Config.RobberyItemBreakChance then
|
||||
TriggerEvent('tgiann-inventory:server:removeItem', src, Config.RobberyItem, 1)
|
||||
exports['tgiann-inventory']:RemoveItem(src, Config.RobberyItem, 1)
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Dein ' .. Config.RobberyItem .. ' ist kaputt gegangen!', 'error')
|
||||
end
|
||||
else
|
||||
|
@ -316,7 +312,7 @@ QBCore.Functions.CreateCallback('vending:server:getMachineByCoords', function(so
|
|||
end
|
||||
end)
|
||||
|
||||
-- Get stash items for vending machine menu (korrigiert)
|
||||
-- Get stash items for vending machine menu (mit korrektem Export)
|
||||
QBCore.Functions.CreateCallback('vending:server:getStashItems', function(source, cb, coords)
|
||||
local machineId = getMachineIdByCoords(coords)
|
||||
if not machineId then
|
||||
|
@ -326,8 +322,8 @@ QBCore.Functions.CreateCallback('vending:server:getStashItems', function(source,
|
|||
|
||||
local machine = vendingMachines[machineId]
|
||||
|
||||
-- Use tgiann-inventory callback to get stash items
|
||||
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getStashItems', function(stashItems)
|
||||
-- Use correct tgiann-inventory export
|
||||
local stashItems = exports['tgiann-inventory']:GetStashItems(machine.stash)
|
||||
local items = {}
|
||||
|
||||
if stashItems then
|
||||
|
@ -340,7 +336,6 @@ QBCore.Functions.CreateCallback('vending:server:getStashItems', function(source,
|
|||
end
|
||||
|
||||
cb(items)
|
||||
end, source, machine.stash)
|
||||
end)
|
||||
|
||||
-- Check if player owns machine
|
||||
|
@ -374,5 +369,17 @@ RegisterCommand('vendingdebug', function(source, args)
|
|||
for id, machine in pairs(vendingMachines) do
|
||||
print('ID:', id, 'Owner:', machine.owner, 'Money:', machine.money)
|
||||
end
|
||||
else
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if Player then
|
||||
local coords = GetEntityCoords(GetPlayerPed(source))
|
||||
local machineId = getMachineIdByCoords(coords)
|
||||
if machineId then
|
||||
local machine = vendingMachines[machineId]
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Machine ID: ' .. machineId .. ' | Owner: ' .. machine.owner .. ' | Money: $' .. machine.money, 'primary')
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Keine Vending Machine in der Nähe!', 'error')
|
||||
end
|
||||
end, true)
|
||||
end
|
||||
end
|
||||
end, false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue