Plz help me for near detection

Hi, i’ve a blank server with no mods and i i’ve created this client.lua :

Citizen.CreateThread(function()
local blip = AddBlipForCoord(-45.228, -1083.123, 25.816)
SetBlipSprite(blip,225)
SetBlipColour(blip, 3)

local modelName = "t20" --Name of model, can find all model names of vehicles on the wiki
local vehicleHash = GetHashKey(modelName) --Get the hash so we can pass it to CreateVehicle as it requires the hash
	
--A loop to make sure the model gets loaded properly
while (not HasModelLoaded(vehicleHash)) do 
	RequestModel(vehicleHash)
	Citizen.Wait(0)
end
	
local rotation = 75.01   --Rotation/heading

local vehicle = CreateVehicle(vehicleHash, -45.228, -1083.123, 25.816, rotation, true, true) --Create the vehicle.

if GetDistanceBetweenCoords(-45.228,-1083.123,25.816,GetEntityCoords(LocalPed())) < 5 then
		drawTxt('Vendez ce vehicule',0,1,0.5,0.8,0.6,255,255,255,255)
		RemoveBlip(blip)
		blip = AddBlipForCoord(5.228, -1083.123, 25.816)
		SetBlipSprite(blip,290)
		SetBlipColour(blip, 3)
end

end)

On the start, i’ve the blip on the map and the “t20” car is here. But normaly, when i’m near the car, there is a message and the blip is destroyed and a new blip must appear. But it don’t detect me : any idea ?

In this line:

if GetDistanceBetweenCoords(-45.228,-1083.123,25.816,GetEntityCoords(LocalPed())) < 5 then

Did you try using GetPlayerPed(-1) instead of LocalPed()?
Plus I would recommend comparing with 5.0 (with the dot) to force it being a float value :wink:

i’ve tryed with GetPlayerPed(-1) and a floating number but it same.
I guess if it’s not a while true loop missing, i’ll try.

Ok, it’s better with loop but i’ve an error : Attempt to call a nil value at the line of drawtext.

Can you show us the drawTxt Function? Could help me finding your problem.

Loop this. It only runs once, from the code you posted above.

Use Vdist native.

float VDIST(float x1, float y1, float z1, float x2, float y2, float z2) // 2A488C176D52CCA5 3C08ECB7
Calculates distance between vectors.

But wouldnt he be able to get the distance between coords and do this too?

GetDistanceBetweenCoords() accepts coordinates in X1, Y1, Z1, X2, Y2, Z2 format. You need
local coords = GetEntityCoords(LocalPed()) GetDistanceBetweenCoords(-45.228,-1083.123,25.816,coords.x,coords.y,coords.z))

thanks all, i’ll try it tomorrow.

@MrDaGree Yes i made a loop on getdistance and drawtext but i can’t loop the new blip so i made a condition.

I’m not sure i’m doing it right, maybe i must think about it in another way. Sul

Hello, ok i’m near to resolve that : Getdistance work fine now but drawtxt was on global NIL error. I though it was a native fonction but i saw that it needeed to be declared so i wrote this function found on another source :

function drawTxt(text,font,centre,x,y,scale,r,g,b,a) SetTextFont(font) SetTextProportional(0) SetTextScale(scale, scale) SetTextColour(r, g, b, a) SetTextDropShadow(0, 0, 0, 0,255) SetTextEdge(1, 0, 0, 0, 255) SetTextDropShadow() SetTextOutline() SetTextCentre(centre) SetTextEntry("STRING") AddTextComponentString(text) DrawText(x , y) end

Now i’ve a NIL global error with SetTextEntry. But the source have not declared this function. How do i declare it please ?
Is my problem is because i don’t use essetialmode and i’ve no essetial declarations ?