[HELP] Draw text on vehicle

Hello, I’m editing a Lock System and I want to when I lock or unlock a vehicle appears a message on the vehicle saying “Locked” or “Unlocked”.

I manage to make the message working by using a DrawText3Ds, but the message appears on my player.

Does someone know how can I make the message appear in the vehicle?

Examples on how it is working now:

This is the part of the code that is controlling the text coordinates

function Display(mePlayer, text, offset)
    local displaying = true
    Citizen.CreateThread(function()
        Wait(time)
        displaying = false
    end)
    Citizen.CreateThread(function()
        nbrDisplaying = nbrDisplaying + 1
        while displaying do
            Wait(0)
            local coords = GetEntityCoords(GetPlayerPed(mePlayer), false)
            DrawText3Ds( coords.x, coords.y, coords.z, text)
        end
        nbrDisplaying = nbrDisplaying - 1
    end)
end

And this is what opens, closes the vehicle and triggers the message:

RegisterNetEvent('esx_vehiclelock:triggerDisplay')
AddEventHandler('esx_vehiclelock:triggerDisplay', function(text, source)
    local offset = 1 + (nbrDisplaying*0.14)
    Display(GetPlayerFromServerId(source), text, offset)
end)

function OpenCloseVehicle()
	local playerPed = GetPlayerPed(-1)
	local coords    = GetEntityCoords(playerPed)

	local vehicle = nil

	if IsPedInAnyVehicle(playerPed,  false) then
		vehicle = GetVehiclePedIsIn(playerPed, false)
	else
		vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 7.0, 0, 70)
	end


			local locked = GetVehicleDoorLockStatus(vehicle)
			if locked == 1 then -- if unlocked
				SetVehicleDoorsLocked(vehicle, 2)
				PlayVehicleDoorCloseSound(vehicle, 1)
				TriggerServerEvent('esx_vehiclelock:shareDisplay', "Vehicle locked")
				Wait(5000)
			elseif locked == 2 then -- if locked
				SetVehicleDoorsLocked(vehicle, 1)
				PlayVehicleDoorOpenSound(vehicle, 0)
				TriggerServerEvent('esx_vehiclelock:shareDisplay', "Vehicle unlocked")
				Wait(5000)
			end
	end
1 Like

maybe have a function that finds the closest vehicle entity and uses those coords

To display 3Dtext on a vehicle you need to change somethings in your function, I made it more generic:

function DisplayOnEntity(entity, text, offset)
    local displaying = true
    Citizen.CreateThread(function()
        Wait(time)
        displaying = false
    end)
    Citizen.CreateThread(function()
        nbrDisplaying = nbrDisplaying + 1
        while displaying do
            Wait(0)
            local coords = GetEntityCoords(entity, false)
            DrawText3Ds( coords.x + offset.x, coords.y + offset.y, coords.z + offset.z, text)
        end
        nbrDisplaying = nbrDisplaying - 1
    end)
end

Take care about ‘offset’, it can’t be null, if you don’t want offset use:

{ x = 0.0, y = 0.0, z = 0.0 }

Thanks for you answer, but I can’t get it to working…

I have this:

	local vehicle = nil

	if IsPedInAnyVehicle(playerPed,  false) then
		vehicle = GetVehiclePedIsIn(playerPed, false)
	else
		vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 7.0, 0, 70)
	end

But I don’t know how to use those coords in the 3dtext

Ok I got, thanks for you answers

can i ask what your solotuion was?

I use this

local vehicle = nil

	if IsPedInAnyVehicle(playerPed,  false) then
		vehicle = GetVehiclePedIsIn(playerPed, false)
	else
		vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 7.0, 0, 70)
	end

On my Display function and made the drawtext get vehicle coords insted of PlayerPed coords.

You need to adapt it to your code

neat

20charrrr

Where do i put this in de code i dont understand ?

can you share your working codes?