forked from Simnation/Main
ed
This commit is contained in:
parent
f89add3449
commit
9520ad1b07
2 changed files with 284 additions and 63 deletions
|
@ -53,40 +53,61 @@ RegisterNetEvent('antidespawn:server:registerVehicle', function(plate, model, co
|
|||
return
|
||||
end
|
||||
|
||||
vehicles[plate] = {
|
||||
model = model,
|
||||
coords = coords,
|
||||
heading = heading,
|
||||
fuel = 100,
|
||||
last_updated = os.time()
|
||||
}
|
||||
|
||||
MySQL.query("INSERT INTO vehicle_antidespawn (plate, model, coords, heading, fuel) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE coords = VALUES(coords), heading = VALUES(heading), last_updated = CURRENT_TIMESTAMP", {
|
||||
plate,
|
||||
model,
|
||||
json.encode(coords),
|
||||
heading,
|
||||
100
|
||||
})
|
||||
|
||||
Debug("Fahrzeug registriert: " .. plate)
|
||||
-- Prüfe ob Fahrzeug in der Garage ist
|
||||
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ? AND state = ?', {plate, 1}, function(result)
|
||||
if result and #result > 0 then
|
||||
Debug("Fahrzeug ist in der Garage, nicht registrieren: " .. plate)
|
||||
return
|
||||
end
|
||||
|
||||
vehicles[plate] = {
|
||||
model = model,
|
||||
coords = coords,
|
||||
heading = heading,
|
||||
fuel = 100,
|
||||
last_updated = os.time()
|
||||
}
|
||||
|
||||
MySQL.query("INSERT INTO vehicle_antidespawn (plate, model, coords, heading, fuel) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE coords = VALUES(coords), heading = VALUES(heading), last_updated = CURRENT_TIMESTAMP", {
|
||||
plate,
|
||||
model,
|
||||
json.encode(coords),
|
||||
heading,
|
||||
100
|
||||
})
|
||||
|
||||
Debug("Fahrzeug registriert: " .. plate)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Aktualisiere ein Fahrzeug
|
||||
RegisterNetEvent('antidespawn:server:updateVehicle', function(plate, coords, heading)
|
||||
if not vehicles[plate] then return end
|
||||
|
||||
vehicles[plate].coords = coords
|
||||
vehicles[plate].heading = heading
|
||||
vehicles[plate].last_updated = os.time()
|
||||
|
||||
MySQL.query("UPDATE vehicle_antidespawn SET coords = ?, heading = ?, last_updated = CURRENT_TIMESTAMP WHERE plate = ?", {
|
||||
json.encode(coords),
|
||||
heading,
|
||||
plate
|
||||
})
|
||||
|
||||
Debug("Fahrzeug aktualisiert: " .. plate)
|
||||
-- Prüfe ob Fahrzeug in der Garage ist
|
||||
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ? AND state = ?', {plate, 1}, function(result)
|
||||
if result and #result > 0 then
|
||||
Debug("Fahrzeug ist in der Garage, entferne aus Tracking: " .. plate)
|
||||
vehicles[plate] = nil
|
||||
|
||||
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {
|
||||
plate
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
vehicles[plate].coords = coords
|
||||
vehicles[plate].heading = heading
|
||||
vehicles[plate].last_updated = os.time()
|
||||
|
||||
MySQL.query("UPDATE vehicle_antidespawn SET coords = ?, heading = ?, last_updated = CURRENT_TIMESTAMP WHERE plate = ?", {
|
||||
json.encode(coords),
|
||||
heading,
|
||||
plate
|
||||
})
|
||||
|
||||
Debug("Fahrzeug aktualisiert: " .. plate)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Entferne ein Fahrzeug
|
||||
|
@ -102,6 +123,42 @@ RegisterNetEvent('antidespawn:server:removeVehicle', function(plate)
|
|||
Debug("Fahrzeug entfernt: " .. plate)
|
||||
end)
|
||||
|
||||
-- Respawn ein Fahrzeug
|
||||
RegisterNetEvent('antidespawn:server:respawnVehicle', function(plate)
|
||||
local src = source
|
||||
|
||||
if not vehicles[plate] then
|
||||
Debug("Fahrzeug nicht in Datenbank: " .. plate)
|
||||
return
|
||||
end
|
||||
|
||||
-- Prüfe ob Fahrzeug in der Garage ist
|
||||
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ? AND state = ?', {plate, 1}, function(result)
|
||||
if result and #result > 0 then
|
||||
Debug("Fahrzeug ist in der Garage, nicht respawnen: " .. plate)
|
||||
|
||||
-- Entferne aus Anti-Despawn Datenbank
|
||||
vehicles[plate] = nil
|
||||
|
||||
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {
|
||||
plate
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
-- Sende Spawn-Event zurück an den Client
|
||||
TriggerClientEvent('antidespawn:client:spawnVehicle', src, {
|
||||
plate = plate,
|
||||
model = vehicles[plate].model,
|
||||
coords = vehicles[plate].coords,
|
||||
heading = vehicles[plate].heading,
|
||||
fuel = vehicles[plate].fuel
|
||||
})
|
||||
|
||||
Debug("Fahrzeug Respawn angefordert: " .. plate)
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Lade Fahrzeuge für einen Spieler
|
||||
RegisterNetEvent('antidespawn:server:loadVehicles', function()
|
||||
local src = source
|
||||
|
@ -111,21 +168,36 @@ RegisterNetEvent('antidespawn:server:loadVehicles', function()
|
|||
|
||||
local playerCoords = GetEntityCoords(GetPlayerPed(src))
|
||||
|
||||
-- Lade nur Fahrzeuge in der Nähe des Spielers
|
||||
-- Prüfe für jedes Fahrzeug, ob es in der Garage ist
|
||||
for plate, vehicle in pairs(vehicles) do
|
||||
local distance = #(playerCoords - vector3(vehicle.coords.x, vehicle.coords.y, vehicle.coords.z))
|
||||
|
||||
if distance < 100.0 then
|
||||
TriggerClientEvent('antidespawn:client:spawnVehicle', src, {
|
||||
plate = plate,
|
||||
model = vehicle.model,
|
||||
coords = vehicle.coords,
|
||||
heading = vehicle.heading,
|
||||
fuel = vehicle.fuel
|
||||
})
|
||||
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ? AND state = ?', {plate, 1}, function(result)
|
||||
if result and #result > 0 then
|
||||
Debug("Fahrzeug ist in der Garage, nicht laden: " .. plate)
|
||||
|
||||
-- Entferne aus Anti-Despawn Datenbank
|
||||
vehicles[plate] = nil
|
||||
|
||||
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {
|
||||
plate
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
Debug("Fahrzeug für Spieler geladen: " .. plate)
|
||||
end
|
||||
-- Lade nur Fahrzeuge in der Nähe des Spielers
|
||||
local distance = #(playerCoords - vector3(vehicle.coords.x, vehicle.coords.y, vehicle.coords.z))
|
||||
|
||||
if distance < 100.0 then
|
||||
TriggerClientEvent('antidespawn:client:spawnVehicle', src, {
|
||||
plate = plate,
|
||||
model = vehicle.model,
|
||||
coords = vehicle.coords,
|
||||
heading = vehicle.heading,
|
||||
fuel = vehicle.fuel
|
||||
})
|
||||
|
||||
Debug("Fahrzeug für Spieler geladen: " .. plate)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -137,3 +209,38 @@ CreateThread(function()
|
|||
Debug("Alte Fahrzeugeinträge bereinigt")
|
||||
end
|
||||
end)
|
||||
|
||||
-- Registriere jg-advancedgarages Events
|
||||
RegisterNetEvent('jg-advancedgarages:server:vehicle-stored', function(data)
|
||||
if data and data.plate then
|
||||
Debug("Fahrzeug in Garage gespeichert: " .. data.plate)
|
||||
|
||||
-- Entferne aus Anti-Despawn Datenbank
|
||||
if vehicles[data.plate] then
|
||||
vehicles[data.plate] = nil
|
||||
|
||||
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {
|
||||
data.plate
|
||||
})
|
||||
|
||||
Debug("Fahrzeug aus Anti-Despawn entfernt: " .. data.plate)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('jg-advancedgarages:server:vehicle-spawned', function(data)
|
||||
if data and data.plate then
|
||||
Debug("Fahrzeug aus Garage gespawnt: " .. data.plate)
|
||||
|
||||
-- Entferne aus Anti-Despawn Datenbank, da es jetzt von der Garage verwaltet wird
|
||||
if vehicles[data.plate] then
|
||||
vehicles[data.plate] = nil
|
||||
|
||||
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {
|
||||
data.plate
|
||||
})
|
||||
|
||||
Debug("Fahrzeug aus Anti-Despawn entfernt: " .. data.plate)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue