Skip to Content

Getting started with scripting for FiveM might be overwhelming. In this guide, we’ll show you how to get started with a JavaScript resource.

Prerequisites

Creating a Resource

Make a folder in your resources/[local]/ directory, for example mymode.

Manifest File

Create a fxmanifest.lua file:

fx_version 'cerulean' game 'gta5' author 'Your Name' description 'My awesome script' version '1.0.0' client_script 'mymode_client.js'

Client Script

Create a mymode_client.js file:

const spawnPos = [686.245, 577.95, 130.461] on('onClientGameTypeStart', () => { exports.spawnmanager.setAutoSpawnCallback(() => { exports.spawnmanager.spawnPlayer( { x: spawnPos[0], y: spawnPos[1], z: spawnPos[2], model: 'a_m_m_skater_01', }, () => { emit('chat:addMessage', { args: ['Welcome to the party!'], }) } ) }) exports.spawnmanager.setAutoSpawn(true) exports.spawnmanager.forceRespawn() })

Running the Resource

  1. Start your FXServer
  2. Execute refresh in the console
  3. Execute start mymode in the console
  4. Connect to your server

Implementing a Car Spawner

Add this to your client script:

Delay = (ms) => new Promise((res) => setTimeout(res, ms)) RegisterCommand( 'car', async (source, args, raw) => { let model = 'adder' if (args.length > 0) { model = args[0].toString() } const hash = GetHashKey(model) if (!IsModelInCdimage(hash) || !IsModelAVehicle(hash)) { emit('chat:addMessage', { args: [`Invalid vehicle model: ${model}`], }) return } RequestModel(hash) while (!HasModelLoaded(hash)) { await Delay(500) } const ped = PlayerPedId() const coords = GetEntityCoords(ped) const vehicle = CreateVehicle( hash, coords[0], coords[1], coords[2], GetEntityHeading(ped), true, false ) SetPedIntoVehicle(ped, vehicle, -1) SetEntityAsNoLongerNeeded(vehicle) SetModelAsNoLongerNeeded(model) emit('chat:addMessage', { args: [`Woohoo! Enjoy your new ${model}!`], }) }, false )

Key Concepts

Restarting Resources

Use restart mymode in the server console to quickly reload your resource without restarting the server.