Getting started with scripting for FiveM might be overwhelming. In this guide, we’ll show you how to get started with a JavaScript resource.
Make a folder in your resources/[local]/ directory, for example mymode.
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'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()
})refresh in the consolestart mymode in the consoleAdd 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
)GetHashKey, CreateVehicle, etc.RegisterCommand to create chat commandsemit to trigger events like chat:addMessageUse restart mymode in the server console to quickly reload your resource without restarting the server.