Skip to main content
TRACK B·FIVEM FUNDAMENTALS·Verified June 2026 · Lua 5.4 · ox_lib 3.x
Learning with an AI assistant?
Copies this lesson plus 2026 ground rules (no lua54 'yes', Cfx.re Portal, correct callback signatures) as a ready-to-paste mentor prompt.

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.

You'll build
qu_coords: a /here command that prints your live position, and a /near check that prints whether a fixed point is within range.
Time
~26 minutes
You need
A working FXServer you can restart one resource on, and the ability to read F8 output.
You'll learn
vector3 -> GetEntityCoords(PlayerPedId()) -> GetEntityHeading -> #(a - b) distance -> GetDistanceBetweenCoords -> why distance gates interaction and performance
BEFORE YOU START

Build it

Make the resource folder

The server has one folder for this lesson.

Inside your server's resources folder, create this folder:

code
resources/qu_coords

Create the files

Every file named in the manifest exists.

Create this exact file layout:

code
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

FiveM knows which file to load.

Open fxmanifest.lua and paste this:

code
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

The topic is now represented by runnable code.

Open client.lua and paste this:

code
-- 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

The expected proof appears in F8.

Open server.cfg and add this line:

code
ensure qu_coords

Save, then run:

code
restart qu_coords

Join the server, open F8, and run this test:

code
/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.

Still ahead in this lesson
  • 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.