JRS COREDocs

Core object

Every function on the table returned by exports.jrs_core:getCoreApi(), on the server and on the client.

Three things decide whether a call into jrs_core works: the player must have a character loaded (money, item and XP calls are refused until IsCharacterReady is true), server round trips go through a rate-limited RPC path (30 calls a second per player, 64 KB payloads, 10 second timeout, see Callbacks), and every getCoreApi() call builds a brand new table, so it belongs at file level and not inside a handler. The badge on each card shows which side owns the function.

Many functions are also plain exports, such as exports.jrs_core:AddMoney(source, 5), which is handy in a one-off line where you do not want to keep the table. The cards list those exports.

First Lines Of A Script#

Shared

getCoreApi

#
exports.jrs_core:getCoreApi()

Builds the core table for the side it runs on: characters, money, jobs, XP, items, notifications and RPC on the server; screen, dialogs, helpers and RPC on the client. GetCoreObject is the same export under a second name.

lua
-- server/main.lua of a ranch script
local JRS = exports.jrs_core:getCoreApi()   -- once, at file level

RegisterNetEvent('my_ranch:milk', function()
    local src = source
    if not JRS.IsCharacterReady(src) then return end
    JRS.AddReward(src, 0, 0.75, 'ranch')   -- scaled by Config.Economy
end)
ReturnstableA new server or client table on every call.

Player Character#

Server functions that read the character a player is playing right now. Most of them return nil until the player has picked a character, so check IsCharacterReady first in code that runs early.

Server

IsCharacterReady

#
JRS.IsCharacterReady(source)

Tells you whether the player has a character loaded. Money, item and XP calls are refused while this is false. IsIdentityReady is the same function.

lua
RegisterNetEvent('my_ranch:collect', function()
    local src = source
    if not JRS.IsCharacterReady(src) then return end
    JRS.AddMoney(src, 3)
end)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsbooleantrue once a character is selected and loaded.
Server

GetCharacter

#
JRS.GetCharacter(source)

Returns the live character object that jrs_core keeps in memory. Changes you make to it are real, so prefer GetCharacterData when you only want to read.

lua
local char = JRS.GetCharacter(source)
if char then
    print(char.firstname, char.job, char.money)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnstable | nilThe character object, or nil when no character is ready.
Server

GetCharacterData

#
JRS.GetCharacterData(source)

Returns a plain copy of the main character fields. Safe to read, log or send to the client. Also exports.jrs_core:GetCharacterData(source).

lua
local data = JRS.GetCharacterData(source)
if data and data.group == 'admin' then
    print(('%s %s is staff'):format(data.firstname, data.lastname))
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnstable | nilsource, identifier, charIdentifier, charid, firstname, lastname, job, jobGrade, group, money, gold, rol, dirtymoney, xp.
Server

GetCharacterName

#
JRS.GetCharacterName(source)

Gives the character first and last name joined by a space. When both are empty it uses the player account name instead. Also exports.jrs_core:GetCharacterName(source).

lua
local name = JRS.GetCharacterName(source) or 'Stranger'
JRS.NotifyRightTip(source, ('Welcome back, %s'):format(name), 4000)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsstring | nilThe name, or nil when no character is ready.
Server

GetCharacterState

#
JRS.GetCharacterState(source)

Reads the load state jrs_core tracks for the player, for code that needs more detail than true or false.

lua
local state = JRS.GetCharacterState(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnsanyThe state record kept by jrs_core.
Server

GetUser

#
JRS.GetUser(source)

Returns the user object for the player account, the same one getUser gives on the core page. getUser is the lower case name.

lua
local user = JRS.GetUser(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnstable | nilThe user object.
Server

GetIdentifiers

#
JRS.GetIdentifiers(source)

Collects the player identifiers into a table keyed by type.

lua
local ids = JRS.GetIdentifiers(source)
print(ids.license)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnstableFor example { steam = 'steam:...', license = 'license:...', discord = 'discord:...' }.
Server

SaveCharacter

#
JRS.SaveCharacter(source)

Writes the loaded character to the database now: name, job, duty, jobs list, skills and metadata. Also exports.jrs_core:SaveCharacter(source).

lua
JRS.Metadata.Set(source, 'bounty', 0)
JRS.SaveCharacter(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsbooleanfalse when the player has no loaded character.

Short Getters#

These older one-line readers are still on the server table. They read the cached player record and return nil when it is missing.

Function Returns
JRS.loaded(source) true when the player record exists
JRS.getIdentifier(source) account identifier
JRS.getCharacterIdentifier(source) character id
JRS.getFirstName(source) / JRS.getLastName(source) name parts
JRS.getGender(source) / JRS.getDob(source) gender and date of birth
JRS.getJob(source) / JRS.getJobGrade(source) active job and grade
JRS.getClan(source) clan value
JRS.GetPlayers() { players = { { source = id } }, count = n } for every loaded player
JRS.GetJobPlayers(job) same shape, only players with that active job

Any Character#

Server functions that look up characters by id, account or name. They work for offline characters too.

Server

GetCharacterById

#
JRS.GetCharacterById(charId)

Loads one character by its character id. Also exports.jrs_core:GetCharacterById(charId).

lua
local row = JRS.GetCharacterById(42)
if row then print(row.firstname, row.lastname) end
ArgumentTypeMeaning
charIdnumberCharacter id.
Returnstable | nilThe character row.
Server

GetOfflineCharacter

#
JRS.GetOfflineCharacter(charId)

Reads a character straight from the database, even when its owner is online.

lua
local row = JRS.GetOfflineCharacter(42)
ArgumentTypeMeaning
charIdnumberCharacter id.
Returnstable | nilThe stored row.
Server

GetCharactersByIdentifier

#
JRS.GetCharactersByIdentifier(identifier)

Lists every character that belongs to one account.

lua
local list = JRS.GetCharactersByIdentifier(JRS.getIdentifier(source))
print(('%d characters on this account'):format(#list))
ArgumentTypeMeaning
identifierstringAccount identifier, for example a steam: or license: value.
ReturnstableArray of character rows, empty when none.
Server

FindCharactersByName

#
JRS.FindCharactersByName(firstname, lastname?)

Searches characters by name, for wanted posters, registries and admin tools. Also exports.jrs_core:FindCharactersByName(firstname, lastname).

lua
local rows = JRS.FindCharactersByName('Ezra', 'Calloway')
ArgumentTypeMeaning
firstnamestringFirst name to search.
lastnamestringLast name to narrow the search.
ReturnstableArray of matching rows.
Server

GetCharacterCount

#
JRS.GetCharacterCount(source)

Counts the characters on the player account.

lua
local count = JRS.GetCharacterCount(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnsnumberNumber of characters.
Server

GetMaxCharacters

#
JRS.GetMaxCharacters(source)

Returns how many characters this player may have. Falls back to Config.Char_Count.

lua
local slots = JRS.GetMaxCharacters(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnsnumberThe slot limit.
Server

CanCreateCharacter

#
JRS.CanCreateCharacter(source)

Checks the count against the limit for you.

lua
if not JRS.CanCreateCharacter(source) then
    JRS.NotifyRightTip(source, 'No free character slot', 4000)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsbooleantrue when a free slot is left.

Money#

All money functions run on the server and refuse to work until IsCharacterReady is true. Amounts must be above zero.

Currency id Balance field
0 money (cash)
1 gold
2 rol
3 dirtymoney
Server

AddMoney

#
JRS.AddMoney(source, amount)

Gives cash. Use it for transfers, refunds and admin grants. For job pay use AddReward so the economy scale applies. Also exports.jrs_core:AddMoney(source, amount).

lua
JRS.AddMoney(source, 12.5)
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberCash to add.
Returnsbooleantrue when the cash was added.
Server

RemoveMoney

#
JRS.RemoveMoney(source, amount)

Takes cash. Nothing is taken when the player has less than amount. Also exports.jrs_core:RemoveMoney(source, amount).

lua
if not JRS.RemoveMoney(source, 4) then
    JRS.NotifyRightTip(source, 'You cannot afford that', 3000)
    return
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberCash to take.
Returnsbooleanfalse when the player is short or not ready.
Server

AddGold

#
JRS.AddGold(source, amount)

Gives gold bars. Also exports.jrs_core:AddGold(source, amount).

lua
JRS.AddGold(source, 0.5)
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberGold to add.
Returnsbooleantrue on success.
Server

RemoveGold

#
JRS.RemoveGold(source, amount)

Takes gold bars. Also exports.jrs_core:RemoveGold(source, amount).

lua
local paid = JRS.RemoveGold(source, 2)
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberGold to take.
Returnsbooleanfalse when the player is short.
Server

AddGoldNuggets

#
exports.jrs_core:AddGoldNuggets(source, count)

Converts nuggets into gold at 100 nuggets per gold bar, rounded to two decimals, and adds the result. Export only.

lua
exports.jrs_core:AddGoldNuggets(source, 35) -- adds 0.35 gold
ArgumentTypeMeaning
sourcenumberPlayer server id.
countnumberNumber of nuggets.
Returnsbooleantrue on success, also when the count rounds down to nothing.
Server

AddDirtyMoney

#
JRS.AddDirtyMoney(source, amount)

Gives dirty money (currency 3). Also exports.jrs_core:AddDirtyMoney(source, amount).

lua
JRS.AddDirtyMoney(source, 40)
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberAmount to add.
Returnsbooleantrue on success.
Server

RemoveDirtyMoney

#
JRS.RemoveDirtyMoney(source, amount)

Takes dirty money. Also exports.jrs_core:RemoveDirtyMoney(source, amount).

lua
JRS.RemoveDirtyMoney(source, 40)
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberAmount to take.
Returnsbooleanfalse when the player is short.
Server

GetDirtyMoney

#
JRS.GetDirtyMoney(source)

Reads the dirty money balance.

lua
local dirty = JRS.GetDirtyMoney(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnsnumberThe balance, 0 when no character is ready.
Server

GetBalance

#
JRS.GetBalance(source)

Reads every currency at once. Also exports.jrs_core:GetBalance(source).

lua
local bal = JRS.GetBalance(source)
print(('cash %.2f, gold %.2f'):format(bal.money, bal.gold))
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnstablemoney, gold, rol, dirtymoney and blackmoney (same value as dirtymoney). All zero when no character is ready.
Server

addMoney

#
JRS.addMoney(source, currency, amount)

The generic adder behind the helpers above. Pick the currency with its id.

lua
JRS.addMoney(source, 2, 1) -- one rol
ArgumentTypeMeaning
sourcenumberPlayer server id.
currencynumberCurrency id from the table above.
amountnumberAmount to add.
Returnsbooleantrue on success.
Server

removeMoney

#
JRS.removeMoney(source, currency, amount)

The generic remover. Fails without taking anything when the balance is too low.

lua
local ok = JRS.removeMoney(source, 0, 7.5)
ArgumentTypeMeaning
sourcenumberPlayer server id.
currencynumberCurrency id.
amountnumberAmount to take.
Returnsbooleantrue on success.

Rewards#

Server

AddReward

#
JRS.AddReward(source, currency, amount, reason?)

Pays a gameplay reward. The amount is first scaled with Config.Economy (see ScaleReward). For cash, the player level bonus and job pay perk are added on top, and job item drops from Config.JobItemDrops may roll for the given reason. Use this for every job, mission or sale payout.

lua
RegisterNetEvent('my_fishing:sell', function(fishCount)
    local src = source
    JRS.AddReward(src, 0, 0.8 * fishCount, 'fishing')
end)
ArgumentTypeMeaning
sourcenumberPlayer server id.
currencynumber0 for cash or 1 for gold.
amountnumberBase amount before scaling.
reasonstringJob or payout key. Needed for job pay perks and item drops.
Returnsbooleantrue when something was paid.
Server

ScaleReward

#
JRS.ScaleReward(amount, currency?)

Shows what a base amount becomes after the economy scale, without paying. Gold uses GoldMultiplier, everything else RewardMultiplier, and the result never drops below MinReward. With Config.Economy.Enabled = false the amount is only rounded.

lua
local shown = JRS.ScaleReward(10, 0)
JRS.NotifyRightTip(source, ('This job pays about $%.2f'):format(shown), 4000)
ArgumentTypeMeaning
amountnumberBase amount.
currencynumber1 for gold, anything else for cash.
ReturnsnumberThe scaled amount, 0 for amounts of zero or less.
Server

RollJobItemDrops

#
JRS.RollJobItemDrops(source, jobKey)

Rolls the extra crafting items listed for jobKey in Config.JobItemDrops and adds them through jrs_inventory. AddReward already calls it for cash payouts, so call it yourself only when you pay in another way. Available on the newer server build.

lua
JRS.RollJobItemDrops(source, 'lumberjack')
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobKeystringJob key used in the config.

Level Perks#

Higher levels unlock discounts and bonuses. These are direct exports; run your price through them before you charge or pay.

Server

ApplyShopDiscount

#
exports.jrs_core:ApplyShopDiscount(source, amount)

Lowers a shop price by the player shop discount. The price never goes under 0.01.

lua
local price = exports.jrs_core:ApplyShopDiscount(source, 25)
if JRS.RemoveMoney(source, price) then
    JRS.AddItem(source, 'canned_beans', 1)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberFull price.
Returnsnumber, number, numberFinal price, amount saved, discount rate.
Server

ApplySellBonus

#
exports.jrs_core:ApplySellBonus(source, amount)

Raises a sell payout by the player sell bonus.

lua
local payout = exports.jrs_core:ApplySellBonus(source, 6)
JRS.AddMoney(source, payout)
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberBase payout.
Returnsnumber, number, numberFinal payout, bonus added, bonus rate.
Server

ApplyTaxReduction

#
exports.jrs_core:ApplyTaxReduction(source, tax)

Cuts a tax amount by the player tax reduction.

lua
local tax = exports.jrs_core:ApplyTaxReduction(source, 3)
ArgumentTypeMeaning
sourcenumberPlayer server id.
taxnumberTax before the reduction.
Returnsnumber, number, numberTax to charge, amount removed, reduction rate.
Server

GetCarryCapacity

#
exports.jrs_core:GetCarryCapacity(source)

Returns the carry weight the player level grants.

lua
local kg = exports.jrs_core:GetCarryCapacity(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsnumber | nilCapacity in kg, nil when perks are not loaded.

Jobs And Duty#

Server

setJob

#
JRS.setJob(source, job, grade?)

Sets the active job and grade. The grade defaults to the current one. For calls from other resources the direct export exports.jrs_core:SetJob(source, job, grade) is the safer path; it also checks the character is ready and tells the client.

lua
local ok, why = exports.jrs_core:SetJob(source, 'sheriff', 1)
if not ok then print('job change failed:', why) end
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringJob name.
gradenumberJob grade.
Returnsboolean, string?true, or false and a reason.
Server

setJobGrade

#
JRS.setJobGrade(source, grade)

Changes only the grade, keeping the same job.

lua
JRS.setJobGrade(source, 3)
ArgumentTypeMeaning
sourcenumberPlayer server id.
gradenumberNew grade.
Returnsboolean, string?true, or false and a reason.

The JRS.Jobs group covers players who hold several jobs. Only one is active at a time. The same functions exist as direct exports: GetJobs, AddJob, RemoveJob, SwitchJob, SetDuty, ToggleDuty, GetDutyPlayers.

Server

Jobs.Get

#
JRS.Jobs.Get(source)

Lists the jobs the character holds. The active job is always in the list.

lua
for name, info in pairs(JRS.Jobs.Get(source)) do
    print(name, info.grade, info.label)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnstableKeyed by job name: { grade = number, label = string }.
Server

Jobs.Add

#
JRS.Jobs.Add(source, job, grade?, label?)

Adds a job to the list or updates its grade and label. It does not make it active. MaxJobs in config/character_service.lua caps the list; 0 means no cap.

lua
JRS.Jobs.Add(source, 'doctor', 0, 'Town Doctor')
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringJob name.
gradenumberGrade, default 0.
labelstringDisplay name, default the job name.
Returnsboolean, string?true, or false with 'invalid_job' or 'max_jobs'.
Server

Jobs.Remove

#
JRS.Jobs.Remove(source, job)

Removes a job from the list. The active job cannot be removed.

lua
JRS.Jobs.Remove(source, 'doctor')
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringJob name.
Returnsboolean, string?true, or false with 'active_job' or 'not_found'.
Server

Jobs.Switch

#
JRS.Jobs.Switch(source, job)

Makes a held job the active one, with its saved grade. Respects JobSwitchCooldownSeconds and puts the player off duty.

lua
local ok, why = JRS.Jobs.Switch(source, 'doctor')
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringA job from the list.
Returnsboolean, string?true, or false with 'job_not_owned', 'cooldown' or another reason.
Server

Jobs.SetDuty

#
JRS.Jobs.SetDuty(source, onDuty)

Sets duty on or off, saves it and updates the OnDuty state bag. Fires jrs_core:server:dutyChanged on the server and jrs_core:client:dutyChanged on that client.

lua
JRS.Jobs.SetDuty(source, true)
ArgumentTypeMeaning
sourcenumberPlayer server id.
onDutybooleanNew duty state.
Returnsbooleanfalse when no character is loaded.
Server

Jobs.ToggleDuty

#
JRS.Jobs.ToggleDuty(source)

Flips duty.

lua
local nowOnDuty = JRS.Jobs.ToggleDuty(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnsbooleanThe new duty state.
Server

Jobs.GetDutyPlayers

#
JRS.Jobs.GetDutyPlayers(job)

Finds online players who have this job active and are on duty.

lua
local sheriffs, count = JRS.Jobs.GetDutyPlayers('sheriff')
for _, id in ipairs(sheriffs) do
    JRS.NotifyRightTip(id, 'Robbery at the Valentine bank', 6000)
end
ArgumentTypeMeaning
jobstringJob name.
Returnstable, numberArray of server ids, and the count.

Groups And Permissions#

Server

GetGroup

#
JRS.GetGroup(source)

Reads the account permission group, such as user or admin. Also exports.jrs_core:GetGroup(source).

lua
local group = JRS.GetGroup(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsstring | nilThe group.
Server

SetGroup

#
JRS.SetGroup(source, group, callback?)

Changes the account group and saves it. Server only on purpose: clients can never set a group.

lua
JRS.SetGroup(target, 'moderator')
ArgumentTypeMeaning
sourcenumberPlayer server id.
groupstringNew group.
callbackfunctionRuns when the save finishes.
Server

RefreshGroup

#
JRS.RefreshGroup(source, callback?)

Reloads the group from the database, for example after another tool changed it.

lua
JRS.RefreshGroup(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
callbackfunctionRuns after the reload.
Server

IsAdmin

#
exports.jrs_core:IsAdmin(source)

Checks the group against the admin groups in the jrs_core config. Source 0 (the server console) always passes.

lua
if not exports.jrs_core:IsAdmin(source) then return end
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsbooleantrue for admin groups.
Server

CanUseCommand

#
exports.jrs_core:CanUseCommand(source, commandKey)

Asks the jrs_core permission table whether this group may use a command. Use it instead of writing your own group checks.

lua
RegisterCommand('bounty', function(src, args)
    if not exports.jrs_core:CanUseCommand(src, 'bounty') then return end
    -- ...
end)
ArgumentTypeMeaning
sourcenumberPlayer server id.
commandKeystringCommand key from the config.
Returnsbooleantrue when allowed.

Character Level#

The character level runs from 1 to 100. The XP needed per level lives in config/levels.lua. Every write function takes an optional reason, written to the logs, and an optional callback(success, newData, oldData, changedAmount, errorCode) that runs when the change is saved. Each name also has lower case aliases such as addXP and addxp.

Server

AddXP

#
JRS.AddXP(source, amount, reason?, callback?)

Adds XP. Double XP events, the server tag bonus and personal boosts are applied here, capped by the limits in the double XP config. Reasons starting with admin or refund skip the cap. Also exports.jrs_core:AddXP(...).

lua
JRS.AddXP(source, 15, 'bounty_turned_in', function(ok, data)
    if ok then print('now level', data.level) end
end)
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberXP to add, whole number above 0.
reasonstringLog reason.
callbackfunctionRuns after the save.
Returnsbooleanfalse right away for an invalid amount.
Server

RemoveXP

#
JRS.RemoveXP(source, amount, reason?, callback?)

Takes XP away. Boosts are not applied.

lua
JRS.RemoveXP(source, 50, 'admin_correction')
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberXP to remove.
Server

SetXP

#
JRS.SetXP(source, amount, reason?, callback?)

Sets total XP to an exact value.

lua
JRS.SetXP(source, 0, 'admin_reset')
ArgumentTypeMeaning
sourcenumberPlayer server id.
amountnumberNew total XP.
Server

GetXP

#
JRS.GetXP(source)

Reads the level data. It waits for the database, so call it inside a thread or event handler.

lua
local xp = JRS.GetXP(source)
if xp then print(xp.totalXp, xp.level) end
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnstable | niltotalXp, level, currentXp, requiredXp, progress, isMaxLevel.
Server

GetLevel

#
JRS.GetLevel(source)

Returns just the level number, plus the full data as a second value.

lua
if JRS.GetLevel(source) < 10 then
    JRS.NotifyRightTip(source, 'You need level 10 for this', 4000)
    return
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsnumber, tableLevel (1 or more) and the same table as GetXP.
Server

SetLevel

#
JRS.SetLevel(source, level, reason?, callback?)

Moves the player to a level by setting total XP to the start of it. The level is clamped between 1 and the max level.

lua
JRS.SetLevel(source, 25, 'admin_event_prize')
ArgumentTypeMeaning
sourcenumberPlayer server id.
levelnumberTarget level.
Server

AddLevel

#
JRS.AddLevel(source, levels, reason?, callback?)

Raises the level by a number of levels.

lua
JRS.AddLevel(source, 1, 'admin_gift')
ArgumentTypeMeaning
sourcenumberPlayer server id.
levelsnumberLevels to add.
Server

RemoveLevel

#
JRS.RemoveLevel(source, levels, reason?, callback?)

Lowers the level by a number of levels.

lua
JRS.RemoveLevel(source, 1, 'admin_penalty')
ArgumentTypeMeaning
sourcenumberPlayer server id.
levelsnumberLevels to remove.
Server

GetLevelData

#
JRS.GetLevelData(totalXp)

Pure math: turns a total XP number into level data. No player needed.

lua
local info = JRS.GetLevelData(12000)
print(info.level, info.progress)
ArgumentTypeMeaning
totalXpnumberTotal XP.
ReturnstableSame fields as GetXP.
Server

GetTotalXpForLevel

#
JRS.GetTotalXpForLevel(level)

Total XP a character needs to reach a level.

lua
local need = JRS.GetTotalXpForLevel(50)
ArgumentTypeMeaning
levelnumberTarget level.
ReturnsnumberTotal XP.

Job Level#

Every job or script keeps its own level from 1 to 100, separate from the character level. Each award also feeds a share into the character level.

Server

AddJobXP

#
JRS.AddJobXP(source, job, amount, reason?, callback?)

Adds XP to one job.

lua
JRS.AddJobXP(source, 'mining', 8, 'iron_ore')
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringJob or script key, for example 'mining'.
amountnumberXP to add.
Server

RemoveJobXP

#
JRS.RemoveJobXP(source, job, amount, reason?, callback?)

Removes XP from one job.

lua
JRS.RemoveJobXP(source, 'mining', 8, 'admin_fix')
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringJob key.
amountnumberXP to remove.
Server

SetJobXP

#
JRS.SetJobXP(source, job, amount, reason?, callback?)

Sets one job XP total.

lua
JRS.SetJobXP(source, 'mining', 0, 'admin_reset')
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringJob key.
amountnumberNew total.
Server

GetJobXP

#
JRS.GetJobXP(source, job)

Reads one job XP. Waits for the database. Also an export.

lua
local xp = JRS.GetJobXP(source, 'fishing')
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringJob key.
ReturnsnumberJob XP.
Server

GetJobLevel

#
JRS.GetJobLevel(source, job)

Reads one job level. Also an export.

lua
if JRS.GetJobLevel(source, 'fishing') >= 20 then
    JRS.AddItem(source, 'fishing_lure_rare', 1)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringJob key.
ReturnsnumberLevel, 1 when nothing is stored.
Server

GetJobLevelData

#
JRS.GetJobLevelData(source, job)

Reads the full level table for one job. Also an export.

lua
local data = JRS.GetJobLevelData(source, 'hunting')
ArgumentTypeMeaning
sourcenumberPlayer server id.
jobstringJob key.
ReturnstableLevel data, at least { level = 1 }.
Server

GetAllJobLevels

#
JRS.GetAllJobLevels(source)

Reads every job level the character has. Also an export.

lua
local rows = JRS.GetAllJobLevels(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnstableOne row per job.

Items#

These server wrappers call jrs_inventory for you. When the inventory is not started they fail softly (false, 0 or an empty table) instead of throwing. The calling resource is passed along for the inventory logs. The inventory page covers the full inventory export list.

Server

AddItem

#
JRS.AddItem(source, item, count, metadata?)

Gives an item. Also exports.jrs_core:InventoryAddItem(...).

lua
if JRS.CanCarryItem(source, 'bread', 2) then
    JRS.AddItem(source, 'bread', 2)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemstringItem name.
countnumberHow many.
metadatatableExtra data stored on the item.
Returnsboolean, string?, table?Success, then the inventory reason and details when it failed.
Server

RemoveItem

#
JRS.RemoveItem(source, item, count)

Takes items by name. Also exports.jrs_core:InventoryRemoveItem(...).

lua
local ok, why = JRS.RemoveItem(source, 'wood', 5)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemstringItem name.
countnumberHow many.
Returnsboolean, string?, table?Success, reason, details.
Server

RemoveItemById

#
JRS.RemoveItemById(source, itemId, count)

Takes from one exact stack, useful for items with metadata. Also exports.jrs_core:InventoryRemoveItemById(...).

lua
JRS.RemoveItemById(source, slot.id, 1)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberInventory item id.
countnumberHow many.
Returnsboolean, string?, table?Success, reason, details.
Server

GetItemCount

#
JRS.GetItemCount(source, item)

Counts an item across the player inventory. Also exports.jrs_core:InventoryGetItemCount(...).

lua
local pelts = JRS.GetItemCount(source, 'pelt_fox')
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemstringItem name.
ReturnsnumberThe count, 0 when none.
Server

CanCarryItem

#
JRS.CanCarryItem(source, item, count)

Checks weight and limits before you give something. Also exports.jrs_core:InventoryCanCarryItem(...).

lua
if not JRS.CanCarryItem(source, 'iron_ore', 3) then
    JRS.NotifyRightTip(source, 'Your bag is full', 3000)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemstringItem name.
countnumberHow many.
Returnsbooleantrue when it fits.
Server

GetInventory

#
JRS.GetInventory(source)

Returns the whole player inventory. Also exports.jrs_core:InventoryGet(source).

lua
local items = JRS.GetInventory(source)
print(json.encode(items))
ArgumentTypeMeaning
sourcenumberPlayer server id.
ReturnstableItem list, empty when unavailable.
Server

GetInventoryItemById

#
JRS.GetInventoryItemById(source, itemId)

Reads one stack by its id. Also exports.jrs_core:InventoryGetItemById(...).

lua
local item = JRS.GetInventoryItemById(source, 1201)
ArgumentTypeMeaning
sourcenumberPlayer server id.
itemIdnumberInventory item id.
Returnstable | nilThe item entry.
Server

IsInventoryReady

#
JRS.IsInventoryReady()

Tells you if jrs_inventory is started. Also an export.

lua
if not JRS.IsInventoryReady() then return end
Returnsbooleantrue when it is running.
Server

GetInventoryApi

#
JRS.GetInventoryApi()

Returns the full jrs_inventory API table, for functions the wrappers here do not cover.

lua
local Inv = JRS.GetInventoryApi()
Returnstable | nilThe inventory API, nil when it is not started.

JRS.Inventory groups the same wrappers (IsReady, GetApi, Get, GetItemById, GetItemCount, AddItem, RemoveItem, RemoveItemById, CanCarry) and adds three more:

Server

Inventory.Transaction

#
JRS.Inventory.Transaction(source, operations, context?)

Runs a list of add and remove steps as one unit: if any step fails, the earlier ones are rolled back. Up to 64 steps. Calls exports.jrs_inventory:InventoryTransaction.

lua
local ok, why = JRS.Inventory.Transaction(source, {
    { type = 'remove', item = 'wood', amount = 4 },
    { type = 'add', item = 'plank', amount = 2 },
}, { owner = 'my_sawmill' })
if not ok then
    JRS.NotifyRightTip(source, 'Crafting failed: ' .. tostring(why), 4000)
end
ArgumentTypeMeaning
sourcenumberPlayer server id.
operationstableSteps like { type = 'add' | 'remove', item = name, amount = n, metadata? = table }. Amounts must be whole numbers.
contexttableowner for logs and id for the transaction id.
Returnsboolean, string?, tableSuccess, failure reason, step details.
Server

Inventory.RegisterHook

#
JRS.Inventory.RegisterHook(eventName, name, callback)

Runs your function after inventory changes. Calls exports.jrs_inventory:RegisterInventoryHook. Events include itemAdded, itemRemoved, transactionCommitted and transactionRolledBack. Registering the same name again replaces the old handler.

lua
JRS.Inventory.RegisterHook('itemAdded', 'my_logger', function(payload)
    print(payload.source, 'got', payload.amount, payload.item)
end)
ArgumentTypeMeaning
eventNamestringInventory hook event.
namestringYour unique hook name.
callbackfunctionReceives one payload table, for items source, item, amount, metadata, sourceResource.
Returnsbooleantrue when registered, false when the inventory is not started.
Server

Inventory.GetFreeWeight

#
JRS.Inventory.GetFreeWeight(source)

Reads how much weight is left.

lua
local free = JRS.Inventory.GetFreeWeight(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsnumber, number, numberValues from jrs_inventory, all 0 when it is not started.

JRS.Trade on the server offers IsTrading(source), GetSession(source) and RegisterValidator(name, callback), all passed to the matching jrs_inventory trade exports.

Metadata, Skills And Appearance#

Server

Metadata.Get

#
JRS.Metadata.Get(source, key, default?)

Reads a value from the character metadata store.

lua
local wanted = JRS.Metadata.Get(source, 'wanted_level', 0)
ArgumentTypeMeaning
sourcenumberPlayer server id.
keystringMetadata key.
defaultanyReturned when the key is empty.
ReturnsanyThe stored value.
Server

Metadata.Set

#
JRS.Metadata.Set(source, key, value)

Writes a value into the character metadata.

lua
JRS.Metadata.Set(source, 'last_bank_robbery', os.time())
ArgumentTypeMeaning
sourcenumberPlayer server id.
keystringMetadata key.
valueanyValue to store.
Server

Metadata.Add

#
JRS.Metadata.Add(source, key, amount)

Adds to a number stored in metadata.

lua
JRS.Metadata.Add(source, 'wanted_level', 1)
ArgumentTypeMeaning
sourcenumberPlayer server id.
keystringMetadata key.
amountnumberAmount to add.
Server

Metadata.Remove

#
JRS.Metadata.Remove(source, key, amount)

Subtracts from a number stored in metadata.

lua
JRS.Metadata.Remove(source, 'wanted_level', 1)
ArgumentTypeMeaning
sourcenumberPlayer server id.
keystringMetadata key.
amountnumberAmount to subtract.
Server

Skills.Get

#
JRS.Skills.Get(source, skill)

Reads one character skill. JRS.Skills.GetAll(source) returns every skill.

lua
local riding = JRS.Skills.Get(source, 'riding')
ArgumentTypeMeaning
sourcenumberPlayer server id.
skillstringSkill name.
Returnstable | nilThe skill entry.
Server

Skills.AddXP

#
JRS.Skills.AddXP(source, skill, xp)

Adds XP to a character skill. JRS.Skills.SetXP(source, skill, xp) sets it.

lua
JRS.Skills.AddXP(source, 'riding', 2)
ArgumentTypeMeaning
sourcenumberPlayer server id.
skillstringSkill name.
xpnumberXP to add.
Server

Appearance.GetForPlayer

#
JRS.Appearance.GetForPlayer(source)

Reads the saved look of the player current character. JRS.Appearance.Get(charId) and JRS.Appearance.Save(charId, data) work by character id instead.

lua
local look = JRS.Appearance.GetForPlayer(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnstable | nilAppearance data.

JRS.Character exposes the whole character service and JRS.Player.Get(source) / JRS.Player.GetAll() return player records. Use them only when the functions above are not enough.

Server Notifications#

Every server notification takes the target player first. All of them also exist as direct exports, for example exports.jrs_core:NotifyRightTip(source, text, ms). Durations are in milliseconds.

Server

NotifyRightTip

#
JRS.NotifyRightTip(source, text, duration)

The usual short message on the right side. Use it for most feedback.

lua
JRS.NotifyRightTip(source, 'Horse stabled', 3000)
ArgumentTypeMeaning
sourcenumberPlayer server id.
textstringMessage.
durationnumberTime on screen.
Server

NotifyLeft

#
JRS.NotifyLeft(source, title, subtitle, dict, icon, duration, color?)

Feed card on the left with a texture icon.

lua
JRS.NotifyLeft(source, 'Bounty', 'Posted in Rhodes', 'menu_textures', 'menu_icon_alert', 5000)
ArgumentTypeMeaning
sourcenumberPlayer server id.
titlestringFirst line.
subtitlestringSecond line.
dictstringTexture dictionary.
iconstringTexture name.
durationnumberTime on screen.
colorstringText color, default COLOR_WHITE.
Server

Notify

#
JRS.Notify(source, text, notifyType?, duration?, title?)

Sends a message through the unified notification renderer. Duration defaults to 3500.

lua
JRS.Notify(source, 'Wagon delivered', 'success', 4000)
ArgumentTypeMeaning
sourcenumberPlayer server id.
textstringMessage. Empty text is ignored.
notifyTypestring'info', 'success', 'warning', 'error' or 'reward'.
Returnsbooleanfalse for a bad source or empty text.
Server

Toast

#
JRS.Toast(source, text, notifyType?, duration?, title?)

Shows a toast card with a type color and optional title. The calling resource is recorded with it.

lua
JRS.Toast(source, 'You earned $4.00', 'reward', 4000, 'Fishing')
ArgumentTypeMeaning
sourcenumberPlayer server id.
textstringMessage.
notifyTypestringToast style.
durationnumberTime on screen.
titlestringCard title.
Returnsbooleantrue when sent.
Server

ShowNotification

#
JRS.ShowNotification(source, payload)

Sends a full toast table when you need fields the short forms do not have.

lua
JRS.ShowNotification(source, { text = 'Train leaving soon', type = 'info', duration = 6000 })
ArgumentTypeMeaning
sourcenumberPlayer server id.
payloadtableToast fields such as text, type, duration, title.
Returnsbooleanfalse when the payload is not a table.

The older RDR2 feed helpers are still on the server table, all with the player source first. With the default Config.Notifications.RouteLegacyNativeFeed = true (in modules/notify/config.lua), every one of them except NotifyDead is drawn as the same JRS toast as Notify, styled by the toast type below. Untyped ones get a type guessed from words in the text, and plain info when nothing matches. Set that option, or Enabled in the same table, to false and they fall back to the game's own feed in the area shown in the first column.

Native area Function Arguments after source Toast type when routed
Left feed NotifyAdvanced text, dict, icon, textColor, duration, quality reward
Left feed NotifyLeftRank title, subtitle, dict, icon, duration, color? reward
Left feed NotifyTip text, duration guessed
Top NotifyBasicTop text, duration guessed
Top NotifySimpleTop title, subtitle, duration guessed
Top NotifyTop text, location, duration guessed, location as title
Middle NotifyCenter text, duration guessed
Middle NotifyFail title, subtitle, duration error
Middle NotifyUpdate title, message, duration warning
Middle NotifyWarning title, message, audioRef, audioName, duration warning
Full screen NotifyDead title, audioRef, audioName, duration never routed, always the death card
Bottom NotifyBottomRight text, duration guessed
Bottom NotifyObjective text, duration guessed

Server Utilities#

Server

TeleportPlayer

#
JRS.TeleportPlayer(source, x, y, z, heading?)

Moves a player to a position.

lua
JRS.TeleportPlayer(source, -279.4, 805.2, 119.4, 90.0)
ArgumentTypeMeaning
sourcenumberPlayer server id.
xnumberX.
ynumberY.
znumberZ.
headingnumberFacing.
Server

HealPlayer

#
JRS.HealPlayer(source)

Heals the player fully on their client.

lua
JRS.HealPlayer(source)
ArgumentTypeMeaning
sourcenumberPlayer server id.
Server

SetWaypoint

#
JRS.SetWaypoint(source, coords, name?, color?)

Places the 3D destination marker for a player. JRS.RemoveWaypoint(source) clears it.

lua
JRS.SetWaypoint(source, vector3(-308.0, 777.0, 118.0), 'Deliver here')
ArgumentTypeMeaning
sourcenumberPlayer server id.
coordsvector3Target position.
namestringMarker label.
coloranyMarker color.
Server

SetPlayerInstance

#
JRS.SetPlayerInstance(source, instance)

Puts the player in a routing bucket. A number is used as the bucket. A string name shares one bucket with everyone else sent to the same name.

lua
JRS.SetPlayerInstance(source, 'interior_saloon_1')
-- back to the open world
JRS.SetPlayerInstance(source, 0)
ArgumentTypeMeaning
sourcenumberPlayer server id.
instancenumber | stringBucket number or instance name. Bucket 0 is the normal world.
Returnsboolean, number?true and the bucket used.
Server

GetOnlinePlayerCount

#
JRS.GetOnlinePlayerCount()

Counts connected players.

lua
print(JRS.GetOnlinePlayerCount())
ReturnsnumberPlayer count.
Server

IsConnectionStale

#
JRS.IsConnectionStale(source)

Tells you if the client heartbeat has gone quiet. JRS.GetLastHeartbeatAge(source) gives the age itself.

lua
if JRS.IsConnectionStale(source) then return end
ArgumentTypeMeaning
sourcenumberPlayer server id.
Returnsbooleantrue when the heartbeat is late.
Server

GetRestartStatus

#
JRS.GetRestartStatus()

Reads the scheduled restart manager state.

lua
local status = JRS.GetRestartStatus()
ReturnstableAt least enabled and blocked.
Server

Debug

#
JRS.Debug(text)

Prints a tagged line to the server console. JRS.Error(text) prints an error line and JRS.Report(id, title, text) prints a report block.

lua
JRS.Debug('my_ranch loaded 12 animals')
ArgumentTypeMeaning
textstringText to print.

The server table also has GetPerformanceMode(), SetPerformanceMode(mode), SetEntityProtected(entity, protected), ApplyHudLayout(source, layout, charId) and SyncWheel(source) for core tools.

Callbacks#

jrs_core has two RPC paths. The bounded one (RegisterServerCallback, CallServer, RegisterClientCallback, TriggerClientCallback) allows 30 calls per second per player, payloads up to 64 KB, and gives up after 10 seconds. Handlers may return up to four values.

Server

RegisterServerCallback

#
JRS.RegisterServerCallback(name, handler)

Registers a handler a client can call with CallServer. The handler is removed when your resource stops. Also exports.jrs_core:RegisterServerCallback.

lua
JRS.RegisterServerCallback('my_shop:getPrice', function(source, item)
    return exports.jrs_core:ApplyShopDiscount(source, 10)
end)
ArgumentTypeMeaning
namestringCallback name, up to 128 characters.
handlerfunctionfunction(source, ...) returning your values.
Returnsbooleanfalse for a bad name or handler.
Client

CallServer

#
JRS.CallServer(name, ...)

Calls a server callback and waits for the answer. Run it inside a thread or handler.

lua
local ok, price = JRS.CallServer('my_shop:getPrice', 'bread')
if ok then print('price', price) end
ArgumentTypeMeaning
namestringCallback name.
Returnsboolean, ...true and the handler values, or false and 'timeout', 'rate_limited', 'not_registered' or another reason.
Client

RegisterClientCallback

#
JRS.RegisterClientCallback(name, handler)

Registers a client handler the server can call.

lua
JRS.RegisterClientCallback('my_shop:getPosition', function()
    return GetEntityCoords(PlayerPedId())
end)
ArgumentTypeMeaning
namestringCallback name.
handlerfunctionReturns the values sent back.
Returnsbooleanfalse for a bad name.
Server

TriggerClientCallback

#
JRS.TriggerClientCallback(source, name, ...)

Calls a client callback on one player and waits. Also exports.jrs_core:TriggerClientCallback.

lua
local ok, coords = JRS.TriggerClientCallback(source, 'my_shop:getPosition')
ArgumentTypeMeaning
sourcenumberPlayer server id.
namestringCallback name.
Returnsboolean, ...true and the values, or false and a reason such as 'timeout' or 'player_dropped'.

The older path uses a callback function instead of waiting:

Server

Rpc

#
JRS.Rpc(name, handler)

Registers a handler for the client Rpc call. Errors in the handler are caught and send nil back. addNewCallBack is the same function.

lua
JRS.Rpc('my_camp:canBuild', function(source, spot)
    return JRS.GetItemCount(source, 'wood') >= 10
end)
ArgumentTypeMeaning
namestringCallback name.
handlerfunctionfunction(source, ...) returning your values.
Returnsbooleantrue when registered.
Client

Rpc

#
JRS.Rpc(name, callback, ...)

Calls a server Rpc handler and runs callback with its values. RpcCall is the same function.

lua
JRS.Rpc('my_camp:canBuild', function(allowed)
    if allowed then startPlacement() end
end, 'riverside')
ArgumentTypeMeaning
namestringCallback name.
callbackfunctionReceives the returned values.

Client Player#

Client

IsCharacterReady

#
JRS.IsCharacterReady()

Tells the client whether the local character is loaded, read from the CharacterReady state bag.

lua
if not JRS.IsCharacterReady() then return end
Returnsbooleantrue once loaded.
Client

WaitForCharacterReady

#
JRS.WaitForCharacterReady(timeoutMs?)

Waits until the character is loaded or the timeout passes. Put it at the start of client threads that need character data.

lua
CreateThread(function()
    if not JRS.WaitForCharacterReady(30000) then return end
    spawnCampProps()
end)
ArgumentTypeMeaning
timeoutMsnumberMaximum wait, default 10000.
Returnsbooleantrue when ready in time.
Client

GetPlayerData

#
JRS.GetPlayerData()

Returns the player data the client has cached.

lua
local data = JRS.GetPlayerData()
ReturnstableClient player data.
Client

GetLevel

#
exports.jrs_core:GetLevel()

Reads the local character level from state bags. Export only.

lua
local level = exports.jrs_core:GetLevel()
ReturnsnumberLevel, 1 when unknown.
Client

GetLocale

#
JRS.GetLocale(key)

Reads a jrs_core translation string.

lua
local text = JRS.GetLocale('core_brand')
ArgumentTypeMeaning
keystringLocale key.
ReturnsstringThe text, or a message saying the key is missing.

Client Notifications#

The client table has the same native feed functions as the server, without the source argument, for example JRS.NotifyTip(text, duration). It also has the toast helpers:

Client

Notify

#
JRS.Notify(text, notifyType?, duration?, title?)

Shows a message through the unified renderer. Duration defaults to 3500.

lua
JRS.Notify('Camp saved', 'success')
ArgumentTypeMeaning
textstringMessage.
notifyTypestringStyle name.
Returnsbooleanfalse for empty text.
Client

Toast

#
JRS.Toast(text, notifyType?, duration?, title?)

Shows a toast card.

lua
JRS.Toast('Fire is lit', 'info', 3000, 'Camp')
ArgumentTypeMeaning
textstringMessage.
notifyTypestring'info', 'success', 'warning', 'error' or 'reward'.
durationnumberTime on screen.
titlestringCard title.
Returnsbooleantrue when shown.
Client

ShowNotification

#
JRS.ShowNotification(payload)

Shows a toast from a full table.

lua
JRS.ShowNotification({ text = 'Storm coming', type = 'warning', duration = 5000 })
ArgumentTypeMeaning
payloadtableToast fields.
Returnsbooleanfalse when the payload is not a table.

JRS.Info, JRS.Success, JRS.WarningNotify, JRS.ErrorNotify and JRS.RewardNotify take (text, duration?, title?) and call Toast with that type.

Client Dialogs#

The input and confirm boxes. See the inputs page for more.

Client

InputAwait

#
JRS.InputAwait(title, subtext, options?)

Opens the text box and waits for the answer.

lua
local amount = JRS.InputAwait('Deposit', 'How much?', { type = 'number', min = 1, max = 500 })
ArgumentTypeMeaning
titlestringBox title.
subtextstringHint line.
optionstableChecks run before the box accepts: maxLength, minLength, type = 'number' with min, max, integer, or your own validate(text) returning true or false and a message. hint adds a line under the subtext.
ReturnsanyThe entered text (a number in number mode), or nil and a reason when the box could not open.
Client

GetInput

#
JRS.GetInput(title, subtext, callback, options?)

Opens the text box and returns at once; the answer arrives in callback. JRS.Input is the same, and JRS.NumberInput forces a number.

lua
JRS.GetInput('Name your horse', 'Max 20 letters', function(name)
    TriggerServerEvent('my_stable:rename', name)
end, { maxLength = 20 })
ArgumentTypeMeaning
titlestringBox title.
subtextstringHint line.
callbackfunctionReceives the value.
Returnsboolean, string?true, or false and a reason.
Client

ConfirmAwait

#
JRS.ConfirmAwait(title, firstButton, secondButton)

Opens a two-button question and waits.

lua
if JRS.ConfirmAwait('Sell this horse?', 'Sell', 'Keep') then
    TriggerServerEvent('my_stable:sell')
end
ArgumentTypeMeaning
titlestringThe question.
firstButtonstringLabel of the yes button.
secondButtonstringLabel of the no button.
Returnsbooleantrue for yes.
Client

GetAnswer

#
JRS.GetAnswer(title, firstButton, secondButton, callback)

Callback form of ConfirmAwait. JRS.Confirm is the same.

lua
JRS.GetAnswer('Join the posse?', 'Join', 'Decline', function(yes)
    if yes then TriggerServerEvent('my_posse:join') end
end)
ArgumentTypeMeaning
titlestringThe question.
firstButtonstringYes label.
secondButtonstringNo label.
callbackfunctionReceives the answer.

JRS.IsInputOpen() and JRS.CloseInput() check and close the box. Menus are opened with JRS.OpenMenu, see the menu page.

Client Helpers#

Client

LoadModel

#
JRS.LoadModel(model)

Requests a model and waits until it is loaded. JRS.LoadModelSafe(model, timeoutMs?) adds a 10 second default timeout and returns loaded, hash.

lua
local ok, hash = JRS.LoadModelSafe('a_c_horse_arabian_white', 5000)
ArgumentTypeMeaning
modelstring | numberModel name or hash.
Client

LoadAnimDict

#
JRS.LoadAnimDict(dict, timeoutMs?)

Loads an animation dictionary with a timeout.

lua
if JRS.LoadAnimDict('amb_work@world_human_hammer@table@male_a@trans') then
    -- play it
end
ArgumentTypeMeaning
dictstringDictionary name.
timeoutMsnumberDefault 10000.
Returnsbooleantrue when loaded.
Client

LoadTextureDict

#
JRS.LoadTextureDict(dict, timeoutMs?)

Loads a streamed texture dictionary with a timeout. JRS.LoadTexture(hash) is the older loader.

lua
JRS.LoadTextureDict('inventory_items')
ArgumentTypeMeaning
dictstringDictionary name.
timeoutMsnumberDefault 10000.
Returnsbooleantrue when loaded.
Client

PlayAnimation

#
JRS.PlayAnimation(ped, anim)

Loads and plays an animation from a table.

lua
JRS.PlayAnimation(PlayerPedId(), {
    dict = 'mech_inventory@eating@canned_food@cylinder@d8-2_h10-5',
    name = 'left_hand', blendInSpeed = 8.0, blendOutSpeed = -8.0,
    duration = 3000, flag = 31, playbackRate = 0.0,
})
ArgumentTypeMeaning
pednumberPed handle.
animtabledict, name, blendInSpeed, blendOutSpeed, duration, flag, playbackRate.
Returnsbooleanfalse when the dictionary does not exist or times out.
Client

GetNearbyPlayers

#
JRS.GetNearbyPlayers(maxDistance?, includeSelf?)

Lists players around you, nearest first.

lua
for _, p in ipairs(JRS.GetNearbyPlayers(10.0)) do
    print(p.serverId, p.distance)
end
ArgumentTypeMeaning
maxDistancenumberRadius, default 5.0.
includeSelfbooleanInclude the local player.
ReturnstableEntries with playerId, serverId, ped, distance.
Client

GetClosestPlayer

#
JRS.GetClosestPlayer(maxDistance?)

The nearest other player, as one entry from GetNearbyPlayers.

lua
local target = JRS.GetClosestPlayer(3.0)
if target then
    TriggerServerEvent('my_trade:request', target.serverId)
end
ArgumentTypeMeaning
maxDistancenumberRadius, default 5.0.
Returnstable | nilThe entry, or nil when nobody is close.
Client

WaitUntil

#
JRS.WaitUntil(check, timeoutMs?, intervalMs?)

Waits until a function returns true.

lua
JRS.WaitUntil(function() return DoesEntityExist(wagon) end, 5000)
ArgumentTypeMeaning
checkfunctionCondition to test.
timeoutMsnumberDefault 10000. A negative value waits forever.
intervalMsnumberPause between checks, default 10.
Returnsbooleanfalse on timeout.
Client

NoSpam

#
JRS.NoSpam(key, cooldownMs?)

A simple cooldown per key.

lua
local ok, wait = JRS.NoSpam('whistle', 2000)
if not ok then return end
ArgumentTypeMeaning
keystringCooldown name.
cooldownMsnumberDefault 1000.
Returnsboolean, numbertrue when allowed, otherwise false and the time left.
Client

TeleportToCoords

#
JRS.TeleportToCoords(x, y, z, heading?)

Moves the local player. JRS.TeleportPedToCoords(ped, x, y, z, heading) moves another ped and JRS.TeleportToWaypoint() jumps to the map marker.

lua
JRS.TeleportToCoords(2693.0, -1405.0, 46.6, 180.0)
ArgumentTypeMeaning
xnumberX.
ynumberY.
znumberZ.
headingnumberFacing.
Client

SetCustomDestination

#
JRS.SetCustomDestination(coords, name?, color?)

Shows the 3D destination marker. JRS.RemoveCustomDestination() hides it.

lua
JRS.SetCustomDestination(vector3(-178.0, 627.0, 114.0), 'Valentine station')
ArgumentTypeMeaning
coordsvector3Target. A missing z is filled from the ground.
namestringLabel.
coloranyMarker color.
Client

HealPlayer

#
JRS.HealPlayer()

Heals the local player.

lua
JRS.HealPlayer()

Smaller helpers on the client table: Round(number, decimals), Lerp(a, b, t), SetTimeout(ms, fn, ...), BigInt(value), DrawText(...), RemoveEntityProperly(entity, hash), SetPlayerInstance(instance), GetPerformanceMode(), GetNearbyPlayerCount(), IsEntityProtected(entity), SetEntityProtected(entity, state), SetMapDiscoveriesEnabled(enabled) and Utils, the raw helper table.

Client Screen Ownership#

Only one full screen UI should own the mouse at a time. These calls let your NUI take part in that.

Client

AcquireUI

#
JRS.AcquireUI(owner?, options?)

Claims the screen for your UI. The owner defaults to your resource. Also an export.

lua
local ok = JRS.AcquireUI(nil, { focus = true, cursor = true })
if not ok then return end
SendNUIMessage({ action = 'open' })
ArgumentTypeMeaning
ownerstringOwner name.
optionstableFor example focus, cursor, force.
Returnsboolean, string?true, or false and 'ui_busy:<owner>'.
Client

ReleaseUI

#
JRS.ReleaseUI(owner?, options?)

Gives the screen back. Also an export.

lua
JRS.ReleaseUI()
ArgumentTypeMeaning
ownerstringOwner name.
Client

IsUIBusy

#
JRS.IsUIBusy(owner?)

Asks if another UI holds the screen. Also an export.

lua
if JRS.IsUIBusy() then return end
ArgumentTypeMeaning
ownerstringYour owner name, left out of the check. Defaults to your resource.
Returnsboolean, string?Busy flag and the current owner.
Client

GetOpenUI

#
JRS.GetOpenUI()

Reads the current screen owner state. Also an export.

lua
local state = JRS.GetOpenUI()
ReturnstableAt least { busy = boolean }.

Client Progress And Trade#

Client

Progress

#
JRS.Progress(action, finish?)

Shows the core progress bar without blocking. finish(cancelled) runs at the end. See the progress bar page for DisplayProgressBar and CancelProgressBar.

lua
JRS.Progress({ duration = 5000, label = 'Skinning...' }, function(cancelled)
    if not cancelled then TriggerServerEvent('my_hunt:skin') end
end)
ArgumentTypeMeaning
actiontable | numberduration, label, canCancel, useWhileDead, brand, or just a duration.
finishfunctionReceives true when the player cancelled.

JRS.Trade on the client wraps the jrs_inventory trade window: Start(target), Cancel(), IsTrading(), GetSession(), CanTradeWith(target) and Reopen(). Each returns false or nil when the inventory is not started.