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#
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.
-- 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)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.
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.
RegisterNetEvent('my_ranch:collect', function()
local src = source
if not JRS.IsCharacterReady(src) then return end
JRS.AddMoney(src, 3)
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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.
local char = JRS.GetCharacter(source)
if char then
print(char.firstname, char.job, char.money)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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).
local data = JRS.GetCharacterData(source)
if data and data.group == 'admin' then
print(('%s %s is staff'):format(data.firstname, data.lastname))
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
source, identifier, charIdentifier, charid, firstname, lastname, job, jobGrade, group, money, gold, rol, dirtymoney, xp.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).
local name = JRS.GetCharacterName(source) or 'Stranger'
JRS.NotifyRightTip(source, ('Welcome back, %s'):format(name), 4000)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.GetCharacterState(source)Reads the load state jrs_core tracks for the player, for code that needs more detail than true or false.
local state = JRS.GetCharacterState(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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.
local user = JRS.GetUser(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.GetIdentifiers(source)Collects the player identifiers into a table keyed by type.
local ids = JRS.GetIdentifiers(source)
print(ids.license)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
{ steam = 'steam:...', license = 'license:...', discord = 'discord:...' }.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).
JRS.Metadata.Set(source, 'bounty', 0)
JRS.SaveCharacter(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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.
JRS.GetCharacterById(charId)Loads one character by its character id. Also exports.jrs_core:GetCharacterById(charId).
local row = JRS.GetCharacterById(42)
if row then print(row.firstname, row.lastname) end| Argument | Type | Meaning |
|---|---|---|
charId | number | Character id. |
JRS.GetOfflineCharacter(charId)Reads a character straight from the database, even when its owner is online.
local row = JRS.GetOfflineCharacter(42)| Argument | Type | Meaning |
|---|---|---|
charId | number | Character id. |
JRS.GetCharactersByIdentifier(identifier)Lists every character that belongs to one account.
local list = JRS.GetCharactersByIdentifier(JRS.getIdentifier(source))
print(('%d characters on this account'):format(#list))| Argument | Type | Meaning |
|---|---|---|
identifier | string | Account identifier, for example a steam: or license: value. |
JRS.FindCharactersByName(firstname, lastname?)Searches characters by name, for wanted posters, registries and admin tools. Also exports.jrs_core:FindCharactersByName(firstname, lastname).
local rows = JRS.FindCharactersByName('Ezra', 'Calloway')| Argument | Type | Meaning |
|---|---|---|
firstname | string | First name to search. |
lastname | string | Last name to narrow the search. |
JRS.GetCharacterCount(source)Counts the characters on the player account.
local count = JRS.GetCharacterCount(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.GetMaxCharacters(source)Returns how many characters this player may have. Falls back to Config.Char_Count.
local slots = JRS.GetMaxCharacters(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.CanCreateCharacter(source)Checks the count against the limit for you.
if not JRS.CanCreateCharacter(source) then
JRS.NotifyRightTip(source, 'No free character slot', 4000)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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 |
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).
JRS.AddMoney(source, 12.5)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | Cash to add. |
JRS.RemoveMoney(source, amount)Takes cash. Nothing is taken when the player has less than amount. Also exports.jrs_core:RemoveMoney(source, amount).
if not JRS.RemoveMoney(source, 4) then
JRS.NotifyRightTip(source, 'You cannot afford that', 3000)
return
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | Cash to take. |
JRS.AddGold(source, amount)Gives gold bars. Also exports.jrs_core:AddGold(source, amount).
JRS.AddGold(source, 0.5)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | Gold to add. |
JRS.RemoveGold(source, amount)Takes gold bars. Also exports.jrs_core:RemoveGold(source, amount).
local paid = JRS.RemoveGold(source, 2)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | Gold to take. |
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.
exports.jrs_core:AddGoldNuggets(source, 35) -- adds 0.35 gold| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
count | number | Number of nuggets. |
JRS.AddDirtyMoney(source, amount)Gives dirty money (currency 3). Also exports.jrs_core:AddDirtyMoney(source, amount).
JRS.AddDirtyMoney(source, 40)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | Amount to add. |
JRS.RemoveDirtyMoney(source, amount)Takes dirty money. Also exports.jrs_core:RemoveDirtyMoney(source, amount).
JRS.RemoveDirtyMoney(source, 40)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | Amount to take. |
JRS.GetDirtyMoney(source)Reads the dirty money balance.
local dirty = JRS.GetDirtyMoney(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.GetBalance(source)Reads every currency at once. Also exports.jrs_core:GetBalance(source).
local bal = JRS.GetBalance(source)
print(('cash %.2f, gold %.2f'):format(bal.money, bal.gold))| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
money, gold, rol, dirtymoney and blackmoney (same value as dirtymoney). All zero when no character is ready.JRS.addMoney(source, currency, amount)The generic adder behind the helpers above. Pick the currency with its id.
JRS.addMoney(source, 2, 1) -- one rol| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
currency | number | Currency id from the table above. |
amount | number | Amount to add. |
JRS.removeMoney(source, currency, amount)The generic remover. Fails without taking anything when the balance is too low.
local ok = JRS.removeMoney(source, 0, 7.5)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
currency | number | Currency id. |
amount | number | Amount to take. |
Rewards#
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.
RegisterNetEvent('my_fishing:sell', function(fishCount)
local src = source
JRS.AddReward(src, 0, 0.8 * fishCount, 'fishing')
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
currency | number | 0 for cash or 1 for gold. |
amount | number | Base amount before scaling. |
reason | string | Job or payout key. Needed for job pay perks and item drops. |
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.
local shown = JRS.ScaleReward(10, 0)
JRS.NotifyRightTip(source, ('This job pays about $%.2f'):format(shown), 4000)| Argument | Type | Meaning |
|---|---|---|
amount | number | Base amount. |
currency | number | 1 for gold, anything else for cash. |
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.
JRS.RollJobItemDrops(source, 'lumberjack')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
jobKey | string | Job 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.
exports.jrs_core:ApplyShopDiscount(source, amount)Lowers a shop price by the player shop discount. The price never goes under 0.01.
local price = exports.jrs_core:ApplyShopDiscount(source, 25)
if JRS.RemoveMoney(source, price) then
JRS.AddItem(source, 'canned_beans', 1)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | Full price. |
exports.jrs_core:ApplySellBonus(source, amount)Raises a sell payout by the player sell bonus.
local payout = exports.jrs_core:ApplySellBonus(source, 6)
JRS.AddMoney(source, payout)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | Base payout. |
exports.jrs_core:ApplyTaxReduction(source, tax)Cuts a tax amount by the player tax reduction.
local tax = exports.jrs_core:ApplyTaxReduction(source, 3)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
tax | number | Tax before the reduction. |
exports.jrs_core:GetCarryCapacity(source)Returns the carry weight the player level grants.
local kg = exports.jrs_core:GetCarryCapacity(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
Jobs And Duty#
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.
local ok, why = exports.jrs_core:SetJob(source, 'sheriff', 1)
if not ok then print('job change failed:', why) end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job name. |
grade | number | Job grade. |
JRS.setJobGrade(source, grade)Changes only the grade, keeping the same job.
JRS.setJobGrade(source, 3)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
grade | number | New grade. |
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.
JRS.Jobs.Get(source)Lists the jobs the character holds. The active job is always in the list.
for name, info in pairs(JRS.Jobs.Get(source)) do
print(name, info.grade, info.label)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
{ grade = number, label = string }.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.
JRS.Jobs.Add(source, 'doctor', 0, 'Town Doctor')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job name. |
grade | number | Grade, default 0. |
label | string | Display name, default the job name. |
'invalid_job' or 'max_jobs'.JRS.Jobs.Remove(source, job)Removes a job from the list. The active job cannot be removed.
JRS.Jobs.Remove(source, 'doctor')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job name. |
'active_job' or 'not_found'.JRS.Jobs.Switch(source, job)Makes a held job the active one, with its saved grade. Respects JobSwitchCooldownSeconds and puts the player off duty.
local ok, why = JRS.Jobs.Switch(source, 'doctor')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | A job from the list. |
'job_not_owned', 'cooldown' or another reason.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.
JRS.Jobs.SetDuty(source, true)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
onDuty | boolean | New duty state. |
JRS.Jobs.ToggleDuty(source)Flips duty.
local nowOnDuty = JRS.Jobs.ToggleDuty(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.Jobs.GetDutyPlayers(job)Finds online players who have this job active and are on duty.
local sheriffs, count = JRS.Jobs.GetDutyPlayers('sheriff')
for _, id in ipairs(sheriffs) do
JRS.NotifyRightTip(id, 'Robbery at the Valentine bank', 6000)
end| Argument | Type | Meaning |
|---|---|---|
job | string | Job name. |
Groups And Permissions#
JRS.GetGroup(source)Reads the account permission group, such as user or admin. Also exports.jrs_core:GetGroup(source).
local group = JRS.GetGroup(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.SetGroup(source, group, callback?)Changes the account group and saves it. Server only on purpose: clients can never set a group.
JRS.SetGroup(target, 'moderator')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
group | string | New group. |
callback | function | Runs when the save finishes. |
JRS.RefreshGroup(source, callback?)Reloads the group from the database, for example after another tool changed it.
JRS.RefreshGroup(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
callback | function | Runs after the reload. |
exports.jrs_core:IsAdmin(source)Checks the group against the admin groups in the jrs_core config. Source 0 (the server console) always passes.
if not exports.jrs_core:IsAdmin(source) then return end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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.
RegisterCommand('bounty', function(src, args)
if not exports.jrs_core:CanUseCommand(src, 'bounty') then return end
-- ...
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
commandKey | string | Command key from the config. |
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.
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(...).
JRS.AddXP(source, 15, 'bounty_turned_in', function(ok, data)
if ok then print('now level', data.level) end
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | XP to add, whole number above 0. |
reason | string | Log reason. |
callback | function | Runs after the save. |
JRS.RemoveXP(source, amount, reason?, callback?)Takes XP away. Boosts are not applied.
JRS.RemoveXP(source, 50, 'admin_correction')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | XP to remove. |
JRS.SetXP(source, amount, reason?, callback?)Sets total XP to an exact value.
JRS.SetXP(source, 0, 'admin_reset')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
amount | number | New total XP. |
JRS.GetXP(source)Reads the level data. It waits for the database, so call it inside a thread or event handler.
local xp = JRS.GetXP(source)
if xp then print(xp.totalXp, xp.level) end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
totalXp, level, currentXp, requiredXp, progress, isMaxLevel.JRS.GetLevel(source)Returns just the level number, plus the full data as a second value.
if JRS.GetLevel(source) < 10 then
JRS.NotifyRightTip(source, 'You need level 10 for this', 4000)
return
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
GetXP.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.
JRS.SetLevel(source, 25, 'admin_event_prize')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
level | number | Target level. |
JRS.AddLevel(source, levels, reason?, callback?)Raises the level by a number of levels.
JRS.AddLevel(source, 1, 'admin_gift')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
levels | number | Levels to add. |
JRS.RemoveLevel(source, levels, reason?, callback?)Lowers the level by a number of levels.
JRS.RemoveLevel(source, 1, 'admin_penalty')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
levels | number | Levels to remove. |
JRS.GetLevelData(totalXp)Pure math: turns a total XP number into level data. No player needed.
local info = JRS.GetLevelData(12000)
print(info.level, info.progress)| Argument | Type | Meaning |
|---|---|---|
totalXp | number | Total XP. |
GetXP.JRS.GetTotalXpForLevel(level)Total XP a character needs to reach a level.
local need = JRS.GetTotalXpForLevel(50)| Argument | Type | Meaning |
|---|---|---|
level | number | Target level. |
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.
JRS.AddJobXP(source, job, amount, reason?, callback?)Adds XP to one job.
JRS.AddJobXP(source, 'mining', 8, 'iron_ore')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job or script key, for example 'mining'. |
amount | number | XP to add. |
JRS.RemoveJobXP(source, job, amount, reason?, callback?)Removes XP from one job.
JRS.RemoveJobXP(source, 'mining', 8, 'admin_fix')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job key. |
amount | number | XP to remove. |
JRS.SetJobXP(source, job, amount, reason?, callback?)Sets one job XP total.
JRS.SetJobXP(source, 'mining', 0, 'admin_reset')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job key. |
amount | number | New total. |
JRS.GetJobXP(source, job)Reads one job XP. Waits for the database. Also an export.
local xp = JRS.GetJobXP(source, 'fishing')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job key. |
JRS.GetJobLevel(source, job)Reads one job level. Also an export.
if JRS.GetJobLevel(source, 'fishing') >= 20 then
JRS.AddItem(source, 'fishing_lure_rare', 1)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job key. |
JRS.GetJobLevelData(source, job)Reads the full level table for one job. Also an export.
local data = JRS.GetJobLevelData(source, 'hunting')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job key. |
{ level = 1 }.JRS.GetAllJobLevels(source)Reads every job level the character has. Also an export.
local rows = JRS.GetAllJobLevels(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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.
JRS.AddItem(source, item, count, metadata?)Gives an item. Also exports.jrs_core:InventoryAddItem(...).
if JRS.CanCarryItem(source, 'bread', 2) then
JRS.AddItem(source, 'bread', 2)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
item | string | Item name. |
count | number | How many. |
metadata | table | Extra data stored on the item. |
JRS.RemoveItem(source, item, count)Takes items by name. Also exports.jrs_core:InventoryRemoveItem(...).
local ok, why = JRS.RemoveItem(source, 'wood', 5)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
item | string | Item name. |
count | number | How many. |
JRS.RemoveItemById(source, itemId, count)Takes from one exact stack, useful for items with metadata. Also exports.jrs_core:InventoryRemoveItemById(...).
JRS.RemoveItemById(source, slot.id, 1)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Inventory item id. |
count | number | How many. |
JRS.GetItemCount(source, item)Counts an item across the player inventory. Also exports.jrs_core:InventoryGetItemCount(...).
local pelts = JRS.GetItemCount(source, 'pelt_fox')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
item | string | Item name. |
JRS.CanCarryItem(source, item, count)Checks weight and limits before you give something. Also exports.jrs_core:InventoryCanCarryItem(...).
if not JRS.CanCarryItem(source, 'iron_ore', 3) then
JRS.NotifyRightTip(source, 'Your bag is full', 3000)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
item | string | Item name. |
count | number | How many. |
JRS.GetInventory(source)Returns the whole player inventory. Also exports.jrs_core:InventoryGet(source).
local items = JRS.GetInventory(source)
print(json.encode(items))| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.GetInventoryItemById(source, itemId)Reads one stack by its id. Also exports.jrs_core:InventoryGetItemById(...).
local item = JRS.GetInventoryItemById(source, 1201)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
itemId | number | Inventory item id. |
JRS.IsInventoryReady()Tells you if jrs_inventory is started. Also an export.
if not JRS.IsInventoryReady() then return endJRS.GetInventoryApi()Returns the full jrs_inventory API table, for functions the wrappers here do not cover.
local Inv = JRS.GetInventoryApi()JRS.Inventory groups the same wrappers (IsReady, GetApi, Get, GetItemById, GetItemCount, AddItem, RemoveItem, RemoveItemById, CanCarry) and adds three more:
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.
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| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
operations | table | Steps like { type = 'add' | 'remove', item = name, amount = n, metadata? = table }. Amounts must be whole numbers. |
context | table | owner for logs and id for the transaction id. |
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.
JRS.Inventory.RegisterHook('itemAdded', 'my_logger', function(payload)
print(payload.source, 'got', payload.amount, payload.item)
end)| Argument | Type | Meaning |
|---|---|---|
eventName | string | Inventory hook event. |
name | string | Your unique hook name. |
callback | function | Receives one payload table, for items source, item, amount, metadata, sourceResource. |
JRS.Inventory.GetFreeWeight(source)Reads how much weight is left.
local free = JRS.Inventory.GetFreeWeight(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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#
JRS.Metadata.Get(source, key, default?)Reads a value from the character metadata store.
local wanted = JRS.Metadata.Get(source, 'wanted_level', 0)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Metadata key. |
default | any | Returned when the key is empty. |
JRS.Metadata.Set(source, key, value)Writes a value into the character metadata.
JRS.Metadata.Set(source, 'last_bank_robbery', os.time())| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Metadata key. |
value | any | Value to store. |
JRS.Metadata.Add(source, key, amount)Adds to a number stored in metadata.
JRS.Metadata.Add(source, 'wanted_level', 1)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Metadata key. |
amount | number | Amount to add. |
JRS.Metadata.Remove(source, key, amount)Subtracts from a number stored in metadata.
JRS.Metadata.Remove(source, 'wanted_level', 1)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Metadata key. |
amount | number | Amount to subtract. |
JRS.Skills.Get(source, skill)Reads one character skill. JRS.Skills.GetAll(source) returns every skill.
local riding = JRS.Skills.Get(source, 'riding')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
skill | string | Skill name. |
JRS.Skills.AddXP(source, skill, xp)Adds XP to a character skill. JRS.Skills.SetXP(source, skill, xp) sets it.
JRS.Skills.AddXP(source, 'riding', 2)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
skill | string | Skill name. |
xp | number | XP to add. |
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.
local look = JRS.Appearance.GetForPlayer(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
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.
JRS.NotifyRightTip(source, text, duration)The usual short message on the right side. Use it for most feedback.
JRS.NotifyRightTip(source, 'Horse stabled', 3000)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
text | string | Message. |
duration | number | Time on screen. |
JRS.NotifyLeft(source, title, subtitle, dict, icon, duration, color?)Feed card on the left with a texture icon.
JRS.NotifyLeft(source, 'Bounty', 'Posted in Rhodes', 'menu_textures', 'menu_icon_alert', 5000)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
title | string | First line. |
subtitle | string | Second line. |
dict | string | Texture dictionary. |
icon | string | Texture name. |
duration | number | Time on screen. |
color | string | Text color, default COLOR_WHITE. |
JRS.Notify(source, text, notifyType?, duration?, title?)Sends a message through the unified notification renderer. Duration defaults to 3500.
JRS.Notify(source, 'Wagon delivered', 'success', 4000)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
text | string | Message. Empty text is ignored. |
notifyType | string | 'info', 'success', 'warning', 'error' or 'reward'. |
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.
JRS.Toast(source, 'You earned $4.00', 'reward', 4000, 'Fishing')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
text | string | Message. |
notifyType | string | Toast style. |
duration | number | Time on screen. |
title | string | Card title. |
JRS.ShowNotification(source, payload)Sends a full toast table when you need fields the short forms do not have.
JRS.ShowNotification(source, { text = 'Train leaving soon', type = 'info', duration = 6000 })| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
payload | table | Toast fields such as text, type, duration, title. |
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#
JRS.TeleportPlayer(source, x, y, z, heading?)Moves a player to a position.
JRS.TeleportPlayer(source, -279.4, 805.2, 119.4, 90.0)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
x | number | X. |
y | number | Y. |
z | number | Z. |
heading | number | Facing. |
JRS.HealPlayer(source)Heals the player fully on their client.
JRS.HealPlayer(source)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.SetWaypoint(source, coords, name?, color?)Places the 3D destination marker for a player. JRS.RemoveWaypoint(source) clears it.
JRS.SetWaypoint(source, vector3(-308.0, 777.0, 118.0), 'Deliver here')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
coords | vector3 | Target position. |
name | string | Marker label. |
color | any | Marker color. |
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.
JRS.SetPlayerInstance(source, 'interior_saloon_1')
-- back to the open world
JRS.SetPlayerInstance(source, 0)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
instance | number | string | Bucket number or instance name. Bucket 0 is the normal world. |
JRS.GetOnlinePlayerCount()Counts connected players.
print(JRS.GetOnlinePlayerCount())JRS.IsConnectionStale(source)Tells you if the client heartbeat has gone quiet. JRS.GetLastHeartbeatAge(source) gives the age itself.
if JRS.IsConnectionStale(source) then return end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.GetRestartStatus()Reads the scheduled restart manager state.
local status = JRS.GetRestartStatus()enabled and blocked.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.
JRS.Debug('my_ranch loaded 12 animals')| Argument | Type | Meaning |
|---|---|---|
text | string | Text 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.
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.
JRS.RegisterServerCallback('my_shop:getPrice', function(source, item)
return exports.jrs_core:ApplyShopDiscount(source, 10)
end)| Argument | Type | Meaning |
|---|---|---|
name | string | Callback name, up to 128 characters. |
handler | function | function(source, ...) returning your values. |
JRS.CallServer(name, ...)Calls a server callback and waits for the answer. Run it inside a thread or handler.
local ok, price = JRS.CallServer('my_shop:getPrice', 'bread')
if ok then print('price', price) end| Argument | Type | Meaning |
|---|---|---|
name | string | Callback name. |
'timeout', 'rate_limited', 'not_registered' or another reason.JRS.RegisterClientCallback(name, handler)Registers a client handler the server can call.
JRS.RegisterClientCallback('my_shop:getPosition', function()
return GetEntityCoords(PlayerPedId())
end)| Argument | Type | Meaning |
|---|---|---|
name | string | Callback name. |
handler | function | Returns the values sent back. |
JRS.TriggerClientCallback(source, name, ...)Calls a client callback on one player and waits. Also exports.jrs_core:TriggerClientCallback.
local ok, coords = JRS.TriggerClientCallback(source, 'my_shop:getPosition')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
name | string | Callback name. |
'timeout' or 'player_dropped'.The older path uses a callback function instead of waiting:
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.
JRS.Rpc('my_camp:canBuild', function(source, spot)
return JRS.GetItemCount(source, 'wood') >= 10
end)| Argument | Type | Meaning |
|---|---|---|
name | string | Callback name. |
handler | function | function(source, ...) returning your values. |
JRS.Rpc(name, callback, ...)Calls a server Rpc handler and runs callback with its values. RpcCall is the same function.
JRS.Rpc('my_camp:canBuild', function(allowed)
if allowed then startPlacement() end
end, 'riverside')| Argument | Type | Meaning |
|---|---|---|
name | string | Callback name. |
callback | function | Receives the returned values. |
Client Player#
JRS.IsCharacterReady()Tells the client whether the local character is loaded, read from the CharacterReady state bag.
if not JRS.IsCharacterReady() then return endJRS.WaitForCharacterReady(timeoutMs?)Waits until the character is loaded or the timeout passes. Put it at the start of client threads that need character data.
CreateThread(function()
if not JRS.WaitForCharacterReady(30000) then return end
spawnCampProps()
end)| Argument | Type | Meaning |
|---|---|---|
timeoutMs | number | Maximum wait, default 10000. |
JRS.GetPlayerData()Returns the player data the client has cached.
local data = JRS.GetPlayerData()exports.jrs_core:GetLevel()Reads the local character level from state bags. Export only.
local level = exports.jrs_core:GetLevel()JRS.GetLocale(key)Reads a jrs_core translation string.
local text = JRS.GetLocale('core_brand')| Argument | Type | Meaning |
|---|---|---|
key | string | Locale key. |
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:
JRS.Notify(text, notifyType?, duration?, title?)Shows a message through the unified renderer. Duration defaults to 3500.
JRS.Notify('Camp saved', 'success')| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
notifyType | string | Style name. |
JRS.Toast(text, notifyType?, duration?, title?)Shows a toast card.
JRS.Toast('Fire is lit', 'info', 3000, 'Camp')| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
notifyType | string | 'info', 'success', 'warning', 'error' or 'reward'. |
duration | number | Time on screen. |
title | string | Card title. |
JRS.ShowNotification(payload)Shows a toast from a full table.
JRS.ShowNotification({ text = 'Storm coming', type = 'warning', duration = 5000 })| Argument | Type | Meaning |
|---|---|---|
payload | table | Toast fields. |
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.
JRS.InputAwait(title, subtext, options?)Opens the text box and waits for the answer.
local amount = JRS.InputAwait('Deposit', 'How much?', { type = 'number', min = 1, max = 500 })| Argument | Type | Meaning |
|---|---|---|
title | string | Box title. |
subtext | string | Hint line. |
options | table | Checks 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. |
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.
JRS.GetInput('Name your horse', 'Max 20 letters', function(name)
TriggerServerEvent('my_stable:rename', name)
end, { maxLength = 20 })| Argument | Type | Meaning |
|---|---|---|
title | string | Box title. |
subtext | string | Hint line. |
callback | function | Receives the value. |
JRS.ConfirmAwait(title, firstButton, secondButton)Opens a two-button question and waits.
if JRS.ConfirmAwait('Sell this horse?', 'Sell', 'Keep') then
TriggerServerEvent('my_stable:sell')
end| Argument | Type | Meaning |
|---|---|---|
title | string | The question. |
firstButton | string | Label of the yes button. |
secondButton | string | Label of the no button. |
JRS.GetAnswer(title, firstButton, secondButton, callback)Callback form of ConfirmAwait. JRS.Confirm is the same.
JRS.GetAnswer('Join the posse?', 'Join', 'Decline', function(yes)
if yes then TriggerServerEvent('my_posse:join') end
end)| Argument | Type | Meaning |
|---|---|---|
title | string | The question. |
firstButton | string | Yes label. |
secondButton | string | No label. |
callback | function | Receives the answer. |
JRS.IsInputOpen() and JRS.CloseInput() check and close the box. Menus are opened with JRS.OpenMenu, see the menu page.
Client Helpers#
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.
local ok, hash = JRS.LoadModelSafe('a_c_horse_arabian_white', 5000)| Argument | Type | Meaning |
|---|---|---|
model | string | number | Model name or hash. |
JRS.LoadAnimDict(dict, timeoutMs?)Loads an animation dictionary with a timeout.
if JRS.LoadAnimDict('amb_work@world_human_hammer@table@male_a@trans') then
-- play it
end| Argument | Type | Meaning |
|---|---|---|
dict | string | Dictionary name. |
timeoutMs | number | Default 10000. |
JRS.LoadTextureDict(dict, timeoutMs?)Loads a streamed texture dictionary with a timeout. JRS.LoadTexture(hash) is the older loader.
JRS.LoadTextureDict('inventory_items')| Argument | Type | Meaning |
|---|---|---|
dict | string | Dictionary name. |
timeoutMs | number | Default 10000. |
JRS.PlayAnimation(ped, anim)Loads and plays an animation from a table.
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,
})| Argument | Type | Meaning |
|---|---|---|
ped | number | Ped handle. |
anim | table | dict, name, blendInSpeed, blendOutSpeed, duration, flag, playbackRate. |
JRS.GetNearbyPlayers(maxDistance?, includeSelf?)Lists players around you, nearest first.
for _, p in ipairs(JRS.GetNearbyPlayers(10.0)) do
print(p.serverId, p.distance)
end| Argument | Type | Meaning |
|---|---|---|
maxDistance | number | Radius, default 5.0. |
includeSelf | boolean | Include the local player. |
playerId, serverId, ped, distance.JRS.GetClosestPlayer(maxDistance?)The nearest other player, as one entry from GetNearbyPlayers.
local target = JRS.GetClosestPlayer(3.0)
if target then
TriggerServerEvent('my_trade:request', target.serverId)
end| Argument | Type | Meaning |
|---|---|---|
maxDistance | number | Radius, default 5.0. |
JRS.WaitUntil(check, timeoutMs?, intervalMs?)Waits until a function returns true.
JRS.WaitUntil(function() return DoesEntityExist(wagon) end, 5000)| Argument | Type | Meaning |
|---|---|---|
check | function | Condition to test. |
timeoutMs | number | Default 10000. A negative value waits forever. |
intervalMs | number | Pause between checks, default 10. |
JRS.NoSpam(key, cooldownMs?)A simple cooldown per key.
local ok, wait = JRS.NoSpam('whistle', 2000)
if not ok then return end| Argument | Type | Meaning |
|---|---|---|
key | string | Cooldown name. |
cooldownMs | number | Default 1000. |
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.
JRS.TeleportToCoords(2693.0, -1405.0, 46.6, 180.0)| Argument | Type | Meaning |
|---|---|---|
x | number | X. |
y | number | Y. |
z | number | Z. |
heading | number | Facing. |
JRS.SetCustomDestination(coords, name?, color?)Shows the 3D destination marker. JRS.RemoveCustomDestination() hides it.
JRS.SetCustomDestination(vector3(-178.0, 627.0, 114.0), 'Valentine station')| Argument | Type | Meaning |
|---|---|---|
coords | vector3 | Target. A missing z is filled from the ground. |
name | string | Label. |
color | any | Marker color. |
JRS.HealPlayer()Heals the local player.
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.
JRS.AcquireUI(owner?, options?)Claims the screen for your UI. The owner defaults to your resource. Also an export.
local ok = JRS.AcquireUI(nil, { focus = true, cursor = true })
if not ok then return end
SendNUIMessage({ action = 'open' })| Argument | Type | Meaning |
|---|---|---|
owner | string | Owner name. |
options | table | For example focus, cursor, force. |
'ui_busy:<owner>'.JRS.ReleaseUI(owner?, options?)Gives the screen back. Also an export.
JRS.ReleaseUI()| Argument | Type | Meaning |
|---|---|---|
owner | string | Owner name. |
JRS.IsUIBusy(owner?)Asks if another UI holds the screen. Also an export.
if JRS.IsUIBusy() then return end| Argument | Type | Meaning |
|---|---|---|
owner | string | Your owner name, left out of the check. Defaults to your resource. |
JRS.GetOpenUI()Reads the current screen owner state. Also an export.
local state = JRS.GetOpenUI(){ busy = boolean }.Client Progress And Trade#
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.
JRS.Progress({ duration = 5000, label = 'Skinning...' }, function(cancelled)
if not cancelled then TriggerServerEvent('my_hunt:skin') end
end)| Argument | Type | Meaning |
|---|---|---|
action | table | number | duration, label, canCancel, useWhileDead, brand, or just a duration. |
finish | function | Receives 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.