Skip to main content

How to Set Up VSCode for FiveM and RedM Lua Scripting

· 3 min read
aj
Contributor of the Qbox Project

Getting VSCode setup for FiveM/RedM scripting is actually really easy. The exentions listed in this blog automatically set most of that up for you! Below we will go over some suggested extensions and addons for VSCode.


Overview

The extensions listed below will provide:

  • Autocompletion for native FiveM/RedM/CFX functions.
  • Type-checking using Lua LSP (via EmmyLua-style annotations).
  • In-editor documentation for native functions.
  • Git functionality like in-editor blame annotations, hovers, CodeLens, and more

vscode intellisense GitLens


Installation

1. Install / Open VSCode

Make sure you have Visual Studio Code installed.

2. Install the suggested extensions


Tips & Tricks

  • Hover over native functions (e.g., GetPlayerRoutingBucket, SetEntityCoords) to view documentation
  • Improve IntelliSense and type safety by annotating functions
  • You can download support for export autocompletes of the inventory and core resources
    • ox_types adds support for export calls from Overextended resources (ox_inventory, ox_doorlock, etc)
    • qbox_types adds support for export calls from QBox resources (qbx_core, qbx_medical, etc)
warning

After downloading either of the addons, store them in a place you will remember (you will need the file path later)

The below image shows ox_types adding autocomplete for inventory exports:

inventory exports

The below codeblock shows a correctly annotated function:

  • ---@param source Source tells the intellisense the function expects a source (aka a players server ID) as the first arg
  • ---@return boolean tells the intellisense the function will return a boolean (aka true or false)
-- Check if player is whitelisted, kept like this for backwards compatibility or future plans
---@param source Source
---@return boolean
function IsWhitelisted(source)
if not serverConfig.whitelist then return true end
if IsPlayerAceAllowed(source --[[@as string]], serverConfig.whitelistPermission) then return true end
return false
end

Setup & Configuration

The below codeblock shows what your library settings should look like after downloading ox_types, qbox_types or both

(To get to the settings, press F1 and type settings)

info

We add the locally stored ox_lib resource path as it automatically adds support for lib autocompletes such as lib.notify

"Lua.workspace.library": [
// EXISTING LIBRARYS HERE
"F:/GitHub/ox_types/types",
"F:/GitHub/qbox_types/types",
"F:/CoolRoleplayServer/resources/[ox]/ox_lib"
],

You're Ready to Code!

That’s it! Your VSCode environment is now set up FiveM/RedM Lua development. No more tab-switching to docs. Just clean, typed, and documented code... hopefully.