Skip to Content
ScriptingJavaScript Basics

JavaScript Basics

JavaScript is a modern alternative to Lua for FiveM scripting.

Variables

const name = "John" let age = 25 var isActive = true

Functions

function greet(name) { return `Hello, ${name}` } const message = greet("World")

Objects

const player = { name: "John", age: 25, items: ["sword", "shield"] } console.log(player.name) // "John" console.log(player.items[0]) // "sword"

FiveM Functions

// Get player const playerId = GetPlayerPed(-1) // Get player coords const coords = GetEntityCoords(playerId) // Trigger event emit('myevent', data)

Async/Await

async function fetchData() { const response = await fetch('https://api.example.com/data') const data = await response.json() return data }

Common Patterns

Debouncing

let lastTime = 0 function debouncedAction() { const currentTime = GetGameTimer() if (currentTime - lastTime < 1000) { return } lastTime = currentTime // Do action }

Threading

setTick(() => { // Do something every frame })
Last updated on