Hello everyone!
This is really a very good script, thank you very much for this script, I have read through your comments and I found that there are a lot of errors, most of them spaw car errors.
After a period of tinkering and testing I can give you the following solutions, not necessarily the best, or the most optimal, but it worked for me.
- In the file config.lua:
Add an array of parking point coordinates to each parking lot, for example parking lot 1:
parking1 = {
x = -304.93497, -- Central location X, Y, Z of the parking
y = -944.39764, -- Y
z = 30.08062, -- Z
size = 83.0, -- The parking range radius (Horizontal)
height = 10.0, -- The parking range radius (Vertical)
name = "Public Parking", -- The name of the parking (blips)
fee = 1000, -- How much parking fee per day (Real life time), set 0 to disable
enter = {x = -279.25, y = -890.39, z = 30.08}, -- The entrance of the parking
maxcar = 100,
ParkingPoint = {
{x = -343.73581, y = -875.97534, z = 30.08, h = 167.92885},
{x = -340.0061, y = -876.40546, z = 30.08, h = 167.92885},
{x = -336.5986, y = -877.28638, z = 30.08, h = 167.92885},
{x = -333.05185, y = -877.97681, z = 30.08, h = 167.92885},
{x = -333.05185, y = -877.97681, z = 30.08, h = 167.92885},
{x = -329.40643, y = -878.63788, z = 30.08, h = 167.92885},
{x = -325.72147, y = -879.25824, z = 30.08, h = 167.92885},
{x = -322.13281, y = -880.16846, z = 30.08, h = 167.92885},
{x = -318.6528, y = -880.93817, z = 30.08, h = 167.92885},
{x = -314.83218, y = -881.64703, z = 30.08, h = 167.92885},
{x = -311.01877, y = -882.46844, z = 30.08, h = 167.92885},
{x = -307.56018, y = -883.28003, z = 30.08, h = 167.92885},
{x = -303.90115, y = -883.99384, z = 30.08, h = 167.92885},
{x = -300.29504, y = -884.85364, z = 30.08, h = 167.92885},
{x = -296.90997, y = -885.5957, z = 30.08, h = 167.92885},
{x = -292.96146, y = -886.41071, z = 30.08, h = 167.92885},
{x = -289.48645, y = -887.41724, z = 30.08, h = 167.92885},
{x = -285.81079, y = -888.4361, z = 30.08, h = 167.92885},
{x = -338.38742, y = -891.4361, z = 30.08, h = 347.51135},
{x = -334.72058, y = -891.99463, z = 30.08, h = 347.51135},
{x = -331.05502, y = -892.71991, z = 30.08, h = 347.51135},
{x = -327.47842, y = -893.32312, z = 30.08, h = 347.51135},
{x = -323.94055, y = -894.14526, z = 30.08, h = 347.51135},
{x = -320.23169, y = -894.90387, z = 30.08, h = 347.51135},
{x = -316.68259, y = -895.71759, z = 30.08, h = 347.51135},
{x = -312.95178, y = -896.23035, z = 30.08, h = 347.51135},
{x = -309.29111, y = -897.10309, z = 30.08, h = 347.51135},
{x = -283.04089, y = -914.87848, z = 30.08, h = 70.72579},
{x = -284.12814, y = -918.38263, z = 30.08, h = 70.72579},
{x = -285.69894, y = -921.81818, z = 30.08, h = 70.72579},
{x = -308.16644, y = -909.45264, z = 30.08, h = 167.92885},
{x = -311.78455, y = -908.59283, z = 30.08, h = 167.92885},
{x = -315.41718, y = -908.10632, z = 30.08, h = 167.92885},
{x = -319.06088, y = -907.17145, z = 30.08, h = 167.92885},
{x = -322.60992, y = -906.66125, z = 30.08, h = 167.92885},
{x = -326.38422, y = -905.72455, z = 30.08, h = 167.92885},
{x = -330.06064, y = -905.14703, z = 30.08, h = 167.92885},
{x = -333.66595, y = -904.12952, z = 30.08, h = 167.92885},
{x = -337.17664, y = -903.45026, z = 30.08, h = 167.92885},
{x = -340.87711, y = -902.56909, z = 30.08, h = 167.92885},
{x = -360.58789, y = -889.40771, z = 30.08, h = 269.34546},
{x = -360.58789, y = -893.06989, z = 30.08, h = 269.34546},
{x = -360.58789, y = -896.72125, z = 30.08, h = 269.34546},
{x = -360.58789, y = -900.47247, z = 30.08, h = 269.34546},
{x = -360.58789, y = -904.11255, z = 30.08, h = 269.34546},
{x = -360.58789, y = -907.74481, z = 30.08, h = 269.34546},
{x = -360.58789, y = -911.57758, z = 30.08, h = 269.34546},
{x = -360.58789, y = -915.3222, z = 30.08, h = 269.34546},
{x = -360.58789, y = -919.01758, z = 30.08, h = 269.34546},
{x = -360.58789, y = -922.65698, z = 30.08, h = 269.34546},
{x = -360.58789, y = -926.40198, z = 30.08, h = 269.34546},
{x = -360.58789, y = -929.99933, z = 30.08, h = 269.34546},
{x = -360.58789, y = -933.68976, z = 30.08, h = 269.34546},
{x = -360.58789, y = -937.40729, z = 30.08, h = 269.34546},
{x = -360.58789, y = -941.16071, z = 30.08, h = 269.34546},
{x = -360.58789, y = -944.87872, z = 30.08, h = 269.34546},
{x = -360.58789, y = -948.60126, z = 30.08, h = 269.34546},
{x = -360.58789, y = -952.27148, z = 30.08, h = 269.34546},
{x = -360.58789, y = -956.00195, z = 30.08, h = 269.34546},
{x = -327.62555, y = -924.50067, z = 30.08, h = 70.72579},
{x = -328.92523, y = -927.94684, z = 30.08, h = 70.72579},
{x = -330.24371, y = -931.44763, z = 30.08, h = 70.72579},
{x = -331.45096, y = -934.98199, z = 30.08, h = 70.72579},
{x = -332.76382, y = -938.37054, z = 30.08, h = 70.72579},
{x = -334.01541, y = -941.85681, z = 30.08, h = 70.72579},
{x = -335.24686, y = -945.39301, z = 30.08, h = 70.72579},
{x = -336.47186, y = -948.83551, z = 30.08, h = 70.72579},
{x = -337.54199, y = -952.27197, z = 30.08, h = 70.72579},
{x = -341.81003, y = -921.61603, z = 30.08, h = 250.13654},
{x = -342.89572, y = -925.20056, z = 30.08, h = 250.13654},
{x = -344.27112, y = -928.51434, z = 30.08, h = 250.13654},
{x = -345.30164, y = -931.9939, z = 30.08, h = 250.13654},
{x = -326.37164, y = -956.26929, z = 30.08, h = 250.13654},
{x = -325.4133, y = -952.67749, z = 30.08, h = 250.13654},
{x = -323.98993, y = -949.32855, z = 30.08, h = 250.13654},
{x = -322.84402, y = -945.83954, z = 30.08, h = 250.13654},
{x = -321.55194, y = -942.26611, z = 30.08, h = 250.13654},
{x = -320.42792, y = -938.91455, z = 30.08, h = 250.13654},
{x = -319.19061, y = -935.3725, z = 30.08, h = 250.13654},
{x = -317.6618, y = -931.92798, z = 30.08, h = 250.13654},
{x = -316.67496, y = -928.37665, z = 30.08, h = 250.13654},
{x = -307.11111, y = -947.46423, z = 30.08, h = 70.72579},
{x = -308.18088, y = -950.96991, z = 30.08, h = 70.72579},
{x = -309.61444, y = -954.36469, z = 30.08, h = 70.72579},
{x = -310.79379, y = -957.94458, z = 30.08, h = 70.72579},
{x = -312.24146, y = -961.38483, z = 30.08, h = 70.72579},
{x = -313.2739, y = -964.88513, z = 30.08, h = 70.72579},
{x = -343.05774, y = -974.15405, z = 30.08, h = 341.34091},
{x = -339.54462, y = -975.3172, z = 30.08, h = 341.34091},
{x = -336.09204, y = -976.51782, z = 30.08, h = 341.34091},
{x = -332.48206, y = -977.41138, z = 30.08, h = 341.34091},
{x = -328.96487, y = -978.57477, z = 30.08, h = 341.34091},
{x = -325.41006, y = -979.86481, z = 30.08, h = 341.34091},
{x = -321.94101, y = -981.12402, z = 30.08, h = 341.34091},
{x = -318.67056, y = -982.61591, z = 30.08, h = 341.34091},
{x = -315.38583, y = -984.05426, z = 30.08, h = 341.34091},
{x = -312.08813, y = -985.42816, z = 30.08, h = 341.34091},
{x = -308.0488, y = -986.32593, z = 30.08, h = 341.34091},
{x = -304.80072, y = -987.79578, z = 30.08, h = 341.34091},
{x = -301.16653, y = -988.96954, z = 30.08, h = 341.34091},
{x = -297.73843, y = -990.01654, z = 30.08, h = 341.34091}
}
},
The same goes for other parking lots.
- In the file client\main.lua:
Edit the RemoveVehicles function as follows:
From line 160 to line 186 replace with:
function RemoveVehicles()
for i, j in pairs(Config.ParkingLocations) do
for k, v in pairs(Config.ParkingLocations[i].ParkingPoint) do
local tmpLoc = {
["x"] = v.x,
["y"] = v.y,
["z"] = v.z,
["h"] = v.h,
}
local timeOut = 0
local notFound = false
while notFound == false and timeOut < 3000 do
local veh, distance = ESX.Game.GetClosestVehicle(tmpLoc)
local vl = GetEntityCoords(veh)
if GetDistanceBetweenCoords(vl.x, vl.y, vl.z, v.x, v.y, v.z, true) < 2 then
if NetworkGetEntityIsLocal(veh) then
local tmpModel = GetEntityModel(veh)
SetModelAsNoLongerNeeded(tmpModel)
DeleteEntity(veh)
end
else
notFound = true
end
end
end
end
LocalVehicles = {}
end
From line 275 to line 329 replace with:
-- Check distance
Citizen.CreateThread(function()
while PlayerIdentifier == nil do
Citizen.Wait(10)
end
while true do
Wait(0)
NearParking, DisParking = GetNearParking()
if NearParking ~= nil then
NearParkingPoint = GetNearParkingPoint()
if NearParkingPoint < 50 then
if not SpawnedVehicles then
--print("Spawned the vehicles")
RemoveVehicles()
TriggerServerEvent("esx_realparking:refreshVehicles", NearParking)
SpawnedVehicles = true
Wait(2000)
end
else
if SpawnedVehicles then
--print("Removed the vehicles")
RemoveVehicles()
SpawnedVehicles = false
end
end
end
end
end)
From line 366to line 501 replace with:
-- Logic thread
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
player = PlayerPedId()
coords = GetEntityCoords(player)
NearParking, DisParking = GetNearParking()
if IsPedInAnyVehicle(GetPlayerPed(-1)) then
if NearParking ~= nil then
for k, v in pairs(Config.ParkingLocations[NearParking].ParkingPoint) do
local distance = GetDistanceBetweenCoords(coords, v.x, v.y, v.z, true)
if distance < 10 then
DrawMarker(27, v.x, v.y, v.z+0.1, 0, 0, 0, 0, 0, 0, 0.5, 0.5, 1.0, 1, 157, 0, 155, 100, false, true, 2, false, nil, nil, false)
DrawMarker(36, v.x, v.y, v.z+0.3, 0, 0, 0, 0, 0, 0, 0.5, 0.5, 1.0, 1, 157, 0, 155, 100, false, true, 2, false, nil, nil, false)
if distance < 3.0 then
local storedVehicle = GetPedInStoredCar(GetPlayerPed(-1))
if storedVehicle ~= false then
DisplayHelpText(string.format(_U("need_parking_fee", storedVehicle.fee)))
else
DisplayHelpText(_U("press_to_save"))
end
if IsControlJustReleased(0, 51) then
if storedVehicle ~= false then
DoScreenFadeOut(250)
Wait(500)
ESX.TriggerServerCallback("esx_realparking:driveCar", function(callback)
if callback.status then
DeleteVehicle(storedVehicle.entity)
DeleteVehicle(GetVehiclePedIsIn(GetPlayerPed(-1)))
storedVehicle = nil
Wait(500)
DriveVehicle(callback.vehData)
ESX.ShowNotification(callback.message)
else
ESX.ShowNotification(callback.message)
end
Wait(1000)
DoScreenFadeIn(250)
end, storedVehicle)
else
local veh = GetVehiclePedIsIn(GetPlayerPed(-1))
if veh ~= 0 then
if IsThisModelACar(GetEntityModel(veh)) or IsThisModelABike(GetEntityModel(veh)) or IsThisModelABoat(GetEntityModel(veh)) or IsThisModelAHeli(GetEntityModel(veh)) or IsThisModelAPlane(GetEntityModel(veh)) or IsThisModelAQuadbike(GetEntityModel(veh)) or IsThisModelABicycle(GetEntityModel(veh)) or IsThisModelAAmphibious_Car(GetEntityModel(veh)) or IsThisModelAAmphibious_Quadbike(GetEntityModel(veh)) or IsThisModelAConvertible(GetEntityModel(veh)) then
local vehProps = ESX.Game.GetVehicleProperties(veh)
local vehPos = GetEntityCoords(veh)
local vehHead = GetEntityHeading(veh)
local engHealth = GetVehicleEngineHealth(veh)
local bdyHealth = GetVehicleBodyHealth(veh)
local tnkHealth = GetVehiclePetrolTankHealth(veh)
LastPlate = vehProps.plate
DoScreenFadeOut(250)
Wait(500)
ESX.TriggerServerCallback("esx_realparking:saveCar", function(callback)
if callback.status then
DeleteVehicle(veh)
ESX.ShowNotification(callback.message)
else
ESX.ShowNotification(callback.message)
end
Wait(1000)
DoScreenFadeIn(250)
end, {
location = {x = v.x, y = v.y, z = v.z, h = v.h},
props = vehProps,
parking = NearParking,
livery = GetVehicleLivery(veh),
health = {
engine = engHealth,
body = bdyHealth,
tank = tnkHealth
}
})
else
ESX.ShowNotification(_U("only_allow_car"))
end
end
end
end
end
end
end
end
end
end
end)
function GetNearParking()
local near = nil
local distance = 10000
for k, v in pairs(Config.ParkingLocations) do
local pl = GetEntityCoords(GetPlayerPed(-1))
local cur_distance = GetDistanceBetweenCoords(pl.x, pl.y, pl.z, v.x, v.y, v.z, true)
if cur_distance < distance then
distance = cur_distance
near = k
end
end
return near, distance
end
function GetNearParkingPoint()
local distance = 10000
NearParking, DisParking = GetNearParking()
if NearParking ~= nil then
for k, v in pairs(Config.ParkingLocations[NearParking].ParkingPoint) do
local pl = GetEntityCoords(GetPlayerPed(-1))
local cur_distance = GetDistanceBetweenCoords(pl.x, pl.y, pl.z, v.x, v.y, v.z, true)
if cur_distance < distance then
distance = cur_distance
end
end
end
return distance
end
Previously, every time you exited the parking area, the client deleted all the cars in the designated area! If unfortunately there are vehicles lying outside it will be missed, and the next time the client spaw the vehicles it will be stacked! Now the client will only delete the vehicles located in the designated parking area, and certainly will not miss any vehicles, so stacking will be overcome.
Here is the test video:
Hope the above can be of help to you!
Sorry for my bad English