ScriptsAboutBlogToolsKnowledge BaseReviewsFAQBasketDocsSupport
shared

RegisterCommand

FiveM shared native documentation with a Lua example.

Summary

Registers a chat or console command with a handler function. Works on client or server. The standard way to add custom commands.

Returns

void

Parameters

commandNamestringThe command name (without the /).
handlerfunctionfunction(source, args, rawCommand).
restrictedbooleanIf true, requires an ACE permission to use.

Example

RegisterCommand('heal', function(source, args, rawCommand)
  local ped = PlayerPedId()
  SetEntityHealth(ped, GetEntityMaxHealth(ped))
end, false)

Common pitfalls

  • Set restricted to true and grant an ACE permission for admin commands — otherwise anyone can run them.
  • On the server, source is the player ID; on the client it's 0. Handle accordingly.

Related natives

Related guides

FiveM scripts done right

Optimized, dual-framework scripts for QBCore and ESX from Viper Development — escrow protected, delivered instantly to your Cfx portal.

Browse Scripts →