Coordinates, vectors, and distance
Almost every world feature in FiveM starts with one question: where is the player, and how far is that from something else. This lesson builds the two lines you will reuse forever. You read your own position as a vector3, then measure the gap to another point, and you learn why that single measurement is the gate that turns a marker, a shop, or a job into something a player can actually reach.
Build it
Make the resource folder
Inside your server's resources folder, create this folder:
resources/qu_coords
Create the files
Create this exact file layout:
resources/qu_coords/
fxmanifest.lua
client.lua
This is a client-only resource. Coordinates belong to the player's character, which lives on the client, so there is no server.lua here.
Write fxmanifest.lua
Open fxmanifest.lua and paste this:
fx_version 'cerulean'
game 'gta5'
client_script 'client.lua'
Older tutorials add a lua54 'yes' line here. As of June 2025 that setting is deprecated and ignored: Lua 5.4 is now the only Lua runtime, so you leave it out.
Write the lesson code
Open client.lua and paste this:
-- A fixed point in the world to measure against (near Legion Square in Los Santos).
local target = vector3(195.17, -933.77, 30.69)
RegisterCommand('here', function()
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local heading = GetEntityHeading(ped)
print(('[qu_coords] you are at x=%.2f y=%.2f z=%.2f facing %.1f deg'):format(pos.x, pos.y, pos.z, heading))
end, false)
RegisterCommand('near', function()
local pos = GetEntityCoords(PlayerPedId())
local dist = #(pos - target)
if dist <= 10.0 then
print(('[qu_coords] target is %.1fm away - IN RANGE'):format(dist))
else
print(('[qu_coords] target is %.1fm away - too far'):format(dist))
end
end, false)
Start and test it
Open server.cfg and add this line:
ensure qu_coords
Save, then run:
restart qu_coords
Join the server, open F8, and run this test:
/here
/near
Your exact numbers will differ because they depend on where your character is standing when you run the command. The shape is what matters: /here prints three position numbers plus a heading, and /near prints a single distance with a verdict. Walk toward Legion Square (or teleport there) and run /near again to watch the distance shrink until it reads IN RANGE. The next section explains how three numbers and a subtraction produced that one distance.
Keep reading the full lesson
Sign in to start, then unlock every step of this lesson and the full FiveM School with a membership.
- How it works
- If something went wrong
- What you can do now
- Try it yourself
The remainder of Coordinates, vectors, and distance is available to FiveM School members.