1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-07 14:00:58 +02:00
parent 187f3ee8ff
commit 07aee0f73e
2 changed files with 377 additions and 120 deletions

View file

@ -77,6 +77,22 @@ CreateThread(function()
end)
end)
-- Check if a vehicle exists in the database
RegisterNetEvent('antidespawn:server:checkVehicleExists', function(plate)
local src = source
-- Skip vehicles with empty or invalid plates
if not plate or plate == "" or string.len(plate) < 2 then
TriggerClientEvent('antidespawn:client:vehicleExistsResult', src, false, plate)
return
end
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ?', {plate}, function(result)
local exists = result and #result > 0
TriggerClientEvent('antidespawn:client:vehicleExistsResult', src, exists, plate)
end)
end)
-- Check if a player owns a vehicle
RegisterNetEvent('antidespawn:server:checkVehicleOwnership', function(plate)
local src = source
@ -87,6 +103,12 @@ RegisterNetEvent('antidespawn:server:checkVehicleOwnership', function(plate)
return
end
-- Skip vehicles with empty or invalid plates
if not plate or plate == "" or string.len(plate) < 2 then
TriggerClientEvent('antidespawn:client:vehicleOwnershipResult', src, false, plate)
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)
@ -100,6 +122,12 @@ RegisterNetEvent('antidespawn:server:registerVehicle', function(plate, model, co
if not Player then return end
-- Skip vehicles with empty or invalid plates
if not plate or plate == "" or string.len(plate) < 2 then
Debug("Skipping vehicle with invalid plate")
return
end
-- Check if vehicle exists in player_vehicles (any player)
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ?', {plate}, function(result)
if not result or #result == 0 then
@ -163,10 +191,19 @@ RegisterNetEvent('antidespawn:server:updateVehicle', function(plate, coords, hea
if not Player then return end
if not vehicles[plate] then return end
-- Skip vehicles with empty or invalid plates
if not plate or plate == "" or string.len(plate) < 2 then
Debug("Skipping update for vehicle with invalid plate")
return
end
-- Check if vehicle exists in player_vehicles (any player)
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ?', {plate}, function(result)
if not result or #result == 0 then
Debug("Vehicle not found in database: " .. plate)
-- Remove from tracking as it no longer exists in the database
vehicles[plate] = nil
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {plate})
return
end
@ -210,6 +247,12 @@ RegisterNetEvent('antidespawn:server:removeVehicle', function(plate)
local src = source
if not vehicles[plate] then return end
-- Skip vehicles with empty or invalid plates
if not plate or plate == "" or string.len(plate) < 2 then
Debug("Skipping removal for vehicle with invalid plate")
return
end
vehicles[plate] = nil
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {
@ -226,6 +269,12 @@ RegisterNetEvent('antidespawn:server:respawnVehicle', function(plate)
if not Player then return end
-- Skip vehicles with empty or invalid plates
if not plate or plate == "" or string.len(plate) < 2 then
Debug("Skipping respawn for vehicle with invalid plate")
return
end
-- Anti-Duplication: Check if there's already an active spawn request for this plate
if activeSpawns[plate] then
Debug("Anti-Dupe: Already processing spawn request for: " .. plate)
@ -305,6 +354,14 @@ RegisterNetEvent('antidespawn:server:loadVehicles', function()
-- Load all vehicles in the database, not just owned ones
for plate, vehicle in pairs(vehicles) do
-- Skip vehicles with empty or invalid plates
if not plate or plate == "" or string.len(plate) < 2 then
Debug("Skipping load for vehicle with invalid plate")
vehicles[plate] = nil
MySQL.query("DELETE FROM vehicle_antidespawn WHERE plate = ?", {plate})
goto continue
end
-- Check if vehicle is in garage by querying the database
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ?', {plate}, function(result)
if not result or #result == 0 then
@ -354,6 +411,7 @@ RegisterNetEvent('antidespawn:server:loadVehicles', function()
loadedCount = loadedCount + 1
end
end)
::continue::
end
-- Warte kurz und lade dann die Fahrzeuge
@ -379,6 +437,7 @@ RegisterNetEvent('antidespawn:server:loadVehicles', function()
end)
end)
-- Cleanup alte Einträge (älter als 24 Stunden)
CreateThread(function()
while true do
@ -511,6 +570,24 @@ RegisterCommand('activespawns', function(source, args, rawCommand)
end
end, true)
-- Check if a vehicle exists in the database
RegisterNetEvent('antidespawn:server:checkVehicleExists', function(plate, callback)
local src = source
MySQL.query('SELECT * FROM player_vehicles WHERE plate = ?', {plate}, function(result)
local exists = result and #result > 0
TriggerClientEvent('antidespawn:client:vehicleExistsResult', src, exists, plate)
end)
end)
-- Client callback for vehicle existence check
RegisterNetEvent('antidespawn:client:vehicleExistsResult', function(exists, plate)
-- This event will be handled by the callback system
end)
-- Clean up when resource stops
AddEventHandler('onResourceStop', function(resourceName)
if resourceName == GetCurrentResourceName() then