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
|
||||
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 dist < 2.0 then
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Hier ist bereits ein Automat registriert!', 'error')
|
||||
return
|
||||
if machine.coords and machine.coords.x and machine.coords.y and machine.coords.z then
|
||||
local dist = #(vector3(coords.x, coords.y, coords.z) - vector3(machine.coords.x, machine.coords.y, machine.coords.z))
|
||||
if dist < 2.0 then
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Hier ist bereits ein Automat registriert!', 'error')
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -210,6 +212,7 @@ RegisterNetEvent('vending:server:openStash', function(coords)
|
|||
label = 'Vending Machine #' .. machine.id
|
||||
})
|
||||
end)
|
||||
|
||||
-- Set item price
|
||||
RegisterNetEvent('vending:server:setItemPrice', function(coords, itemName, price)
|
||||
local src = source
|
||||
|
@ -517,14 +520,13 @@ RegisterNetEvent('vending:server:startRobbery', function(coords)
|
|||
|
||||
robberyInProgress[machineId] = true
|
||||
|
||||
-- Alert police
|
||||
local streetHash = GetStreetNameAtCoord(coords.x, coords.y, coords.z)
|
||||
local streetName = GetStreetNameFromHashKey(streetHash)
|
||||
-- Alert police - use a generic location name instead of street name
|
||||
local locationName = "Verkaufsautomat #" .. machineId
|
||||
|
||||
local players = QBCore.Functions.GetQBPlayers()
|
||||
for k, v in pairs(players) do
|
||||
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
|
||||
|
||||
|
@ -533,11 +535,11 @@ RegisterNetEvent('vending:server:startRobbery', function(coords)
|
|||
local targetPlayer = QBCore.Functions.GetPlayer(playerId)
|
||||
if targetPlayer 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
|
||||
for _, manager in pairs(machine.managers) do
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -584,10 +586,22 @@ end)
|
|||
|
||||
-- Helper function to get machine ID by coordinates
|
||||
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
|
||||
local dist = #(vector3(coords.x, coords.y, coords.z) - vector3(machine.coords.x, machine.coords.y, machine.coords.z))
|
||||
if dist < 2.0 then
|
||||
return id
|
||||
-- Ensure machine coords are properly formatted
|
||||
if machine.coords and machine.coords.x and machine.coords.y and machine.coords.z then
|
||||
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
|
||||
return nil
|
||||
|
@ -747,4 +761,3 @@ QBCore.Functions.CreateCallback('vending:server:getMachineStatus', function(sour
|
|||
|
||||
cb({exists = true, canManage = canManage})
|
||||
end)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue