[HELP] A parking script based on esx-qalle-sellvehicles

Hi everyone,

I’m trying to edit esx-qalle-sellvehicles in order to use it as a parking system. You drive your car on a parking place, buy a ticket and your vehicle will stay parked there until you get it back. But I’m facing some troubles :

When you buy a car, or remove one from the shop, I want it not to despawn.
So I commented out the function "DeleteVehicle(veh) at line 171 and 181 and the vehicle no longer dispawns, but I still have the attached menu as you can see at 26 seconds :


short clip

How to remove that menu whitout despawning the car?

Ok it’s almost ready :
JagerBom gave me a hand on this (thanks man, tu déchires!) and he found a way to remove the menu when you remove or buy the car :star_struck:.

In the client.lua you’ll need to find the part where you buy the vehicle and replace it by :

elseif action == "buy" then
			ESX.TriggerServerCallback("esx-qalle-sellvehicles:buyVehicle", function(isPurchasable, totalMoney)
				if isPurchasable then
					--ReleaseVehicles()
      				print(ESX.DumpTable(Config.VehiclePositions))
					for i = 1, #Config.VehiclePositions, 1 do
						if Config.VehiclePositions[i]["entityId"] ~= nil then
							local pedCoords = GetEntityCoords(GetPlayerPed(-1))
          					print(pedCoords)
							local vehCoords = GetEntityCoords(Config.VehiclePositions[i]["entityId"])
							local dstCheck = GetDistanceBetweenCoords(pedCoords, vehCoords, true)
							if dstCheck <= 2.0 then
								Config.VehiclePositions[i]["entityId"] = nil
							end
						end
					end
					ESX.ShowNotification("Vous avez ~g~acheté~s~ le véhicule")
					menu.close()
				end
			end, ESX.Game.GetVehicleProperties(veh), price)
		elseif action == "remove" then
			ESX.TriggerServerCallback("esx-qalle-sellvehicles:buyVehicle", function(isPurchasable, totalMoney)
				if isPurchasable then
					--ReleaseVehicles()
      				print(ESX.DumpTable(Config.VehiclePositions))
					for i = 1, #Config.VehiclePositions, 1 do
						if Config.VehiclePositions[i]["entityId"] ~= nil then
							local pedCoords = GetEntityCoords(GetPlayerPed(-1))
          					print(pedCoords)
							local vehCoords = GetEntityCoords(Config.VehiclePositions[i]["entityId"])
							local dstCheck = GetDistanceBetweenCoords(pedCoords, vehCoords, true)
							if dstCheck <= 2.0 then
								Config.VehiclePositions[i]["entityId"] = nil
							end
						end
					end
					ESX.ShowNotification("Vous avez ~g~retiré~s~ le véhicule de la vente")
					menu.close()
				end
			end, ESX.Game.GetVehicleProperties(veh), 0)

It’s working nice for the client (player A) who buys or removes the vehicle :

Video (No menu anymore :slight_smile: )

but not working if player B looks at the buyer. :


Video

I presume I’m missing something server-sided to allow player B to see the car released.
I’ll let you know… :wink:

I tried something :

RegisterNetEvent("esx-qalle-sellvehicles:ReleaseVehicles")
AddEventHandler("esx-qalle-sellvehicles:ReleaseVehicles", function()
	local VehPos = Config.VehiclePositions

	for i = 1, #VehPos, 1 do
		local veh, distance = ESX.Game.GetClosestVehicle(VehPos[i])
		
		if DoesEntityExist(veh) and distance <= 2.0 then
			Citizen.Wait(100)
			
			SetEntityAsMissionEntity(veh, true, true)
			FreezeEntityPosition(veh, false)
			SetVehicleHasBeenOwnedByPlayer(veh, true)
		end
	end		
end)

This is client-sided.
And we have this, calling the trigger from server-side when you buy or remove the car from the shop :

TriggerClientEvent("esx-qalle-sellvehicles:ReleaseVehicles", -1)

I no longer have any error in both consoles, but it’s only working for the client who buys or removes the car. I need some help to sync this action so everyone on the server can see the “unfrozen” car.

Here some news :

The only way to make it work for each clients is to quickly despawn/spawn the vehicle parked on the place. So I edited the code a bit :

RegisterNetEvent("esx-qalle-sellvehicles:RemoveVehicles2")
AddEventHandler("esx-qalle-sellvehicles:RemoveVehicles2", function()

	local VehPos = Config.VehiclePositions

	for i = 1, #VehPos, 1 do
		
		local playerPed = PlayerPedId()
		local veh, distance = ESX.Game.GetClosestVehicle(VehPos[i])
		local vehprops = ESX.Game.GetVehicleProperties(veh)


		if DoesEntityExist(veh) and distance <= 1.0 then
			
			ESX.Game.DeleteVehicle(veh)
			
			ESX.Game.SpawnVehicle(vehprops.model, {
												x = VehPos[i].x,
												y = VehPos[i].y,
												z = VehPos[i].z
											}, VehPos[i].h, function(veh)
			ESX.Game.SetVehicleProperties(veh, vehprops)
			TaskWarpPedIntoVehicle(PlayerPedId(), veh, -1)
			SetVehicleOnGroundProperly(veh)
			SetEntityAsMissionEntity(veh, true, true)
			end)
		end
	end
end)

With this, the parked car is despawned/spawned and “unfrozen” so the owner or buyer can go with his car.


clip

I still have some trouble to despawn the car for all the client and to spawn it on its parking place.
As you can see in this clip, the vehicle is only despawning for the client who takes the car, not for the other clients. Also, the car spawns on parking place 1 instead of spawning on place 2.


clip2

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.