Update server.lua
This commit is contained in:
parent
90d92129ee
commit
5190cf1220
1 changed files with 63 additions and 56 deletions
|
@ -18,15 +18,6 @@ CreateThread(function()
|
|||
prices = json.decode(data.prices) or {},
|
||||
stash = 'vending_' .. data.id
|
||||
}
|
||||
|
||||
-- Create stash for this vending machine
|
||||
exports['tgiann-inventory']:CreateStash({
|
||||
stashId = 'vending_' .. data.id,
|
||||
stashName = 'Vending Machine #' .. data.id,
|
||||
maxWeight = Config.MaxWeight,
|
||||
maxSlots = Config.MaxSlots,
|
||||
stashCoords = vendingMachines[data.id].coords
|
||||
})
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -77,15 +68,6 @@ RegisterNetEvent('vending:server:registerMachine', function(coords, prop)
|
|||
stash = 'vending_' .. machineId
|
||||
}
|
||||
|
||||
-- Create stash
|
||||
exports['tgiann-inventory']:CreateStash({
|
||||
stashId = 'vending_' .. machineId,
|
||||
stashName = 'Vending Machine #' .. machineId,
|
||||
maxWeight = Config.MaxWeight,
|
||||
maxSlots = Config.MaxSlots,
|
||||
stashCoords = coords
|
||||
})
|
||||
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Verkaufsautomat erfolgreich gekauft für $' .. Config.VendingMachinePrice .. '!', 'success')
|
||||
TriggerClientEvent('vending:client:refreshTargets', -1)
|
||||
end)
|
||||
|
@ -123,7 +105,12 @@ RegisterNetEvent('vending:server:openStash', function(coords)
|
|||
return
|
||||
end
|
||||
|
||||
exports['tgiann-inventory']:OpenStash(src, machine.stash)
|
||||
-- Open stash using tgiann-inventory
|
||||
TriggerEvent('tgiann-inventory:server:openStash', src, machine.stash, {
|
||||
maxweight = Config.MaxWeight,
|
||||
slots = Config.MaxSlots,
|
||||
label = 'Vending Machine #' .. machine.id
|
||||
})
|
||||
end)
|
||||
|
||||
-- Set item price
|
||||
|
@ -195,16 +182,18 @@ RegisterNetEvent('vending:server:buyItem', function(coords, itemName)
|
|||
return
|
||||
end
|
||||
|
||||
-- Check if item is available in stash
|
||||
local stashItems = exports['tgiann-inventory']:GetStashItems(machine.stash)
|
||||
-- Get stash items using tgiann-inventory callback
|
||||
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getStashItems', function(stashItems)
|
||||
local hasItem = false
|
||||
|
||||
for i = 1, #stashItems do
|
||||
if stashItems[i].name == itemName and stashItems[i].amount > 0 then
|
||||
if stashItems then
|
||||
for slot, item in pairs(stashItems) do
|
||||
if item.name == itemName and item.amount > 0 then
|
||||
hasItem = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not hasItem then
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Artikel nicht verfügbar!', 'error')
|
||||
|
@ -218,11 +207,14 @@ 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 give to player
|
||||
exports['tgiann-inventory']:RemoveItemFromStash(machine.stash, itemName, 1)
|
||||
exports['tgiann-inventory']:AddItem(src, itemName, 1)
|
||||
-- Remove item from stash
|
||||
TriggerEvent('tgiann-inventory:server:removeItemFromStash', machine.stash, itemName, 1)
|
||||
|
||||
-- Add item to player
|
||||
TriggerEvent('tgiann-inventory:server:addItem', src, itemName, 1)
|
||||
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Artikel gekauft für $' .. price .. '!', 'success')
|
||||
end, src, machine.stash)
|
||||
end)
|
||||
|
||||
-- Start robbery
|
||||
|
@ -237,8 +229,15 @@ RegisterNetEvent('vending:server:startRobbery', function(coords)
|
|||
local machine = vendingMachines[machineId]
|
||||
|
||||
-- Check if player has required item
|
||||
local hasItem = exports['tgiann-inventory']:GetItemByName(src, Config.RobberyItem)
|
||||
if not hasItem or hasItem.amount < 1 then
|
||||
local hasItem = false
|
||||
for k, v in pairs(Player.PlayerData.items) do
|
||||
if v.name == Config.RobberyItem and v.amount > 0 then
|
||||
hasItem = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not hasItem then
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Du benötigst einen ' .. Config.RobberyItem, 'error')
|
||||
return
|
||||
end
|
||||
|
@ -296,7 +295,7 @@ RegisterNetEvent('vending:server:completeRobbery', function(coords, success)
|
|||
|
||||
-- Remove robbery item with chance
|
||||
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')
|
||||
end
|
||||
else
|
||||
|
@ -334,14 +333,22 @@ QBCore.Functions.CreateCallback('vending:server:getStashItems', function(source,
|
|||
end
|
||||
|
||||
local machine = vendingMachines[machineId]
|
||||
local items = exports['tgiann-inventory']:GetStashItems(machine.stash)
|
||||
|
||||
-- Add prices to items
|
||||
for i = 1, #items do
|
||||
items[i].price = machine.prices[items[i].name] or Config.DefaultPrice
|
||||
-- Get stash items using tgiann-inventory callback
|
||||
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getStashItems', function(stashItems)
|
||||
local items = {}
|
||||
|
||||
if stashItems then
|
||||
for slot, item in pairs(stashItems) do
|
||||
if item.amount > 0 then
|
||||
item.price = machine.prices[item.name] or Config.DefaultPrice
|
||||
table.insert(items, item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
cb(items)
|
||||
end, source, machine.stash)
|
||||
end)
|
||||
|
||||
-- Check if player owns machine
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue