This commit is contained in:
Nordi98 2025-08-06 18:50:02 +02:00
parent 9520ad1b07
commit 0be79cdd60
2 changed files with 321 additions and 66 deletions

View file

@ -18,6 +18,7 @@ CreateThread(function()
`coords` longtext NOT NULL,
`heading` float NOT NULL,
`fuel` int(11) DEFAULT 100,
`mods` longtext DEFAULT NULL,
`last_updated` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `plate` (`plate`)
@ -37,6 +38,7 @@ CreateThread(function()
coords = json.decode(vehicle.coords),
heading = vehicle.heading,
fuel = vehicle.fuel,
mods = json.decode(vehicle.mods),
last_updated = vehicle.last_updated
}
end
@ -45,7 +47,7 @@ CreateThread(function()
end)
-- Registriere ein Fahrzeug
RegisterNetEvent('antidespawn:server:registerVehicle', function(plate, model, coords, heading)
RegisterNetEvent('antidespawn:server:registerVehicle', function(plate, model, coords, heading, mods)
local src = source
if not plate or not model or not coords then
@ -65,15 +67,17 @@ RegisterNetEvent('antidespawn:server:registerVehicle', function(plate, model, co
coords = coords,
heading = heading,
fuel = 100,
mods = mods,
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", {
MySQL.query("INSERT INTO vehicle_antidespawn (plate, model, coords, heading, fuel, mods) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE coords = VALUES(coords), heading = VALUES(heading), mods = VALUES(mods), last_updated = CURRENT_TIMESTAMP", {
plate,
model,
json.encode(coords),
heading,
100
100,
json.encode(mods)
})
Debug("Fahrzeug registriert: " .. plate)
@ -81,7 +85,7 @@ RegisterNetEvent('antidespawn:server:registerVehicle', function(plate, model, co
end)
-- Aktualisiere ein Fahrzeug
RegisterNetEvent('antidespawn:server:updateVehicle', function(plate, coords, heading)
RegisterNetEvent('antidespawn:server:updateVehicle', function(plate, coords, heading, mods)
if not vehicles[plate] then return end
-- Prüfe ob Fahrzeug in der Garage ist
@ -98,11 +102,13 @@ RegisterNetEvent('antidespawn:server:updateVehicle', function(plate, coords, hea
vehicles[plate].coords = coords
vehicles[plate].heading = heading
vehicles[plate].mods = mods
vehicles[plate].last_updated = os.time()
MySQL.query("UPDATE vehicle_antidespawn SET coords = ?, heading = ?, last_updated = CURRENT_TIMESTAMP WHERE plate = ?", {
MySQL.query("UPDATE vehicle_antidespawn SET coords = ?, heading = ?, mods = ?, last_updated = CURRENT_TIMESTAMP WHERE plate = ?", {
json.encode(coords),
heading,
json.encode(mods),
plate
})
@ -110,19 +116,6 @@ RegisterNetEvent('antidespawn:server:updateVehicle', function(plate, coords, hea
end)
end)
-- Entferne ein Fahrzeug
RegisterNetEvent('antidespawn:server:removeVehicle', function(plate)
if not vehicles[plate] then return end
vehicles[plate] = nil
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {
plate
})
Debug("Fahrzeug entfernt: " .. plate)
end)
-- Respawn ein Fahrzeug
RegisterNetEvent('antidespawn:server:respawnVehicle', function(plate)
local src = source
@ -152,7 +145,8 @@ RegisterNetEvent('antidespawn:server:respawnVehicle', function(plate)
model = vehicles[plate].model,
coords = vehicles[plate].coords,
heading = vehicles[plate].heading,
fuel = vehicles[plate].fuel
fuel = vehicles[plate].fuel,
mods = vehicles[plate].mods
})
Debug("Fahrzeug Respawn angefordert: " .. plate)
@ -192,7 +186,8 @@ RegisterNetEvent('antidespawn:server:loadVehicles', function()
model = vehicle.model,
coords = vehicle.coords,
heading = vehicle.heading,
fuel = vehicle.fuel
fuel = vehicle.fuel,
mods = vehicle.mods
})
Debug("Fahrzeug für Spieler geladen: " .. plate)
@ -201,6 +196,7 @@ RegisterNetEvent('antidespawn:server:loadVehicles', function()
end
end)
-- Cleanup alte Einträge (älter als 24 Stunden)
CreateThread(function()
while true do