[Help] I need delete vehicle when the vehicle is in marker

Hello guys,
Sorry for my English but I’m from Poland :slight_smile:

I need short srcipt which delete vehicle when the vehicle is in marker and press E on the keyboard

The vehicle to be removed is “rhapsody”

Thanks for help

Wouldn’t be that hard right? you check if a player is close to the marker. if yes display a prompt and delete the vehicle player is in if he presses E

You can check the distance using for example Vdist or vector3 maths

Then check if a control is pressed using IsControlJustPressed()

:smile:

Ok, I wrote myself a few lines of code and it works in the end

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
			if (IsInVehicle()) then
				if IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey("Rhapsody"))  then
					DrawMarker(1, -1287.86, -1399.74, 4.50 - 1, 0, 0, 0, 0, 0, 0, 2.5001, 2.5001, 1.0001, 255, 165, 0,165, 0, 0, 0,0)
					if GetDistanceBetweenCoords(-1287.86, -1399.74, 4.50, GetEntityCoords(LocalPed())) < 2.0 then
					local playerPed = PlayerPedId()
					SetTextComponentFormat('STRING');
					AddTextComponentString("Wciśnij ~INPUT_CONTEXT~ aby zwrócić ~b~pojazd służbowy");
					DisplayHelpTextFromStringLabel(0, 0, 1, -1);
						if IsPedInAnyVehicle(playerPed, false) then
							if (IsControlJustReleased(1, 38)) then
								DeleteVehicle(GetVehiclePedIsIn(playerPed, true))
							end
						end
					end
				end
			end
	end
end)
1 Like

The code fix, the earlier one works only on the vehicle affected by the console

ESX = nil

Citizen.CreateThread(function()
	while ESX == nil do
		TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
		Citizen.Wait(0)
	end
end)

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
			if (IsInVehicle()) then
				if IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey("Rhapsody"))  then
					DrawMarker(1, -1287.86, -1399.74, 4.50 - 1, 0, 0, 0, 0, 0, 0, 2.5001, 2.5001, 1.0001, 255, 165, 0,165, 0, 0, 0,0)
					if GetDistanceBetweenCoords(-1287.86, -1399.74, 4.50, GetEntityCoords(LocalPed())) < 2.0 then
					local playerPed = PlayerPedId()
					local auto = GetVehiclePedIsIn(GetPlayerPed(-1)) 
					SetTextComponentFormat('STRING');
					AddTextComponentString("Wciśnij ~INPUT_CONTEXT~ aby zwrócić ~b~pojazd służbowy");
					DisplayHelpTextFromStringLabel(0, 0, 1, -1);
						if IsPedInAnyVehicle(playerPed, false) then
							if (IsControlJustReleased(1, 38)) then
								ESX.Game.DeleteVehicle(auto)
							end
						end
					end
				end
			end
	end
end)
1 Like

And how I do for all vehicle ?

How I do for all vehicle , not only Rhapsody or by job

6 months old topic