forked from Simnation/Main
ed
This commit is contained in:
parent
0be79cdd60
commit
cf533de903
2 changed files with 84 additions and 4 deletions
|
@ -55,6 +55,11 @@ RegisterNetEvent('antidespawn:server:registerVehicle', function(plate, model, co
|
|||
return
|
||||
end
|
||||
|
||||
-- Stelle sicher, dass das Modell als Zahl gespeichert wird
|
||||
if type(model) == "string" then
|
||||
model = tonumber(model) or model
|
||||
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
|
||||
|
@ -73,17 +78,18 @@ RegisterNetEvent('antidespawn:server:registerVehicle', function(plate, model, co
|
|||
|
||||
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,
|
||||
tostring(model), -- Speichere als String in der Datenbank
|
||||
json.encode(coords),
|
||||
heading,
|
||||
100,
|
||||
json.encode(mods)
|
||||
})
|
||||
|
||||
Debug("Fahrzeug registriert: " .. plate)
|
||||
Debug("Fahrzeug registriert: " .. plate .. " (Modell: " .. tostring(model) .. ")")
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
-- Aktualisiere ein Fahrzeug
|
||||
RegisterNetEvent('antidespawn:server:updateVehicle', function(plate, coords, heading, mods)
|
||||
if not vehicles[plate] then return end
|
||||
|
@ -240,3 +246,25 @@ RegisterNetEvent('jg-advancedgarages:server:vehicle-spawned', function(data)
|
|||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Befehl zum Bereinigen der Datenbank
|
||||
RegisterCommand('clearvehicles', function(source, args, rawCommand)
|
||||
if source == 0 then -- Nur über Konsole ausführbar
|
||||
local count = 0
|
||||
|
||||
for plate, vehicle in pairs(vehicles) do
|
||||
local model = vehicle.model
|
||||
|
||||
-- Prüfe ob das Modell gültig ist
|
||||
if type(model) == "string" and not tonumber(model) then
|
||||
-- Ungültiges Modell, entferne aus Datenbank
|
||||
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {plate})
|
||||
vehicles[plate] = nil
|
||||
count = count + 1
|
||||
Debug("Ungültiges Modell entfernt: " .. plate .. " (Modell: " .. tostring(model) .. ")")
|
||||
end
|
||||
end
|
||||
|
||||
Debug("Bereinigung abgeschlossen. " .. count .. " Fahrzeuge entfernt.")
|
||||
end
|
||||
end, true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue