Engineering
Natives: the game functions behind every FiveM script
What FiveM natives are, how to read the Cfx native reference, naming (SNAKE_CASE to PascalCase), namespaces, client vs server natives, return values and out-parameters, Citizen.InvokeNative and native hashes.
Overview
Nearly everything a FiveM script does to the game — spawning a car, reading a position, playing an animation, drawing text — goes through a native: a function built into GTA V (or into FiveM itself) that scripts can call. There are thousands of them. Knowing how to find the right one and read its documentation is the single most useful skill after the language itself.
What a native is
GTA V’s own scripts (missions, the phone, the Online modes) are written in a scripting language that calls into the game engine through native functions. FiveM exposes those same natives to Lua, JavaScript and C#, and adds its own set — the CFX natives — for things only a multiplayer framework needs, such as player identifiers, resources, state bags and server-side entities.
| Group | Examples | Where they run |
|---|---|---|
| Game natives | GetEntityCoords, CreateVehicle, TaskPlayAnim | Client (a subset also on the server with OneSync) |
| CFX natives | GetPlayerIdentifiers, GetResourceState, SetResourceKvp | Client, server or both — check each |
Reading the native reference
The Cfx documentation site hosts the native reference, searchable by name. Each entry shows the C-style declaration, the native’s hash, parameters, return value and community notes. Take GET_ENTITY_COORDS:
Vector3 GET_ENTITY_COORDS(Entity entity, BOOL alive);local pos = GetEntityCoords(PlayerPedId(), true)
print(pos.x, pos.y, pos.z)- Name: remove underscores and capitalise each word to get the Lua/JS name.
- Types:
Entity,Ped,VehicleandPlayerare integer handles;Hashis a number (usejoaator backticks);BOOLis true/false. - Notes: many parameters are named
p0,p1… because nobody has worked out what they do. The notes under the entry usually say what values are safe.
Out-parameters become return values
In C, some natives write results into pointers. In Lua you simply receive them as extra return values, in order:
BOOL GET_GROUND_Z_FOR_3D_COORD(float x, float y, float z, float* groundZ, BOOL ignoreWater, BOOL p5);local found, groundZ = GetGroundZFor_3dCoord(x, y, 1000.0, false, false)
if found then print(groundZ) endThe function’s own return value comes first (found), followed by each out-parameter (groundZ). The same pattern applies to natives like GetScreenCoordFromWorldCoord.
Client natives and server natives
Most game natives exist only on the client, because the client runs the game. With OneSync the server gains a set of natives that work on its view of entities — GetPlayerPed, GetEntityCoords, GetVehiclePedIsIn, SetEntityCoords, CreateVehicleServerSetter and others. The reference marks each native’s side; calling a client-only native on the server throws an error that the function does not exist.
Calling a native by hash
Occasionally a native has no name in your runtime yet — new game builds add natives, and some are only known by hash. You can call it directly:
-- Equivalent to SetEntityInvincible(ped, true)
Citizen.InvokeNative(0x3882114BDE571AD4, PlayerPedId(), true)Return types of natives called by hash are not known to the runtime, so reading return values may need explicit result types (Citizen.ResultAsInteger(), Citizen.ResultAsVector() and friends). Use named natives whenever they exist.
The cost of calling natives
Each native call crosses from the scripting runtime into the game. That is cheap once, and expensive a few thousand times per frame. The common waste is calling the same native repeatedly inside a Wait(0) loop — for example PlayerPedId() five times per frame. Cache values that do not change every frame, and slow the loop down when nothing is nearby. Lua performance optimisation and threads and Wait cover the techniques.
Frequently asked questions
What are natives in FiveM?
Built-in functions of GTA V and of FiveM itself that scripts call to control the game — spawning entities, reading positions, animations, UI and more.
Where can I find the FiveM native list?
In the native reference on the Cfx documentation site, searchable by name and grouped by namespace.
How do I convert a native name to Lua?
Remove the underscores and capitalise each word: SET_ENTITY_HEALTH becomes SetEntityHealth.
Why does a native not exist on the server?
It is a client-only native. Only natives marked as server-side (many require OneSync) are available in server scripts.
What does p0 or p1 mean in a native?
The parameter’s purpose is unknown or undocumented. Check the notes on the native’s page for values that are known to work.
Need this built, not just explained?
Ten years of FiveM work, from Lua to NUI
Custom resources, React NUI, ESX / QBCore / Qbox integration, OneSync performance audits and security reviews — plus the websites and SEO around your server brand.
Related guides
- EngineeringThreads and Wait in FiveM: loops that do not eat framesCreateThread(fn) starts a coroutine that runs alongside the game; Wait(ms) pauses it and lets everything else run. Wait(0) resumes on the next frame, so the loop runs every frame (60+ times a second). Use it only while you must draw or read input every frame; otherwise sleep for hundreds of milliseconds, and make loops adaptive — fast when the player is near something, slow when they are not.
- EngineeringServer-side entity spawning in FiveMOn the server, create vehicles with CreateVehicleServerSetter(model, type, x, y, z, heading) — it is more reliable than the RPC-based CreateVehicle. Wait for DoesEntityExist, set plate and state, put the player in with SetPedIntoVehicle, and send the network ID to the client if it needs to do more. Delete with DeleteEntity. Once all scripts spawn server-side, enable sv_entityLockdown.
- Getting startedWrite your first FiveM script, step by stepCreate a folder resources/my_first, add an fxmanifest.lua with fx_version 'cerulean', game 'gta5', a client_script and a server_script, then write a client command that loads a model with RequestModel, waits for HasModelLoaded, spawns it with CreateVehicle and seats the player with SetPedIntoVehicle. Add ensure my_first to server.cfg, restart, and type /car adder in game.