forked from Simnation/Main
Update server.lua
This commit is contained in:
parent
64fecd2fa0
commit
2c063aa102
1 changed files with 27 additions and 14 deletions
|
@ -32,10 +32,12 @@ RegisterNetEvent('vending:server:registerMachine', function(coords, prop)
|
||||||
|
|
||||||
-- Check if there's already a machine at these coords
|
-- Check if there's already a machine at these coords
|
||||||
for id, machine in pairs(vendingMachines) do
|
for id, machine in pairs(vendingMachines) do
|
||||||
local dist = #(vector3(coords.x, coords.y, coords.z) - vector3(machine.coords.x, machine.coords.y, machine.coords.z))
|
if machine.coords and machine.coords.x and machine.coords.y and machine.coords.z then
|
||||||
if dist < 2.0 then
|
local dist = #(vector3(coords.x, coords.y, coords.z) - vector3(machine.coords.x, machine.coords.y, machine.coords.z))
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Hier ist bereits ein Automat registriert!', 'error')
|
if dist < 2.0 then
|
||||||
return
|
TriggerClientEvent('QBCore:Notify', src, 'Hier ist bereits ein Automat registriert!', 'error')
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -210,6 +212,7 @@ RegisterNetEvent('vending:server:openStash', function(coords)
|
||||||
label = 'Vending Machine #' .. machine.id
|
label = 'Vending Machine #' .. machine.id
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Set item price
|
-- Set item price
|
||||||
RegisterNetEvent('vending:server:setItemPrice', function(coords, itemName, price)
|
RegisterNetEvent('vending:server:setItemPrice', function(coords, itemName, price)
|
||||||
local src = source
|
local src = source
|
||||||
|
@ -517,14 +520,13 @@ RegisterNetEvent('vending:server:startRobbery', function(coords)
|
||||||
|
|
||||||
robberyInProgress[machineId] = true
|
robberyInProgress[machineId] = true
|
||||||
|
|
||||||
-- Alert police
|
-- Alert police - use a generic location name instead of street name
|
||||||
local streetHash = GetStreetNameAtCoord(coords.x, coords.y, coords.z)
|
local locationName = "Verkaufsautomat #" .. machineId
|
||||||
local streetName = GetStreetNameFromHashKey(streetHash)
|
|
||||||
|
|
||||||
local players = QBCore.Functions.GetQBPlayers()
|
local players = QBCore.Functions.GetQBPlayers()
|
||||||
for k, v in pairs(players) do
|
for k, v in pairs(players) do
|
||||||
if v.PlayerData.job.name == 'police' and v.PlayerData.job.onduty then
|
if v.PlayerData.job.name == 'police' and v.PlayerData.job.onduty then
|
||||||
TriggerClientEvent('vending:client:policeAlert', v.PlayerData.source, coords, streetName)
|
TriggerClientEvent('vending:client:policeAlert', v.PlayerData.source, coords, locationName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -533,11 +535,11 @@ RegisterNetEvent('vending:server:startRobbery', function(coords)
|
||||||
local targetPlayer = QBCore.Functions.GetPlayer(playerId)
|
local targetPlayer = QBCore.Functions.GetPlayer(playerId)
|
||||||
if targetPlayer then
|
if targetPlayer then
|
||||||
if targetPlayer.PlayerData.citizenid == machine.owner then
|
if targetPlayer.PlayerData.citizenid == machine.owner then
|
||||||
TriggerClientEvent('QBCore:Notify', targetPlayer.PlayerData.source, 'Dein Verkaufsautomat wird gerade aufgebrochen! Standort: ' .. streetName, 'error', 10000)
|
TriggerClientEvent('QBCore:Notify', targetPlayer.PlayerData.source, 'Dein Verkaufsautomat wird gerade aufgebrochen! Standort: ' .. locationName, 'error', 10000)
|
||||||
elseif machine.managers then
|
elseif machine.managers then
|
||||||
for _, manager in pairs(machine.managers) do
|
for _, manager in pairs(machine.managers) do
|
||||||
if targetPlayer.PlayerData.citizenid == manager then
|
if targetPlayer.PlayerData.citizenid == manager then
|
||||||
TriggerClientEvent('QBCore:Notify', targetPlayer.PlayerData.source, 'Ein Verkaufsautomat, den du verwaltest, wird gerade aufgebrochen! Standort: ' .. streetName, 'error', 10000)
|
TriggerClientEvent('QBCore:Notify', targetPlayer.PlayerData.source, 'Ein Verkaufsautomat, den du verwaltest, wird gerade aufgebrochen! Standort: ' .. locationName, 'error', 10000)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -584,10 +586,22 @@ end)
|
||||||
|
|
||||||
-- Helper function to get machine ID by coordinates
|
-- Helper function to get machine ID by coordinates
|
||||||
function getMachineIdByCoords(coords)
|
function getMachineIdByCoords(coords)
|
||||||
|
-- Ensure coords is properly formatted
|
||||||
|
local x, y, z
|
||||||
|
if coords and coords.x ~= nil and coords.y ~= nil and coords.z ~= nil then
|
||||||
|
x, y, z = coords.x, coords.y, coords.z
|
||||||
|
else
|
||||||
|
-- Handle case where coords might be a table without x,y,z properties
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
for id, machine in pairs(vendingMachines) do
|
for id, machine in pairs(vendingMachines) do
|
||||||
local dist = #(vector3(coords.x, coords.y, coords.z) - vector3(machine.coords.x, machine.coords.y, machine.coords.z))
|
-- Ensure machine coords are properly formatted
|
||||||
if dist < 2.0 then
|
if machine.coords and machine.coords.x and machine.coords.y and machine.coords.z then
|
||||||
return id
|
local dist = #(vector3(x, y, z) - vector3(machine.coords.x, machine.coords.y, machine.coords.z))
|
||||||
|
if dist < 2.0 then
|
||||||
|
return id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
|
@ -747,4 +761,3 @@ QBCore.Functions.CreateCallback('vending:server:getMachineStatus', function(sour
|
||||||
|
|
||||||
cb({exists = true, canManage = canManage})
|
cb({exists = true, canManage = canManage})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue