JRS COREDocs

Lib helpers

The small helper library built into jrs_core for prompts, peds, blips, distance checks, dialogs and quick player data.

The JRS lib is a set of plain helper functions that used to ship as a separate jrs_lib resource. It now lives inside jrs_core (client/lib.lua, client/lib_exports.lua and server/lib.lua), and jrs_core still answers to the old name through provide 'jrs_lib'. Call one of the exports below to get the helper table for your side, then call functions on it.

Getting The Helpers#

Client

jrs_lib

#
exports.jrs_core:jrs_lib()

Builds and returns the client helper table. The name matches the old resource, so a script written for it only needs the resource name changed.

lua
local lib = exports.jrs_core:jrs_lib()
local hours, minutes = lib.getTime()
print(('In-game time %02d:%02d'):format(hours, minutes))
ReturnstableThe client helper table (prompts, peds, blips, distance and dialog helpers).
Client

getLibApi

#
exports.jrs_core:getLibApi()

Same table as jrs_lib(), under a clearer name. Pick either one; they are built by the same function.

lua
local lib = exports.jrs_core:getLibApi()
ReturnstableThe client helper table.
Client

jrs_lib:getApi

#
TriggerEvent('jrs_lib:getApi', function(lib) ... end)

Hands the full client helper table to your callback. This copy also carries getFolder and fpsTimer, which the export does not include.

lua
local lib
TriggerEvent('jrs_lib:getApi', function(api) lib = api end)
print(lib.getFolder())
ArgumentTypeMeaning
cbfunctionCalled right away with the helper table.
Server

getLibServerApi

#
exports.jrs_core:getLibServerApi()

Returns the server helper table: player info, item registration, notifications and Discord logging.

lua
local libServer = exports.jrs_core:getLibServerApi()
print(libServer.getFramework()) -- "jrs_core"
ReturnstableThe server helper table.
Server

jrs_lib:getApi

#
TriggerEvent('jrs_lib:getApi', function(lib) ... end)

Server version of the same event. Your callback receives the same table as getLibServerApi().

lua
local libServer
TriggerEvent('jrs_lib:getApi', function(api) libServer = api end)
ArgumentTypeMeaning
cbfunctionCalled right away with the server helper table.

Settings#

All lib options sit under Config.Lib in jrs_core/config/lib.lua.

Key Default What it changes
FolderWithIcons 'jrs_inventory/html/images/items/' Where the fallback notification loads item icons from.
EnableDevCommands true Registers the two developer commands listed at the bottom of this page.
PolyPointCommand 'polyPoint' Name of the polygon tracing command. Empty string turns it off.
TargetCommand 'target' Name of the aim debug command. Empty string turns it off.
CharacterTable 'Characters' Value returned by the server helper CharacterTable().
JobColumn 'job' Value returned by JobColumn().
JobGradeColumn 'jobgrade' Value returned by JobGradeColumn().
SteamColumn 'identifier' Value returned by SteamColumn().
CharIdColumn 'charidentifier' Value returned by CharIdColumn().

Prompt Groups#

Prompts are keyed by their text plus the group id you pass in, so the same text can live in two groups. A group stays on screen while it is switched on with showPrompt. When the player completes a button, the lib disables that button and fires the event you attached to it, so turn it back on with setPromptEnable when you are ready for the next press.

Client

createPrompt

#
lib.createPrompt(text, key, promptHash, holdMode, event)

Registers one button inside a prompt group. Calling it again with the same text and group does nothing, so it is safe inside a loop.

lua
local lib = exports.jrs_core:jrs_lib()
local group = GetRandomIntInRange(0, 0xffffff)

lib.createPrompt('Open shop', 0xC7B5340A, group, 'SHORT_TIMED_EVENT', 'myshop:open')
lib.showPrompt('General Store', group, true)

AddEventHandler('myshop:open', function()
    -- open your menu here, then allow the next press
    lib.setPromptEnable('Open shop', group, true)
end)
ArgumentTypeMeaning
textstringLabel shown on the button.
keynumberControl hash, for example 0xC7B5340A for Enter.
promptHashnumberGroup id the button belongs to. Any number you pick works, such as GetRandomIntInRange(0, 0xffffff).
holdModestring|falsefalse for a tap, or a hold timing name such as 'SHORT_TIMED_EVENT', 'MEDIUM_TIMED_EVENT' or 'LONG_TIMED_EVENT'.
eventstringClient event fired with TriggerEvent when the button is completed.
Client

showPrompt

#
lib.showPrompt(name, prompt, show)

Turns a whole group on or off. While it is on, a background loop draws the group every frame with name as its title and listens for presses.

lua
local lib = exports.jrs_core:jrs_lib()
local inside = lib.playerNearCoords(-322.2, 803.9, 117.9, 2.0)
lib.showPrompt('General Store', group, inside)
ArgumentTypeMeaning
namestringGroup title shown above the buttons.
promptnumberGroup id used in createPrompt.
showbooleanfalse hides the group. Any other value shows it.
Client

getPrompt

#
lib.getPrompt(promptHash, text)

Draws a group for the current frame only. Use it when you run your own loop instead of showPrompt.

lua
CreateThread(function()
    while nearBench do
        lib.getPrompt(group, 'Workbench')
        if lib.getPromptButton('Craft', group) then
            TriggerServerEvent('mycraft:start')
        end
        Wait(0)
    end
end)
ArgumentTypeMeaning
promptHashnumberGroup id.
textstringGroup title for this frame.
Client

getPromptButton

#
lib.getPromptButton(text, promptHash)

Checks whether the player has finished holding a button. On success it also resets the hold so the next check starts clean.

lua
if lib.getPromptButton('Craft', group) then
    print('crafting started')
end
ArgumentTypeMeaning
textstringButton text used in createPrompt.
promptHashnumberGroup id.
Returnsbooleantrue on the frame the hold completed.
Client

getPromptButtonData

#
lib.getPromptButtonData(text, promptHash)

Gives you the raw prompt handle so you can call prompt natives on it yourself.

lua
local handle = lib.getPromptButtonData('Craft', group)
if handle then PromptSetPriority(handle, 2) end
ArgumentTypeMeaning
textstringButton text.
promptHashnumberGroup id.
ReturnsnumberPrompt handle, or nil when no such button was created.
Client

setPromptVisible

#
lib.setPromptVisible(text, hash, state)

Hides or shows a single button while the rest of its group stays on screen.

lua
lib.setPromptVisible('Sell', group, playerHasItems)
ArgumentTypeMeaning
textstringButton text.
hashnumberGroup id.
statebooleantrue to show the button.
Client

setPromptEnable

#
lib.setPromptEnable(text, hash, state)

Greys a button out or makes it usable again. You need this after every completed press, because the lib disables the button before firing its event.

lua
lib.setPromptEnable('Open shop', group, true)
ArgumentTypeMeaning
textstringButton text.
hashnumberGroup id.
statebooleantrue to allow presses.
Client

promptDelete

#
lib.promptDelete(text, promptHash)

Removes one button. When the last button of a group is gone, the group is switched off as well.

lua
AddEventHandler('onResourceStop', function(name)
    if name ~= GetCurrentResourceName() then return end
    lib.promptDelete('Open shop', group)
end)
ArgumentTypeMeaning
textstringButton text.
promptHashnumberGroup id.

Peds Vehicles And Blips#

Client

createPed

#
lib.createPed(model, x, y, z, h, dist, scenario)

Adds a local, frozen, invincible ped to a pool. The ped spawns when the player comes within dist and is removed again when they leave, checked once per second. Every ped in the pool is cleaned up when jrs_core stops.

lua
lib.createPed('U_M_M_VALGENSTOREOWNER_01', -324.1, 803.6, 116.9, 280.0, 40.0, 'WORLD_HUMAN_STAND_WAITING')
ArgumentTypeMeaning
modelstringPed model name.
xnumberX position.
ynumberY position.
znumberZ position.
hnumberHeading.
distnumberSpawn and despawn range in metres.
scenariostringScenario name to play in place, such as 'WORLD_HUMAN_SMOKE'.
Client

getLastPed

#
lib.getLastPed()

Returns the handle of the most recent ped the pool spawned.

lua
local ped = lib.getLastPed()
if ped and DoesEntityExist(ped) then SetPedScale(ped, 1.05) end
ReturnsnumberPed handle, or nil before any pool ped has spawned.
Client

createVehicle

#
lib.createVehicle(model, x, y, z, h)

Loads the model, spawns a networked vehicle, places it on the ground and marks it as a mission entity. It waits until the vehicle exists, so call it from a thread.

lua
CreateThread(function()
    lib.createVehicle('wagon02x', -280.4, 780.2, 118.5, 10.0)
    local wagon = lib.getLastVehicle()
    SetVehicleDoorsLocked(wagon, 1)
end)
ArgumentTypeMeaning
modelstringVehicle model name.
xnumberX position.
ynumberY position.
znumberZ position.
hnumberHeading.
Client

getLastVehicle

#
lib.getLastVehicle()

Returns the vehicle made by the latest createVehicle call.

lua
local wagon = lib.getLastVehicle()
ReturnsnumberVehicle handle, or 0 if none was made yet.
Client

createBlip

#
lib.createBlip(text, x, y, z, sprite)

Puts a half-size map blip at a position. Blips made here are removed when jrs_core stops.

lua
lib.createBlip('Fishing spot', -1340.6, -1270.2, 40.3, 1595002520)
ArgumentTypeMeaning
textstringBlip name shown on the map.
xnumberX position.
ynumberY position.
znumberZ position.
spritenumberBlip sprite hash.
Client

deleteObj

#
lib.deleteObj(obj)

Deletes an object. For networked objects it asks for control first and gives up after about one second.

lua
lib.deleteObj(campfire)
ArgumentTypeMeaning
objnumberEntity handle.
Client

deletePed

#
lib.deletePed(obj)

Same as deleteObj but uses DeletePed, which is the right call for peds.

lua
lib.deletePed(guard)
ArgumentTypeMeaning
objnumberPed handle.
Client

playAnim

#
lib.playAnim(entity, dict, anim, flag, time)

Loads an animation dictionary and plays one clip on an entity. It waits for the dictionary, so run it in a thread.

lua
lib.playAnim(PlayerPedId(), 'mech_inventory@crafting@fallbacks', 'full_craft_and_stow', 1, 4000)
ArgumentTypeMeaning
entitynumberPed to animate.
dictstringAnimation dictionary.
animstringClip name.
flagnumberAnimation flag.
timenumberDuration in ms, -1 to loop.
Client

getAllPeds

#
lib.getAllPeds()

Lists every ped the client knows about.

lua
print(('%d peds nearby'):format(#lib.getAllPeds()))
ReturnstableArray of ped handles.
Client

getAllEntities

#
lib.getAllEntities()

Lists every object the client knows about. Despite the name it only covers objects, not peds or vehicles.

lua
for _, obj in ipairs(lib.getAllEntities()) do
    if GetEntityModel(obj) == `p_campfire01x` then print('fire at', GetEntityCoords(obj)) end
end
ReturnstableArray of object handles.
Client

getAllVehicles

#
lib.getAllVehicles()

Lists every vehicle the client knows about.

lua
local wagons = lib.getAllVehicles()
ReturnstableArray of vehicle handles.

Distance And Position#

Client

playerNearCoords

#
lib.playerNearCoords(x, y, z, dist, mark)

Tells you if the local player is close to a spot while on foot and alive. Riding a horse or sitting in a vehicle counts as not near.

lua
if lib.playerNearCoords(-322.2, 803.9, 117.9, 1.5, true) then
    lib.drawMe(-322.2, 803.9, 118.4, 'Store counter', 3.0)
end
ArgumentTypeMeaning
xnumberX position.
ynumberY position.
znumberZ position.
distnumberRange in metres.
markbooleanDraws a ground ring of the same size while the player is inside.
Returnsbooleantrue when the player is in range.
Client

checkPlayersNearEntity

#
lib.checkPlayersNearEntity(entity, distance)

Checks if any other player stands near an entity. The local player is ignored. Handy before spawning or deleting something others might see.

lua
if not lib.checkPlayersNearEntity(crate, 30.0) then lib.deleteObj(crate) end
ArgumentTypeMeaning
entitynumberEntity to measure from.
distancenumberRange in metres.
Returnsbooleantrue if another player is in range.
Client

groundCheck

#
lib.groundCheck(x, y)

Searches upward from height 1 to 1000 for the ground at a map position. The area must be loaded for a hit.

lua
local z = lib.groundCheck(-280.0, 790.0)
ArgumentTypeMeaning
xnumberX position.
ynumberY position.
ReturnsnumberGround height, or 0.0 when nothing was found.
Client

getTarget

#
lib.getTarget()

Returns what the gameplay camera is looking at, up to 5 metres away. The ray only runs while something asks for it, so call it every frame or so while you need it. The first call after a pause may return old values.

lua
local hitPos, hitEntity = lib.getTarget()
if hitEntity ~= 0 and IsEntityAPed(hitEntity) then
    lib.drawMe(hitPos.x, hitPos.y, hitPos.z + 0.3, 'Talk', 5.0)
end
Returnsvector3Hit position.
ReturnsnumberHit entity handle, 0 if none.
Returnsvector3End point of the ray.
Client

drawMe

#
lib.drawMe(x, y, z, text, dist, marker)

Draws a small 3D text label at a world position when the player is within dist. Call it every frame.

lua
CreateThread(function()
    while true do
        lib.drawMe(-322.2, 803.9, 118.4, 'Press Enter to shop', 3.0, true)
        Wait(0)
    end
end)
ArgumentTypeMeaning
xnumberX position.
ynumberY position.
znumberZ position.
textstringText to show.
distnumberMax distance to draw at.
markeranyAny value also draws a small ground ring under the text.
Client

IsPlayerInsidePolygon

#
lib.IsPlayerInsidePolygon(playerPos, polyPoints, debug, issmall)

Tests a position against a flat polygon (height is ignored). Use /polyPoint to record the corners in game.

lua
local farm = {
    vector3(-850.1, -1290.4, 43.5),
    vector3(-830.7, -1290.0, 43.5),
    vector3(-830.2, -1270.8, 43.6),
    vector3(-851.0, -1271.3, 43.6),
}
if lib.IsPlayerInsidePolygon(GetEntityCoords(PlayerPedId()), farm) then
    print('on the farm')
end
ArgumentTypeMeaning
playerPosvector3Position to test.
polyPointstableArray of vector3 corners in order.
debugbooleanDraws numbered posts at each corner.
issmallbooleanDraws thin posts instead.
Returnsbooleantrue when the position is inside.
Client

calculatePolygonLength

#
lib.calculatePolygonLength(polyPoints)

Adds up the length of every edge, including the edge from the last corner back to the first.

lua
print('fence needed: ' .. lib.calculatePolygonLength(farm) .. ' m')
ArgumentTypeMeaning
polyPointstableArray of vector3 corners.
ReturnsstringPerimeter in metres, formatted with two decimals.
Client

getPlayers

#
lib.getPlayers()

Lists the server ids of active players in client slots 0 to 32.

lua
for _, id in ipairs(lib.getPlayers()) do print(id) end
ReturnstableArray of server ids.
Client

getTime

#
lib.getTime()

Reads the in-game clock.

lua
local h = lib.getTime()
if h >= 22 or h < 5 then print('store closed') end
ReturnsnumberHours.
ReturnsnumberMinutes.
Client

fpsTimer

#
lib.fpsTimer()

Picks a short wait time from the current frame rate: lower FPS gives a longer wait. Only in the table from the jrs_lib:getApi event.

lua
Wait(lib.fpsTimer())
ReturnsnumberMilliseconds to wait, between 0 and 7.5.

Dialogs And Notices#

Client

notify

#
lib.notify(title, text, icon, duration)

Shows a notice to the local player. It goes through jrsCore:notify, so it uses the unified JRS toast when that is loaded and the lib's own popup otherwise.

lua
lib.notify('Fishing', 'You caught a bass.', 'bass', 4000)
ArgumentTypeMeaning
titlestringHeading.
textstringBody text.
iconstringItem image name, loaded from Config.Lib.FolderWithIcons in the fallback popup.
durationnumberTime on screen in ms, 3000 when left out.
Client

getInput

#
lib.getInput(title, subtext, cb)

Opens a one-line text box with mouse focus and waits for the player. It blocks the calling thread until they answer.

lua
lib.getInput('Letters only', 'Name your horse', function(value)
    if value == 'close' or value == '' then return end
    TriggerServerEvent('mystable:rename', value)
end)
ArgumentTypeMeaning
titlestringSmall hint text.
subtextstringMain heading of the box.
cbfunctionReceives the typed text, or the string 'close' if the player closed the box.
Client

getAnswer

#
lib.getAnswer(title, first, second, cb)

Opens a two-button question and waits for a choice. Blocks the calling thread like getInput.

lua
lib.getAnswer('Sell this wagon for $40?', 'Sell', 'Keep', function(yes)
    if yes then TriggerServerEvent('mywagon:sell') end
end)
ArgumentTypeMeaning
titlestringQuestion text.
firststringLabel of the yes button.
secondstringLabel of the no button.
cbfunctionReceives true for the first button and false for the second.
Client

getFolder

#
lib.getFolder()

Returns the icon folder from Config.Lib.FolderWithIcons. Only in the table from the jrs_lib:getApi event.

lua
local img = 'nui://' .. lib.getFolder() .. 'bread.png'
ReturnsstringFolder path, for example 'jrs_inventory/html/images/items/'.
Client

jrsCore:notify

#
TriggerClientEvent('jrsCore:notify', source, title, text, icon, duration)

The event behind every lib notice. Fire it from the server to reach one player, or with TriggerEvent on the client.

lua
TriggerClientEvent('jrsCore:notify', source, 'Bank', 'Your loan was paid off.', nil, 5000)
ArgumentTypeMeaning
titlestringHeading.
textstringBody text.
iconstringItem image name.
durationnumberTime on screen in ms.
Client

jrs_lib:createStash

#
TriggerEvent('jrs_lib:createStash', id, size)

Legacy stash event kept from the old resource. It forwards to stash events from another inventory style.

Warning

Nothing in JRS Core handles the events this one forwards to, so it opens nothing. Use the server helpers createStorage and openStorage on the player object instead.

ArgumentTypeMeaning
idstringStash id.
sizenumberWeight limit, multiplied by 1000.
Client

jrs_lib:openStash

#
TriggerEvent('jrs_lib:openStash', id, size)

Second legacy stash event, with the same limits as jrs_lib:createStash.

ArgumentTypeMeaning
idstringStash id.
sizenumberWeight limit, multiplied by 1000.

Server Helpers#

Get this table with exports.jrs_core:getLibServerApi(). Inventory calls are passed to jrs_inventory once it is started; before that they quietly do nothing.

Server

getInformation

#
libServer.getInformation(source, cb)

Builds a player object for one online player and passes it to your callback. The object wraps the active character and jrs_inventory in short method names, listed in the next section.

lua
local libServer = exports.jrs_core:getLibServerApi()

RegisterNetEvent('myshop:buyBread', function()
    local src = source
    libServer.getInformation(src, function(player)
        if not player then return end
        if player.getMoney() < 2 then
            libServer.notify(src, 'Store', 'Not enough cash.')
            return
        end
        player.removeMoney(2)
        player.addItem('bread', 1)
    end)
end)
ArgumentTypeMeaning
sourcenumberPlayer server id.
cbfunctionReceives the player object, or nil when the player has no loaded user.
Server

registerItem

#
libServer.registerItem(itemId, callback)

Makes an item usable by passing it to jrs_inventory's RegisterUsableItem.

lua
libServer.registerItem('canteen', function(data)
    TriggerClientEvent('mythirst:drink', data.source)
end)
ArgumentTypeMeaning
itemIdstringItem name.
callbackfunctionRuns when a player uses the item. It receives the data jrs_inventory sends.
Returnsbooleanfalse when jrs_inventory is not started yet.
Server

notify

#
libServer.notify(source, title, message, image, time)

Sends a jrsCore:notify notice to one player.

lua
libServer.notify(source, 'Sheriff', 'Your fine was paid.', nil, 4000)
ArgumentTypeMeaning
sourcenumberPlayer server id.
titlestringHeading.
messagestringBody text.
imagestringItem image name.
timenumberTime on screen in ms.
Server

sendDiscordMessage

#
libServer.sendDiscordMessage(webhookLink, title, description, color, steamHex, charIdentifier, firstName, lastName)

Posts an embed to a Discord webhook with two side fields: Steam id plus character id, and first plus last name.

lua
libServer.sendDiscordMessage(GetConvar('myshop_webhook', ''), 'Wagon sold',
    { 'Model: wagon02x', 'Price: $40' }, 15105570,
    player.getSteamIdentifier(), player.getCharIdentifier(),
    player.getFirstname(), player.getLastname())
ArgumentTypeMeaning
webhookLinkstringWebhook URL.
titlestringEmbed title.
descriptionstring|tableBody text, or an array of lines joined with new lines.
colornumberEmbed colour as a decimal number.
steamHexstringSteam identifier. The steam: prefix is cut off.
charIdentifiernumberCharacter id.
firstNamestringCharacter first name.
lastNamestringCharacter last name.
Server

getFramework

#
libServer.getFramework()

Lets shared scripts confirm which core they run on.

lua
if libServer.getFramework() == 'jrs_core' then print('running on JRS') end
ReturnsstringAlways 'jrs_core'.
Server

CharacterTable

#
libServer.CharacterTable()

Reads Config.Lib.CharacterTable. Scripts that build their own SQL can use these five readers instead of hard-coding names.

ReturnsstringDefaults to 'Characters'.
Server

JobColumn

#
libServer.JobColumn()

Reads Config.Lib.JobColumn.

ReturnsstringDefaults to 'job'.
Server

JobGradeColumn

#
libServer.JobGradeColumn()

Reads Config.Lib.JobGradeColumn.

ReturnsstringDefaults to 'jobgrade'.
Server

SteamColumn

#
libServer.SteamColumn()

Reads Config.Lib.SteamColumn.

ReturnsstringDefaults to 'identifier'.
Server

CharIdColumn

#
libServer.CharIdColumn()

Reads Config.Lib.CharIdColumn.

lua
local sql = ('SELECT %s FROM %s WHERE %s = ?'):format(
    libServer.JobColumn(), libServer.CharacterTable(), libServer.CharIdColumn())
ReturnsstringDefaults to 'charidentifier'.

Player Object#

Everything below is a method on the object passed to the getInformation callback. Methods take no source, because the object already knows its player. Values such as money are read from the character when you call the getter.

Character Data#

Server

getGroup

#
player.getGroup()

Reads the staff group of the user account.

ReturnsstringGroup name, for example 'user' or 'admin'.
Server

getFirstname

#
player.getFirstname()

Reads the character first name.

ReturnsstringFirst name.
Server

getLastname

#
player.getLastname()

Reads the character last name.

ReturnsstringLast name.
Server

getSteamIdentifier

#
player.getSteamIdentifier()

Reads the account identifier saved on the character.

ReturnsstringIdentifier such as 'steam:110000112345678'.
Server

getCharIdentifier

#
player.getCharIdentifier()

Reads the database id of the active character.

ReturnsnumberCharacter id.
Server

getJob

#
player.getJob()

Reads the active job name.

ReturnsstringJob name, 'unemployed' when none.
Server

getGrade

#
player.getGrade()

Reads the job grade from the jobGrade field of the character.

Warning

Character rows store the grade as jobgrade (lower case), so this can return nil. If it does, read the grade through the core object from exports.jrs_core:GetCore().

ReturnsnumberJob grade.
Server

setJob

#
player.setJob(job, grade, arg)

Changes the active job and grade through the core character setJob. The third value is passed along but the core ignores it.

lua
player.setJob('sheriff', 1)
ArgumentTypeMeaning
jobstringJob name.
gradenumberGrade.
arganyUnused.
Server

setGrade

#
player.setGrade(amount)

Meant to change only the job grade.

Warning

The character object in jrs_core has no setJobGrade method, so this call throws an error. Use player.setJob(player.getJob(), grade) instead.

ArgumentTypeMeaning
amountnumberNew grade.
Server

chanceSkin

#
player.chanceSkin(skin)

Saves a full clothing set for the character through jrs_clothing and reloads it on the player. The name is kept from the old resource.

lua
player.chanceSkin({ Hat = 0x1A2B3C4D, Coat = 0x5E6F7A8B })
ArgumentTypeMeaning
skintable|stringClothing table, or the same as a JSON string.
Returnsbooleantrue when jrs_clothing saved it; false if jrs_clothing is not started.

Money#

Server

getMoney

#
player.getMoney()

Reads the cash balance.

ReturnsnumberCash.
Server

addMoney

#
player.addMoney(amount)

Gives cash.

lua
player.addMoney(12.5)
ArgumentTypeMeaning
amountnumberAmount to add.
Server

removeMoney

#
player.removeMoney(amount)

Takes cash. Check getMoney() first; this does not check the balance for you.

ArgumentTypeMeaning
amountnumberAmount to take.
Server

getGold

#
player.getGold()

Reads the gold balance.

ReturnsnumberGold.
Server

addGold

#
player.addGold(amount)

Gives gold.

ArgumentTypeMeaning
amountnumberAmount to add.
Server

removeGold

#
player.removeGold(amount)

Takes gold.

lua
if player.getGold() >= 5 then player.removeGold(5) end
ArgumentTypeMeaning
amountnumberAmount to take.

Items And Weapons#

Server

getCountItem

#
player.getCountItem(id)

Counts how many of an item the player holds.

lua
if player.getCountItem('pickaxe') == 0 then return end
ArgumentTypeMeaning
idstringItem name.
ReturnsnumberCount, 0 when jrs_inventory is not started.
Server

addItem

#
player.addItem(id, amount, metadata)

Gives an item through jrs_inventory.

lua
player.addItem('letter', 1, { description = 'Sealed letter for the mayor' })
ArgumentTypeMeaning
idstringItem name.
amountnumberHow many.
metadatatableExtra data saved on the item.
Server

removeItem

#
player.removeItem(id, amount)

Takes items by name.

ArgumentTypeMeaning
idstringItem name.
amountnumberHow many.
Server

removeItemId

#
player.removeItemId(id, amount)

Takes items from one exact stack by its inventory id, which matters when stacks carry different metadata.

ArgumentTypeMeaning
idnumberInventory item id.
amountnumberHow many.
Server

canCarryItem

#
player.canCarryItem(id, count)

Asks jrs_inventory whether the item fits.

lua
if player.canCarryItem('coal', 10) then player.addItem('coal', 10) end
ArgumentTypeMeaning
idstringItem name.
countnumberHow many.
Returnsbooleantrue when there is room.
Server

canCarryWeapon

#
player.canCarryWeapon(_, count)

Asks jrs_inventory whether more weapons fit. The first argument is ignored.

ArgumentTypeMeaning
_anyUnused, pass nil.
countnumberNumber of weapons.
Returnsbooleantrue when there is room.
Server

createWeapon

#
player.createWeapon(weapon, ammo)

Creates a new weapon in the player's inventory.

lua
if player.canCarryWeapon(nil, 1) then
    player.createWeapon('WEAPON_REVOLVER_CATTLEMAN', { AMMO_REVOLVER = 12 })
end
ArgumentTypeMeaning
weaponstringWeapon name such as 'WEAPON_REVOLVER_CATTLEMAN'.
ammotableStarting ammo, passed straight to jrs_inventory.
Server

giveWeapon

#
player.giveWeapon(id, playerId)

Moves an existing weapon to a player.

ArgumentTypeMeaning
idnumberWeapon id.
playerIdnumberServer id of the receiver.
Server

getInventory

#
player.getInventory()

Returns the player's items from jrs_inventory.

lua
for _, item in pairs(player.getInventory()) do print(item.name, item.count) end
ReturnstableItem list, empty when jrs_inventory is not started.
Server

getItemNames

#
player.getItemNames()

Reads every row of the jrs_items table. The query runs async and the method waits only 100 ms, so on a slow database it may return an empty table.

ReturnstableRows from jrs_items.
Server

getMetadata

#
player.getMetadata(id)

Meant to read one metadata key from the last item the player used.

Warning

It relies on getLastUsedID, which the current jrs_inventory does not provide, so the call fails. Read metadata from the data your usable item callback receives instead.

ArgumentTypeMeaning
idstringMetadata key.
ReturnsanyMetadata value, then the item id.
Server

closeInv

#
player.closeInv()

Closes the inventory screen on the player's client.

Storage And Logs#

Server

createStorage

#
player.createStorage(id, size)

Registers a storage container in jrs_inventory for this player.

lua
player.createStorage('cabin_' .. player.getCharIdentifier(), 100)
player.openStorage('cabin_' .. player.getCharIdentifier(), 'Cabin chest')
ArgumentTypeMeaning
idstringStorage id.
sizenumberStorage size limit.
Server

openStorage

#
player.openStorage(id, label)

Opens a registered storage on the player's screen.

ArgumentTypeMeaning
idstringStorage id.
labelstringTitle shown on the window.
Server

updateStorage

#
player.updateStorage(id, size)

Changes the size of a registered storage, for example after an upgrade.

ArgumentTypeMeaning
idstringStorage id.
sizenumberNew size limit.
Server

discord

#
player.discord(webhookLink, title, description, color, steamHex, charIdentifier, firstName, lastName)

Same as sendDiscordMessage, reachable from the player object. You still pass the player fields yourself.

ArgumentTypeMeaning
webhookLinkstringWebhook URL.
titlestringEmbed title.
descriptionstring|tableBody text or lines.
colornumberEmbed colour.
steamHexstringSteam identifier.
charIdentifiernumberCharacter id.
firstNamestringFirst name.
lastNamestringLast name.

Developer Commands#

Both commands are client side and are registered while Config.Lib.EnableDevCommands is on.

Command What it does
/polyPoint Starts tracing a polygon at your feet. Press the bound key to add a corner where you stand; the corner list is copied through the NUI. Run it again to stop and clear.
/target Toggles a dot that shows where the camera ray ends, the same ray getTarget reads.