JRS COREDocs

Developer setup

Write and run your first JRS Core resource, then set up the editor for autocomplete

The fastest way to learn the API is a resource that does one thing. This one adds /hello: it greets the character and pays a small tip, with the amount decided on the server.

  1. Make the folder

    Create jrs_hello inside your resources folder. A resource needs only a manifest and one script.

  2. Write the two files

    Save both as UTF-8 without BOM, or the server will refuse to read the manifest.

    fxmanifest.lua
    lua
    fx_version 'cerulean'
    game 'rdr3'
    rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aware my resources *will* become incompatible once RedM ships.'
    lua54 'yes'
    
    server_script 'server.lua'
    server.lua
    lua
    local JRS = exports.jrs_core:getCoreApi()
    
    RegisterCommand('hello', function(source)
        local character = JRS.GetCharacter(source)
        if not character then return end          -- player is still on the character screen
        JRS.NotifyRightTip(source, 'Hello ' .. character.firstname, 4000)
        JRS.AddMoney(source, 5)                    -- server decides the amount
    end)
  3. Load it after the core

    Add ensure jrs_hello on its own line below ensure jrs_core in server.cfg, restart, join and type /hello.

    JRS.GetCharacter returns nil while the player is still on the character screen, which is why the command checks it first.

Editor#

Any editor works. The JRS Core extension for VS Code saves the most time: download jrs-core-vsc.vsix, open Extensions, press ... and choose Install from VSIX.

It gives you autocomplete and hover docs for every core export and event, snippets for common blocks, the JRS Dark theme and a command that opens this site. Type JRS., exports.jrs_core: or jrs- in a .lua file to check it is active.

Tip

Before your own events give money or items, read Writing solid scripts.