forked from Simnation/Main
Update client.lua
This commit is contained in:
parent
7b0763ef2f
commit
e947b360e7
1 changed files with 61 additions and 56 deletions
|
@ -1,9 +1,12 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Add targets to all vending machine props
|
-- Function to initialize targets
|
||||||
CreateThread(function()
|
function InitializeTargets()
|
||||||
Wait(2000)
|
-- Remove existing targets first to avoid duplicates
|
||||||
|
exports['qb-target']:RemoveTargetModel(Config.VendingProps)
|
||||||
|
Wait(100)
|
||||||
|
|
||||||
|
-- Add targets
|
||||||
exports['qb-target']:AddTargetModel(Config.VendingProps, {
|
exports['qb-target']:AddTargetModel(Config.VendingProps, {
|
||||||
options = {
|
options = {
|
||||||
{
|
{
|
||||||
|
@ -45,8 +48,49 @@ CreateThread(function()
|
||||||
},
|
},
|
||||||
distance = 2.0
|
distance = 2.0
|
||||||
})
|
})
|
||||||
|
|
||||||
|
print("^2[VENDING]^7 Added targets to " .. #Config.VendingProps .. " vending machine props")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add targets to all vending machine props with multiple attempts (Option 1)
|
||||||
|
CreateThread(function()
|
||||||
|
-- First attempt
|
||||||
|
Wait(2000)
|
||||||
|
InitializeTargets()
|
||||||
|
|
||||||
|
-- Second attempt after a delay
|
||||||
|
Wait(5000)
|
||||||
|
InitializeTargets()
|
||||||
|
|
||||||
|
-- Third attempt after server is fully loaded
|
||||||
|
Wait(10000)
|
||||||
|
InitializeTargets()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Event-based initialization (Option 2)
|
||||||
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||||
|
Wait(1000)
|
||||||
|
InitializeTargets()
|
||||||
|
end)
|
||||||
|
|
||||||
|
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
||||||
|
-- Nothing to do here, but good to have for completeness
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Listen for resource start/stop events
|
||||||
|
AddEventHandler('onResourceStart', function(resourceName)
|
||||||
|
if resourceName == 'qb-target' or resourceName == GetCurrentResourceName() then
|
||||||
|
Wait(1000)
|
||||||
|
InitializeTargets()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Command to manually refresh targets
|
||||||
|
RegisterCommand('refreshvendingtargets', function()
|
||||||
|
InitializeTargets()
|
||||||
|
QBCore.Functions.Notify('Vending machine targets refreshed', 'success')
|
||||||
|
end, false)
|
||||||
|
|
||||||
-- Check if machine is registered
|
-- Check if machine is registered
|
||||||
function isRegisteredMachine(entity)
|
function isRegisteredMachine(entity)
|
||||||
local coords = GetEntityCoords(entity)
|
local coords = GetEntityCoords(entity)
|
||||||
|
@ -582,8 +626,7 @@ end)
|
||||||
|
|
||||||
-- Refresh targets (called when new machine is registered)
|
-- Refresh targets (called when new machine is registered)
|
||||||
RegisterNetEvent('vending:client:refreshTargets', function()
|
RegisterNetEvent('vending:client:refreshTargets', function()
|
||||||
-- Targets are automatically updated by qb-target
|
InitializeTargets()
|
||||||
-- This event can be used for additional refresh logic if needed
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Management menu (alternative opening method)
|
-- Management menu (alternative opening method)
|
||||||
|
@ -614,22 +657,6 @@ RegisterNetEvent('vending:client:openManagement', function(machine)
|
||||||
lib.showContext('vending_management')
|
lib.showContext('vending_management')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Debug commands
|
|
||||||
RegisterCommand('vendingdebug', function()
|
|
||||||
local playerPed = PlayerPedId()
|
|
||||||
local coords = GetEntityCoords(playerPed)
|
|
||||||
|
|
||||||
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')
|
|
||||||
end
|
|
||||||
end, coords)
|
|
||||||
end, false)
|
|
||||||
|
|
||||||
-- Debug command to check props
|
-- Debug command to check props
|
||||||
RegisterCommand('checkvendingprops', function()
|
RegisterCommand('checkvendingprops', function()
|
||||||
local playerPed = PlayerPedId()
|
local playerPed = PlayerPedId()
|
||||||
|
@ -672,40 +699,18 @@ RegisterCommand('checkvendingprops', function()
|
||||||
QBCore.Functions.Notify('Found ' .. foundProps .. ' vending machines nearby', 'primary')
|
QBCore.Functions.Notify('Found ' .. foundProps .. ' vending machines nearby', 'primary')
|
||||||
end, false)
|
end, false)
|
||||||
|
|
||||||
-- Command to manually refresh targets
|
-- Debug commands
|
||||||
RegisterCommand('refreshvendingtargets', function()
|
RegisterCommand('vendingdebug', function()
|
||||||
exports['qb-target']:RemoveTargetModel(Config.VendingProps)
|
local playerPed = PlayerPedId()
|
||||||
Wait(500)
|
local coords = GetEntityCoords(playerPed)
|
||||||
|
|
||||||
exports['qb-target']:AddTargetModel(Config.VendingProps, {
|
QBCore.Functions.TriggerCallback('vending:server:getMachineByCoords', function(machine)
|
||||||
options = {
|
if machine then
|
||||||
{
|
print('Machine found:', json.encode(machine))
|
||||||
type = "client",
|
QBCore.Functions.Notify('Machine data logged to console', 'primary')
|
||||||
event = "vending:client:buyMachine",
|
else
|
||||||
icon = "fas fa-dollar-sign",
|
print('No machine found at current location')
|
||||||
label = "Automaten kaufen ($" .. Config.VendingMachinePrice .. ")"
|
QBCore.Functions.Notify('No machine found here', 'error')
|
||||||
},
|
end
|
||||||
{
|
end, coords)
|
||||||
type = "client",
|
|
||||||
event = "vending:client:openBuyMenu",
|
|
||||||
icon = "fas fa-shopping-cart",
|
|
||||||
label = "Kaufen"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "client",
|
|
||||||
event = "vending:client:openOwnerMenu",
|
|
||||||
icon = "fas fa-cog",
|
|
||||||
label = "Verwalten"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "client",
|
|
||||||
event = "vending:client:startRobbery",
|
|
||||||
icon = "fas fa-mask",
|
|
||||||
label = "Aufbrechen"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
distance = 2.0
|
|
||||||
})
|
|
||||||
|
|
||||||
QBCore.Functions.Notify('Vending machine targets refreshed', 'success')
|
|
||||||
end, false)
|
end, false)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue