forked from Simnation/Main
Update client.lua
This commit is contained in:
parent
06a3a3297c
commit
a4780f13be
1 changed files with 90 additions and 52 deletions
|
@ -93,12 +93,12 @@ end, false)
|
|||
|
||||
-- Check if machine is registered
|
||||
function isRegisteredMachine(entity)
|
||||
local coords = GetEntityCoords(entity)
|
||||
local entityId = NetworkGetNetworkIdFromEntity(entity)
|
||||
local isRegistered = false
|
||||
|
||||
QBCore.Functions.TriggerCallback('vending:server:machineExists', function(exists)
|
||||
isRegistered = exists
|
||||
end, coords)
|
||||
end, entityId)
|
||||
|
||||
-- Wait for callback (not ideal but works for canInteract)
|
||||
local timeout = 0
|
||||
|
@ -112,12 +112,12 @@ end
|
|||
|
||||
-- Check if player can manage machine
|
||||
function canManageMachine(entity)
|
||||
local coords = GetEntityCoords(entity)
|
||||
local entityId = NetworkGetNetworkIdFromEntity(entity)
|
||||
local canManage = false
|
||||
|
||||
QBCore.Functions.TriggerCallback('vending:server:canManage', function(result)
|
||||
canManage = result
|
||||
end, coords)
|
||||
end, entityId)
|
||||
|
||||
-- Wait for callback
|
||||
local timeout = 0
|
||||
|
@ -134,8 +134,11 @@ RegisterNetEvent('vending:client:buyMachine', function(data)
|
|||
local entity = data.entity
|
||||
local coords = GetEntityCoords(entity)
|
||||
local model = GetEntityModel(entity)
|
||||
local entityId = NetworkGetNetworkIdFromEntity(entity)
|
||||
local prop = nil
|
||||
|
||||
print("[VENDING] Buying machine: Entity ID: " .. entityId)
|
||||
|
||||
-- Find prop name
|
||||
for i = 1, #Config.VendingProps do
|
||||
if GetHashKey(Config.VendingProps[i]) == model then
|
||||
|
@ -155,7 +158,7 @@ RegisterNetEvent('vending:client:buyMachine', function(data)
|
|||
description = 'Automaten für $' .. Config.VendingMachinePrice .. ' kaufen',
|
||||
icon = 'fas fa-check',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('vending:server:registerMachine', coords, prop)
|
||||
TriggerServerEvent('vending:server:registerMachine', coords, prop, entityId)
|
||||
end
|
||||
},
|
||||
{
|
||||
|
@ -172,7 +175,9 @@ end)
|
|||
-- Open buy menu with quantity selection
|
||||
RegisterNetEvent('vending:client:openBuyMenu', function(data)
|
||||
local entity = data.entity
|
||||
local coords = GetEntityCoords(entity)
|
||||
local entityId = NetworkGetNetworkIdFromEntity(entity)
|
||||
|
||||
print("[VENDING] Opening buy menu: Entity ID: " .. entityId)
|
||||
|
||||
QBCore.Functions.TriggerCallback('vending:server:getStashItems', function(items)
|
||||
if #items == 0 then
|
||||
|
@ -191,7 +196,7 @@ RegisterNetEvent('vending:client:openBuyMenu', function(data)
|
|||
description = 'Preis: $' .. item.price .. ' | Verfügbar: ' .. item.amount,
|
||||
icon = 'fas fa-shopping-cart',
|
||||
onSelect = function()
|
||||
openQuantityDialog(coords, item.name, item.price, item.amount, itemLabel)
|
||||
openQuantityDialog(entityId, item.name, item.price, item.amount, itemLabel)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
@ -209,11 +214,11 @@ RegisterNetEvent('vending:client:openBuyMenu', function(data)
|
|||
})
|
||||
|
||||
lib.showContext('vending_buy_menu')
|
||||
end, coords)
|
||||
end, entityId)
|
||||
end)
|
||||
|
||||
-- Open quantity dialog for buying items
|
||||
function openQuantityDialog(coords, itemName, price, maxAmount, itemLabel)
|
||||
function openQuantityDialog(entityId, itemName, price, maxAmount, itemLabel)
|
||||
local input = lib.inputDialog('Menge auswählen', {
|
||||
{
|
||||
type = 'number',
|
||||
|
@ -229,7 +234,7 @@ function openQuantityDialog(coords, itemName, price, maxAmount, itemLabel)
|
|||
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)
|
||||
TriggerServerEvent('vending:server:buyItem', itemName, amount, entityId)
|
||||
else
|
||||
QBCore.Functions.Notify('Ungültige Menge!', 'error')
|
||||
end
|
||||
|
@ -239,21 +244,25 @@ end
|
|||
-- Open owner menu
|
||||
RegisterNetEvent('vending:client:openOwnerMenu', function(data)
|
||||
local entity = data.entity
|
||||
local coords = GetEntityCoords(entity)
|
||||
local entityId = NetworkGetNetworkIdFromEntity(entity)
|
||||
|
||||
QBCore.Functions.TriggerCallback('vending:server:getMachineByCoords', function(machine)
|
||||
print("[VENDING] Opening owner menu: Entity ID: " .. entityId)
|
||||
|
||||
QBCore.Functions.TriggerCallback('vending:server:getMachineByEntity', function(machine)
|
||||
if not machine then
|
||||
QBCore.Functions.Notify('Automat nicht gefunden!', 'error')
|
||||
return
|
||||
end
|
||||
|
||||
print("[VENDING] Machine data received: ID: " .. machine.id .. ", isOwner: " .. tostring(machine.isOwner))
|
||||
|
||||
local options = {
|
||||
{
|
||||
title = 'Inventar verwalten',
|
||||
description = 'Items hinzufügen/entfernen',
|
||||
icon = 'fas fa-box',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('vending:server:openStash', coords)
|
||||
TriggerServerEvent('vending:server:openStash', entityId)
|
||||
end
|
||||
},
|
||||
{
|
||||
|
@ -261,7 +270,7 @@ RegisterNetEvent('vending:client:openOwnerMenu', function(data)
|
|||
description = 'Verkaufspreise für Items setzen',
|
||||
icon = 'fas fa-tags',
|
||||
onSelect = function()
|
||||
openPriceMenu(coords)
|
||||
openPriceMenu(entityId)
|
||||
end
|
||||
},
|
||||
{
|
||||
|
@ -269,7 +278,7 @@ RegisterNetEvent('vending:client:openOwnerMenu', function(data)
|
|||
description = 'Verfügbar: $' .. machine.money,
|
||||
icon = 'fas fa-money-bill',
|
||||
onSelect = function()
|
||||
openWithdrawMenu(coords, machine.money)
|
||||
openWithdrawMenu(entityId, machine.money)
|
||||
end
|
||||
},
|
||||
{
|
||||
|
@ -284,12 +293,13 @@ RegisterNetEvent('vending:client:openOwnerMenu', function(data)
|
|||
|
||||
-- Add manager options only for owner
|
||||
if machine.isOwner then
|
||||
print("[VENDING] Adding manager options for owner")
|
||||
table.insert(options, {
|
||||
title = 'Verwalter',
|
||||
description = 'Verwalter hinzufügen/entfernen',
|
||||
icon = 'fas fa-users-cog',
|
||||
onSelect = function()
|
||||
openManagersMenu(coords)
|
||||
openManagersMenu(entityId)
|
||||
end
|
||||
})
|
||||
|
||||
|
@ -299,9 +309,11 @@ RegisterNetEvent('vending:client:openOwnerMenu', function(data)
|
|||
description = 'Verkaufe den Automaten für ' .. math.floor(Config.VendingMachinePrice * Config.SellBackPercentage / 100) .. '$',
|
||||
icon = 'fas fa-dollar-sign',
|
||||
onSelect = function()
|
||||
sellVendingMachine(coords, machine.id)
|
||||
sellVendingMachine(entityId, machine.id)
|
||||
end
|
||||
})
|
||||
else
|
||||
print("[VENDING] Not adding manager options - not owner")
|
||||
end
|
||||
|
||||
lib.registerContext({
|
||||
|
@ -311,11 +323,11 @@ RegisterNetEvent('vending:client:openOwnerMenu', function(data)
|
|||
})
|
||||
|
||||
lib.showContext('vending_owner_menu')
|
||||
end, coords)
|
||||
end, entityId)
|
||||
end)
|
||||
|
||||
-- Funktion zum Verkaufen des Automaten
|
||||
function sellVendingMachine(coords, machineId)
|
||||
function sellVendingMachine(entityId, machineId)
|
||||
local input = lib.inputDialog('Automaten verkaufen', {
|
||||
{
|
||||
type = 'checkbox',
|
||||
|
@ -326,12 +338,12 @@ function sellVendingMachine(coords, machineId)
|
|||
})
|
||||
|
||||
if input and input[1] then
|
||||
TriggerServerEvent('vending:server:sellMachine', coords, machineId)
|
||||
TriggerServerEvent('vending:server:sellMachine', machineId, entityId)
|
||||
end
|
||||
end
|
||||
|
||||
-- Open price menu
|
||||
function openPriceMenu(coords)
|
||||
function openPriceMenu(entityId)
|
||||
QBCore.Functions.TriggerCallback('vending:server:getStashItems', function(items)
|
||||
if #items == 0 then
|
||||
QBCore.Functions.Notify('Keine Items im Automaten!', 'error')
|
||||
|
@ -348,7 +360,7 @@ function openPriceMenu(coords)
|
|||
description = 'Aktueller Preis: $' .. item.price,
|
||||
icon = 'fas fa-tag',
|
||||
onSelect = function()
|
||||
setPriceForItem(coords, item.name, itemLabel)
|
||||
setPriceForItem(entityId, item.name, itemLabel)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
@ -361,11 +373,11 @@ function openPriceMenu(coords)
|
|||
})
|
||||
|
||||
lib.showContext('vending_price_menu')
|
||||
end, coords)
|
||||
end, entityId)
|
||||
end
|
||||
|
||||
-- Set price for specific item
|
||||
function setPriceForItem(coords, itemName, itemLabel)
|
||||
function setPriceForItem(entityId, itemName, itemLabel)
|
||||
local input = lib.inputDialog('Preis festlegen', {
|
||||
{
|
||||
type = 'number',
|
||||
|
@ -378,12 +390,12 @@ function setPriceForItem(coords, itemName, itemLabel)
|
|||
})
|
||||
|
||||
if input and input[1] then
|
||||
TriggerServerEvent('vending:server:setItemPrice', coords, itemName, tonumber(input[1]))
|
||||
TriggerServerEvent('vending:server:setItemPrice', itemName, tonumber(input[1]), entityId)
|
||||
end
|
||||
end
|
||||
|
||||
-- Open withdraw menu
|
||||
function openWithdrawMenu(coords, availableMoney)
|
||||
function openWithdrawMenu(entityId, availableMoney)
|
||||
if availableMoney <= 0 then
|
||||
QBCore.Functions.Notify('Kein Geld im Automaten!', 'error')
|
||||
return
|
||||
|
@ -401,7 +413,7 @@ function openWithdrawMenu(coords, availableMoney)
|
|||
})
|
||||
|
||||
if input and input[1] then
|
||||
TriggerServerEvent('vending:server:withdrawMoney', coords, tonumber(input[1]))
|
||||
TriggerServerEvent('vending:server:withdrawMoney', tonumber(input[1]), entityId)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -434,7 +446,7 @@ function openStatsMenu(machine)
|
|||
end
|
||||
|
||||
-- Open managers menu
|
||||
function openManagersMenu(coords)
|
||||
function openManagersMenu(entityId)
|
||||
-- Get current managers
|
||||
QBCore.Functions.TriggerCallback('vending:server:getManagers', function(managers)
|
||||
local options = {
|
||||
|
@ -443,7 +455,7 @@ function openManagersMenu(coords)
|
|||
description = 'Neuen Verwalter hinzufügen',
|
||||
icon = 'fas fa-user-plus',
|
||||
onSelect = function()
|
||||
openAddManagerMenu(coords)
|
||||
openAddManagerMenu(entityId)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
@ -467,9 +479,9 @@ function openManagersMenu(coords)
|
|||
description = 'Verwalter entfernen',
|
||||
icon = 'fas fa-user-minus',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('vending:server:removeManager', coords, manager.citizenid)
|
||||
TriggerServerEvent('vending:server:removeManager', manager.citizenid, entityId)
|
||||
Wait(500)
|
||||
openManagersMenu(coords) -- Refresh the menu
|
||||
openManagersMenu(entityId) -- Refresh the menu
|
||||
end
|
||||
}
|
||||
}
|
||||
|
@ -495,11 +507,11 @@ function openManagersMenu(coords)
|
|||
})
|
||||
|
||||
lib.showContext('managers_menu')
|
||||
end, coords)
|
||||
end, entityId)
|
||||
end
|
||||
|
||||
-- Open add manager menu
|
||||
function openAddManagerMenu(coords)
|
||||
function openAddManagerMenu(entityId)
|
||||
QBCore.Functions.TriggerCallback('vending:server:getOnlinePlayers', function(players)
|
||||
if #players == 0 then
|
||||
QBCore.Functions.Notify('Keine Spieler online!', 'error')
|
||||
|
@ -515,9 +527,9 @@ function openAddManagerMenu(coords)
|
|||
description = 'ID: ' .. player.id,
|
||||
icon = 'fas fa-user',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('vending:server:addManager', coords, player.id)
|
||||
TriggerServerEvent('vending:server:addManager', player.id, entityId)
|
||||
Wait(500)
|
||||
openManagersMenu(coords) -- Refresh the menu
|
||||
openManagersMenu(entityId) -- Refresh the menu
|
||||
end
|
||||
})
|
||||
end
|
||||
|
@ -536,7 +548,7 @@ end
|
|||
-- Robbery menu
|
||||
RegisterNetEvent('vending:client:startRobbery', function(data)
|
||||
local entity = data.entity
|
||||
local coords = GetEntityCoords(entity)
|
||||
local entityId = NetworkGetNetworkIdFromEntity(entity)
|
||||
|
||||
lib.registerContext({
|
||||
id = 'vending_robbery_confirm',
|
||||
|
@ -547,7 +559,7 @@ RegisterNetEvent('vending:client:startRobbery', function(data)
|
|||
description = 'Versuche den Automaten aufzubrechen',
|
||||
icon = 'fas fa-mask',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('vending:server:startRobbery', coords)
|
||||
TriggerServerEvent('vending:server:startRobbery', entityId)
|
||||
end
|
||||
},
|
||||
{
|
||||
|
@ -562,7 +574,7 @@ RegisterNetEvent('vending:client:startRobbery', function(data)
|
|||
end)
|
||||
|
||||
-- Start robbery animation and progress
|
||||
RegisterNetEvent('vending:client:startRobbery', function(coords)
|
||||
RegisterNetEvent('vending:client:startRobbery', function(entityId)
|
||||
local playerPed = PlayerPedId()
|
||||
local robberyTime = 10000 -- 10 seconds
|
||||
|
||||
|
@ -589,12 +601,12 @@ RegisterNetEvent('vending:client:startRobbery', function(coords)
|
|||
})
|
||||
|
||||
ClearPedTasks(playerPed)
|
||||
TriggerServerEvent('vending:server:completeRobbery', coords, success)
|
||||
TriggerServerEvent('vending:server:completeRobbery', entityId, success)
|
||||
else
|
||||
-- Fallback without progress bar
|
||||
Wait(robberyTime)
|
||||
ClearPedTasks(playerPed)
|
||||
TriggerServerEvent('vending:server:completeRobbery', coords, true)
|
||||
TriggerServerEvent('vending:server:completeRobbery', entityId, true)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -640,7 +652,7 @@ RegisterNetEvent('vending:client:openManagement', function(machine)
|
|||
description = 'Items hinzufügen oder entfernen',
|
||||
icon = 'fas fa-box',
|
||||
onSelect = function()
|
||||
TriggerServerEvent('vending:server:openStash', machine.coords)
|
||||
TriggerServerEvent('vending:server:openStash', machine.entityId)
|
||||
end
|
||||
},
|
||||
{
|
||||
|
@ -648,7 +660,7 @@ RegisterNetEvent('vending:client:openManagement', function(machine)
|
|||
description = 'Geld abheben',
|
||||
icon = 'fas fa-money-bill',
|
||||
onSelect = function()
|
||||
openWithdrawMenu(machine.coords, machine.money)
|
||||
openWithdrawMenu(machine.entityId, machine.money)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
@ -676,7 +688,8 @@ RegisterCommand('checkvendingprops', function()
|
|||
|
||||
if dist < 30.0 then
|
||||
foundProps = foundProps + 1
|
||||
print("Found " .. propName .. " at distance: " .. dist)
|
||||
local entityId = NetworkGetNetworkIdFromEntity(obj)
|
||||
print("Found " .. propName .. " at distance: " .. dist .. " | Entity ID: " .. entityId)
|
||||
|
||||
-- Add a temporary blip
|
||||
local blip = AddBlipForEntity(obj)
|
||||
|
@ -684,7 +697,7 @@ RegisterCommand('checkvendingprops', function()
|
|||
SetBlipColour(blip, 2)
|
||||
SetBlipScale(blip, 0.8)
|
||||
BeginTextCommandSetBlipName("STRING")
|
||||
AddTextComponentString(propName)
|
||||
AddTextComponentString(propName .. " | ID: " .. entityId)
|
||||
EndTextCommandSetBlipName(blip)
|
||||
|
||||
-- Remove blip after 10 seconds
|
||||
|
@ -703,14 +716,39 @@ end, false)
|
|||
RegisterCommand('vendingdebug', function()
|
||||
local playerPed = PlayerPedId()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
local entity = nil
|
||||
local entityId = 0
|
||||
|
||||
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')
|
||||
-- Try to find the closest vending machine
|
||||
local minDist = 3.0
|
||||
local objects = GetGamePool('CObject')
|
||||
|
||||
for _, obj in ipairs(objects) do
|
||||
local model = GetEntityModel(obj)
|
||||
for _, propName in ipairs(Config.VendingProps) do
|
||||
if model == GetHashKey(propName) then
|
||||
local objCoords = GetEntityCoords(obj)
|
||||
local dist = #(coords - objCoords)
|
||||
if dist < minDist then
|
||||
minDist = dist
|
||||
entity = obj
|
||||
entityId = NetworkGetNetworkIdFromEntity(obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
end, coords)
|
||||
end
|
||||
|
||||
if entity then
|
||||
QBCore.Functions.TriggerCallback('vending:server:getMachineByEntity', function(machine)
|
||||
if machine then
|
||||
print('Machine found:', json.encode(machine))
|
||||
QBCore.Functions.Notify('Machine #' .. machine.id .. ' | Entity ID: ' .. entityId .. ' | Owner: ' .. machine.owner, 'primary')
|
||||
else
|
||||
print('No machine found with entity ID:', entityId)
|
||||
QBCore.Functions.Notify('No machine found with entity ID: ' .. entityId, 'error')
|
||||
end
|
||||
end, entityId)
|
||||
else
|
||||
QBCore.Functions.Notify('No vending machine found nearby', 'error')
|
||||
end
|
||||
end, false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue