Citizen.CreateThread(function()
Citizen.Wait(3000)
local isInVehicle = false
local currentVehiclePlate = nil
local wasDead = false
while (true) do
Citizen.Wait(50)
local playerPed = PlayerPedId()
if (not isInVehicle and IsPedInAnyVehicle(playerPed)) then
-- entered vehicle
isInVehicle = true
if (enabled) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
if (NetworkGetEntityIsNetworked(vehicle) and not IsVehicleBlacklisted(vehicle)) then
local networkId = NetworkGetNetworkIdFromEntity(vehicle)
SetNetworkIdCanMigrate(netId, true)
local modifications = GetVehicleModifications(vehicle)
currentVehiclePlate = GetVehicleNumberPlateText(vehicle)
TriggerServerEvent("AdvancedParking:enteredVehicle", networkId, modifications)
Log("Vehicle " .. currentVehiclePlate .. " entered")
end
end
elseif (isInVehicle and not IsPedInAnyVehicle(playerPed, false)) then
-- left vehicle
isInVehicle = false
if (enabled and not wasDead) then
local vehicle = GetVehiclePedIsIn(playerPed, true)
if (vehicle ~= 0) then
if (NetworkGetEntityIsNetworked(vehicle) and not IsVehicleBlacklisted(vehicle)) then
local networkId = NetworkGetNetworkIdFromEntity(vehicle)
SetNetworkIdCanMigrate(netId, true)
local modifications = GetVehicleModifications(vehicle)
TriggerServerEvent("AdvancedParking:leftVehicle", networkId, modifications)
Log("Vehicle " .. GetVehicleNumberPlateText(vehicle) .. " left")
-- if vehicle is deleted soon after
Citizen.CreateThread(function()
local veh = vehicle
local plate = GetVehicleNumberPlateText(veh)
local startTime = GetGameTimer()
local playerPed = PlayerPedId()
local playerPos
while (true) do
Citizen.Wait(0)
if (GetGameTimer() - startTime >= 1000) then
break
end
if (not DoesEntityExist(veh)) then
TriggerServerEvent("AdvancedParking:deleteVehicle", plate, false)
Log("Vehicle " .. currentVehiclePlate .. " left and deleted after exit")
currentVehiclePlate = nil
break
end
playerPed = PlayerPedId()
playerPos = GetEntityCoords(playerPed)
vehPos = GetEntityCoords(veh)
if (Vdist(playerPos.x, playerPos.y, playerPos.z, vehPos.x, vehPos.y, vehPos.z) > 50.0) then
currentVehiclePlate = nil
break
end
end
currentVehiclePlate = nil
end)
end
elseif (currentVehiclePlate) then
TriggerServerEvent("AdvancedParking:deleteVehicle", currentVehiclePlate, false)
Log("Vehicle " .. currentVehiclePlate .. " left and deleted")
currentVehiclePlate = nil
end
end
end
if (not wasDead and IsPlayerDead(PlayerId())) then
wasDead = true
elseif (wasDead and not IsPlayerDead(PlayerId())) then
Citizen.CreateThread(function()
Citizen.Wait(1000)
wasDead = false
end)
end
end
end)