Native functions (or “natives”) are the built-in functions provided by GTA V and FiveM to interact with the game engine. They allow you to manipulate entities, control the camera, manage UI, and much more.
CreateVehicle).-- Get the current player's local ped
local ped = PlayerPedId()
-- Get Entity Coordinates (Vector3)
local coords = GetEntityCoords(ped)
-- Heal the player
SetEntityHealth(ped, 200)
-- Give Weapon
GiveWeaponToPed(ped, `WEAPON_PISTOL`, 100, false, true)-- Spawn a vehicle (Client)
local model = `adder`
RequestModel(model)
while not HasModelLoaded(model) do Wait(0) end
local veh = CreateVehicle(model, x, y, z, heading, true, false)
SetPedIntoVehicle(PlayerPedId(), veh, -1)
-- Repair Vehicle
SetVehicleFixed(veh)-- Draw 3D Text
DrawText3D(x, y, z, "Press ~g~E~w~ to Interact") -- (Custom helper usually required)
-- Notifications (Native)
BeginTextCommandThefeedPost("STRING")
AddTextComponentSubstringPlayerName("Hello World")
EndTextCommandThefeedPostTicker(false, true)Used for per-frame logic like markers or interactions.
CreateThread(function()
while true do
local sleep = 1000 -- Default sleep (1 second)
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local dist = #(coords - targetCoords) -- Fast vector distance check
if dist < 5.0 then
sleep = 0 -- Run every frame when close
DrawMarker(1, targetCoords, ...)
if dist < 1.5 then
-- Handle Input
if IsControlJustReleased(0, 38) then -- E Key
print("Interacted!")
end
end
end
Wait(sleep) -- Dynamic wait time saves performance
end
end)Checking for entities in front of the player.
local function GetEntityInFront()
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local offset = GetOffsetFromEntityInWorldCoords(ped, 0.0, 5.0, 0.0)
local ray = StartShapeTestCapsule(coords.x, coords.y, coords.z, offset.x, offset.y, offset.z, 0.5, 10, ped, 7)
local _, hit, _, _, entity = GetShapeTestResult(ray)
return hit, entity
endFrameworks often wrap natives to provide easier APIs or handle networking automatically.
-- Notification
QBCore.Functions.Notify('This is a notification', 'success')
-- Spawning Vehicle (Server-side callback often used)
QBCore.Functions.SpawnVehicle('adder', function(veh)
SetEntityHeading(veh, 90.0)
end, coords, true)-- Notification
ESX.ShowNotification('This is a notification')
-- Spawning Vehicle
ESX.Game.SpawnVehicle('adder', coords, 90.0, function(veh)
-- callback
end)GetHashKey) are slow. Use the backtick syntax `model_name` for compile-time hashing.#(vec1 - vec2)) instead of GetDistanceBetweenCoords or Vdist. It is significantly faster.Wait() times in loops. Only run code every frame (Wait(0)) when absolutely necessary (e.g., drawing markers or checking input).Citizen.Wait or Citizen.CreateThread. Use the direct global aliases Wait and CreateThread.