1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-07 13:02:53 +02:00
parent 8a9036936a
commit f64ba04bac
2 changed files with 214 additions and 290 deletions

View file

@ -387,6 +387,116 @@ RegisterCommand('clearvehicles', function(source, args, rawCommand)
end
end, true)
-- Check if a player owns a vehicle
RegisterNetEvent('antidespawn:server:checkVehicleOwnership', function(plate)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ? AND citizenid = ?', {plate, Player.PlayerData.citizenid}, function(result)
local isOwned = result and #result > 0
TriggerClientEvent('antidespawn:client:vehicleOwnershipResult', src, isOwned, plate)
end)
end)
-- Modified registerVehicle function to verify ownership
RegisterNetEvent('antidespawn:server:registerVehicle', function(plate, model, coords, heading, mods)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
-- Verify ownership before registering
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ? AND citizenid = ?', {plate, Player.PlayerData.citizenid}, function(result)
if not result or #result == 0 then
Debug("Player does not own vehicle: " .. plate)
return
end
-- Check if vehicle is in garage
if result[1].state == 1 then
Debug("Fahrzeug ist in der Garage, nicht registrieren: " .. plate)
-- Remove from Anti-Despawn database if present
if vehicles[plate] then
vehicles[plate] = nil
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {plate})
Debug("Fahrzeug aus Anti-Despawn entfernt: " .. plate)
end
return
end
-- Continue with registration as before
vehicles[plate] = {
model = model,
coords = coords,
heading = heading,
fuel = 100,
mods = mods,
last_updated = os.time()
}
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,
tostring(model),
json.encode(coords),
heading,
100,
json.encode(mods)
})
Debug("Fahrzeug registriert: " .. plate .. " (Modell: " .. tostring(model) .. ")")
end)
end)
-- Also modify respawnVehicle to verify ownership
RegisterNetEvent('antidespawn:server:respawnVehicle', function(plate)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
-- Verify ownership before respawning
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ? AND citizenid = ?', {plate, Player.PlayerData.citizenid}, function(result)
if not result or #result == 0 then
Debug("Player does not own vehicle: " .. plate)
return
end
if not vehicles[plate] then
Debug("Fahrzeug nicht in Datenbank: " .. plate)
return
end
-- Check if vehicle is in garage
if result[1].state == 1 then
Debug("Fahrzeug ist in der Garage, nicht respawnen: " .. plate)
-- Remove from Anti-Despawn database
vehicles[plate] = nil
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {plate})
return
end
-- Send spawn event back to client
TriggerClientEvent('antidespawn:client:spawnVehicle', src, {
plate = plate,
model = vehicles[plate].model,
coords = vehicles[plate].coords,
heading = vehicles[plate].heading,
fuel = vehicles[plate].fuel,
mods = vehicles[plate].mods
})
Debug("Fahrzeug Respawn angefordert: " .. plate)
end)
end)
-- Befehl zum Leeren der Datenbank
RegisterCommand('clearalldespawn', function(source, args, rawCommand)
if source == 0 then -- Nur über Konsole ausführbar