jrs_core hands every script one table that holds its helpers. You get it with exports.jrs_core:GetCoreObject() (or the alias getCoreApi()), and the server and client each get their own version of the table. This page follows a player through the core: account and group, the character and its jobs, the state bags and events that track it, money, health and position, and then the helpers for notices, callbacks and logging.
Getting Started#
exports.jrs_core:GetCoreObject()Builds the core table for the side you call it from. Call it once at the top of a file and keep the result in a local. getCoreApi() is the same function under another name.
local JRS = exports.jrs_core:GetCoreObject()
RegisterCommand('whoami', function(src)
local name = JRS.GetCharacterName(src)
JRS.NotifyRightTip(src, ('You are %s'):format(name or 'nobody'), 4000)
end)User Accounts#
A user is the account row of a connected player (one per Steam or license id). The character they are playing hangs off it as getUsedCharacter.
| Field | Type | What it holds |
|---|---|---|
identifier |
string | Account identifier stored in jrs_users. |
group |
string | Permission group, for example user or admin. |
chars |
number | How many character slots the account may use. |
warnings |
number | Warning counter from the database. |
banned |
number | Ban flag from the database. |
getUsedCharacter |
table or nil | The selected character object (see Characters). |
JRS.getUser(source)Looks up the account of an online player. Also available as JRS.GetUser and as the direct exports exports.jrs_core:GetUser(source) and exports.jrs_core:getUser(source).
local user = JRS.getUser(src)
if not user then return end
print(user.identifier, user.group, user.chars)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
user.setGroup(source, targetId, groupName)Changes the permission group of targetId. It forwards to JRS.SetGroup, so prefer calling that directly.
user.setGroup(src, src, 'moderator')| Argument | Type | Meaning |
|---|---|---|
source | number | Caller id. Only checked for nil. |
targetId | number | Player whose group changes. |
groupName | string | New group name. |
user.setUsedCharacter(source, charIdentifier, characterRow?)Selects one of the account's characters for the player. The character selector uses it; normal scripts rarely need it.
local ok = user.setUsedCharacter(src, 12)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
charIdentifier | number | Character id to select. |
characterRow | tableoptional | A jrs_characters row. Its id must match charIdentifier. |
JRS.GetIdentifiers(source)Collects every identifier of a player into a table keyed by type.
local ids = JRS.GetIdentifiers(src)
print(ids.discord or 'no discord linked')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
{ steam = 'steam:...', license = 'license:...', discord = 'discord:...' }.exports.jrs_core:GetPlayerIdentity(source)A light export that returns plain data only, handy for resources that check identity many times a second.
local id = exports.jrs_core:GetPlayerIdentity(src)
if id then print('playing char', id.charIdentifier) end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
{ identifier, charIdentifier }, or nil when no character is selected.Groups And Permissions#
JRS.GetGroup(source)Reads the permission group from the core cache. Also exported as exports.jrs_core:GetGroup(source).
if JRS.GetGroup(src) == 'admin' then
-- admin only branch
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.SetGroup(source, group, callback?)Writes a new group to the cache and to jrs_users. Accounts listed as core owners can never be moved off owner. Also exported as exports.jrs_core:SetGroup(source, group).
JRS.SetGroup(target, 'moderator', function(ok, group)
print('group saved', ok, group)
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
group | string | New group name. |
callback | functionoptional | Called as callback(ok, group, result) once the database write finishes. |
JRS.RefreshGroup(source, callback?)Re-reads the group from the database. Use it after you edit jrs_users.group by hand while the player is online.
JRS.RefreshGroup(src)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
callback | functionoptional | Called when the refresh is done. |
exports.jrs_core:IsAdmin(source)Checks whether a player's group counts as an admin group in the core config. Source 0 (the server console) is always allowed.
if not exports.jrs_core:IsAdmin(src) then return end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
exports.jrs_core:CanUseCommand(source, commandKey)Asks the core permission table whether the player's group may run a named command. Use this instead of writing your own group lists.
RegisterCommand('tpm', function(src)
if not exports.jrs_core:CanUseCommand(src, 'tpm') then return end
TriggerClientEvent('myscript:tpm', src)
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. 0 is always allowed. |
commandKey | string | Command key from the core permission config. |
Joining the server is gated separately, before any group is read. The connect check is switched on with Config.Whitelist (or Config.WhitelistDiscord, which also allows the role in Config.DiscordWhitelistRole) in jrs_core/config/config.lua, and it lets a player in when their Steam or Discord id has a row in jrs_whitelist or jrs_discord_whitelist; core owners always pass. There is nothing to call from a script; add or remove rows in those tables instead.
Characters#
The character object is what getUser(source).getUsedCharacter or GetCharacter(source) returns. It is a live table: values change when the core changes them, so read them when you need them.
| Field | Type | What it holds |
|---|---|---|
identifier |
string | Owning account identifier. |
charIdentifier |
number | Character id (jrs_characters.charidentifier). |
firstname, lastname, nickname |
string | Names. |
gender, dateofbirth, occupation, character_desc |
string | Identity fields. |
money, gold, rol, dirtymoney |
number | Balances. |
job, jobgrade, joblabel |
string, number, string | Active job. |
onduty |
boolean | Duty flag for the active job. |
multijobs |
table | Every job the character holds, keyed by job name: { grade, label }. |
skills |
table | Skill data keyed by skill name. |
meta |
string | JSON text of the character metadata. |
skin, comp, inventory, coords |
string | JSON text columns. |
xp, level |
number | Core level progress. |
JRS.GetCharacter(source)Returns the selected character, but only once it is fully ready. During loading, switching or logout it returns nil, which keeps half-loaded data out of your script. Lower-case getCharacter is the same function.
local char = JRS.GetCharacter(src)
if not char then return end
print(char.firstname, char.job, char.money)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.IsCharacterReady(source)Quick yes or no for "is this player in game with a character". IsIdentityReady is an alias.
if not JRS.IsCharacterReady(src) then return end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.GetCharacterState(source)Short status record of the player's character. Also exported as exports.jrs_core:GetCharacterState(source).
local state = JRS.GetCharacterState(src)
print(state.ready, state.charIdentifier)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
{ ready, version, identifier, charIdentifier }.JRS.ClearCharacter(source, reason?)Marks the character as unloaded. It clears the character state bags and fires the unload events.
JRS.ClearCharacter(src, 'kicked_to_selector')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
reason | stringoptional | Text passed on to the characterUnloaded events. |
JRS.GetCharacterData(source)A flat copy of the most used character values. Safe to send over the network or to keep, because it has no functions in it. Also exported directly.
local data = JRS.GetCharacterData(src)
TriggerClientEvent('myscript:profile', src, data)| 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)First and last name joined with a space. Falls back to the player's Steam name when the character has no name.
print(JRS.GetCharacterName(src) .. ' opened the shop')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
character.setJob(source, job, grade)Sets the active job, saves it and updates the Job, JobGrade and JobLabel state bags. The job is also added to multijobs. It can refuse when the character has no valid identity yet.
local char = JRS.GetCharacter(src)
local ok, why = char.setJob(src, 'sheriff', 2)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job name. |
grade | number | Grade, defaults to 0. |
character.setMeta(source, metaTable)Replaces the whole metadata table and saves it. For single keys use the Metadata helpers below.
char.setMeta(src, { hunger = 80, thirst = 75 })| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
metaTable | table | Full metadata table. |
character.addCurrency(source, currencyType, amount)Adds to one balance, saves it and refreshes the HUD. Amounts must be above 0 and below one billion.
char.addCurrency(src, 0, 12.50)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
currencyType | number | 0 money, 1 gold, 2 rol, 3 dirty money. |
amount | number | Amount to add. |
character.removeCurrency(source, currencyType, amount)Takes from one balance. It does not check the balance first, so test it yourself or use removeAccount.
if char.money >= 5 then char.removeCurrency(src, 0, 5) end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
currencyType | number | 0 money, 1 gold, 2 rol, 3 dirty money. |
amount | number | Amount to remove. |
character.changeSkin(source, clothingTable)Hands a new outfit to jrs_clothing and reloads the clothes on the player. buySkin(source, name, clothingTable) does the same and takes an outfit name first.
char.changeSkin(src, outfit)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
clothingTable | table | Clothing components. |
character.buySkinPlayer(source, skinData)Saves new body and face data into the skinPlayer column.
char.buySkinPlayer(src, newSkin)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
skinData | table | Skin values. |
character.addXP(amount, reason?, callback?)XP helpers live on the character too: addXP, removeXP, setXP, setLevel, addLevel, removeLevel, plus the readers getXP() and getLevel(). You may pass the source first, as in addXP(source, amount, reason), or leave it out.
char.addXP(25, 'fished_trout')
print('level', char.getLevel())| Argument | Type | Meaning |
|---|---|---|
amount | number | XP to add. |
reason | stringoptional | Reason saved with the change. |
callback | functionoptional | Called when the XP system finishes. |
player_not_found when the character has no online player.JRS.GetCharacterById(charId)Fetches a character by id, online or not. GetOfflineCharacter(charId) reads the database row only.
local row = JRS.GetCharacterById(42)
if row then print(row.firstname) end| Argument | Type | Meaning |
|---|---|---|
charId | number | Character id. |
JRS.GetCharactersByIdentifier(identifier)Lists every character that belongs to one account.
for _, c in ipairs(JRS.GetCharactersByIdentifier(user.identifier)) do
print(c.charIdentifier, c.firstname)
end| Argument | Type | Meaning |
|---|---|---|
identifier | string | Account identifier. |
JRS.FindCharactersByName(firstname, lastname?)Searches characters by name, for police records, mail and similar tools.
local hits = JRS.FindCharactersByName('Arthur', 'Morgan')| Argument | Type | Meaning |
|---|---|---|
firstname | string | First name to search. |
lastname | stringoptional | Last name to narrow the search. |
JRS.GetCharacterCount(source)Number of characters the player's account already has. Pair it with GetMaxCharacters(source) and CanCreateCharacter(source).
print(JRS.GetCharacterCount(src) .. ' / ' .. JRS.GetMaxCharacters(src))
if JRS.CanCreateCharacter(src) then print('free slot') end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.SaveCharacter(source)Writes the in-memory character to the database right away. Use it before a risky action such as a server restart command.
JRS.SaveCharacter(src)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.saveLocation(source, coords?, heading?)Stores where the character will spawn next time. Without coords it uses the ped's current position.
JRS.saveLocation(src, vector3(-281.0, 790.2, 118.6), 90.0)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
coords | vector3optional | Position to store. |
heading | numberoptional | Heading to store. |
JRS.getLastSavedLocation(source)Reads the last stored spawn position.
local pos = JRS.getLastSavedLocation(src)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
{ x, y, z, heading }.Character Metadata#
Metadata is a free key and value store on each character, saved as JSON. Every write fires jrs_core:server:metadataChanged.
JRS.Metadata.Get(source, key?, default?)Reads one key, or the whole table when key is nil.
local kills = JRS.Metadata.Get(src, 'bounty_kills', 0)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | stringoptional | Key to read. |
default | anyoptional | Returned when the key is missing or no character is loaded. |
JRS.Metadata.Set(source, key, value)Writes one key and saves it.
JRS.Metadata.Set(src, 'tutorial_done', true)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Key to write. |
value | any | Value to store. |
JRS.Metadata.Add(source, key, amount)Adds to a number key. Metadata.Remove(source, key, amount) subtracts.
JRS.Metadata.Add(src, 'bounty_kills', 1)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Number key. |
amount | number | Amount to add. |
Jobs#
A character can hold several jobs in multijobs but only one is active at a time.
exports.jrs_core:SetJob(source, job, grade)The stable way to set the active job from another resource. It checks the character is ready, saves the job and tells the client. exports.jrs_core:setJob and JRS.setJob do the same.
local ok, why = exports.jrs_core:SetJob(src, 'doctor', 1)
if not ok then print('hire failed: ' .. why) end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job name. |
grade | number | Grade, rounded down, never below 0. |
character_not_ready.JRS.setJobGrade(source, grade)Promotes or demotes inside the active job.
JRS.setJobGrade(src, 3)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
grade | number | New grade. |
JRS.getJob(source)Active job name. getJobGrade(source) returns the grade.
if JRS.getJob(src) == 'sheriff' and JRS.getJobGrade(src) >= 2 then
-- deputy and above
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.GetJobPlayers(job)Finds online players whose active job matches.
local docs = JRS.GetJobPlayers('doctor')
print(docs.count .. ' doctors online')| Argument | Type | Meaning |
|---|---|---|
job | string | Job name. |
{ players = { { source = id }, ... }, count = n }.JRS.Jobs.Get(source)All jobs the character holds. The active job is always in the list.
for job, info in pairs(JRS.Jobs.Get(src)) do
print(job, info.grade, info.label)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
{ [job] = { grade, label } }.JRS.Jobs.Add(source, job, grade?, label?)Gives the character another job without making it active. Respects the job limit in the character service config.
JRS.Jobs.Add(src, 'farmer', 0, 'Farmer')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job name. |
grade | numberoptional | Grade, defaults to 0. |
label | stringoptional | Display label, defaults to the job name. |
max_jobs or invalid_job on failure.JRS.Jobs.Remove(source, job)Takes a held job away. The active job cannot be removed.
JRS.Jobs.Remove(src, 'farmer')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | Job name. |
active_job or not_found on failure.JRS.Jobs.Switch(source, job)Makes a held job the active one, then sets the player off duty. A cooldown from config applies.
local ok, why = JRS.Jobs.Switch(src, 'farmer')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | A job the character already holds. |
job_not_owned or cooldown on failure.JRS.Jobs.SetDuty(source, state)Puts the player on or off duty, saves it and updates the OnDuty state bag. Jobs.ToggleDuty(source) flips it and returns the new value.
JRS.Jobs.SetDuty(src, true)
local now = JRS.Jobs.ToggleDuty(src)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
state | boolean | true for on duty. |
JRS.Jobs.GetDutyPlayers(job)Players of a job who are on duty right now.
local list, count = JRS.Jobs.GetDutyPlayers('sheriff')| Argument | Type | Meaning |
|---|---|---|
job | string | Job name. |
State Bags#
The core keeps these keys on Player(source).state. They replicate to the owning client, so read them with LocalPlayer.state.Key on the client. Values reset to false when the character unloads.
| Key | Type | Meaning |
|---|---|---|
CharacterReady |
boolean | A character is loaded and playable. |
CharacterId |
number | Character id. |
CharacterIdentifier |
string | Owning account identifier. |
FirstName, LastName, Nickname |
string | Names. |
Gender |
string | Character gender. |
Job, JobGrade, JobLabel |
string, number, string | Active job. |
OnDuty |
boolean | Duty flag. |
Group |
string | Permission group. |
jrsPvp |
boolean | PvP allowed for this player. |
jrsLanguage |
string | Chosen UI language. |
jrsPerks |
table | Unlocked level perks. |
isDead |
boolean | Free edition: the player is down. |
IsInSession, jrsPlayer |
boolean, table | Free edition: player object is active, and a snapshot of it. |
-- server
local job = Player(src).state.Job
-- client
AddStateBagChangeHandler('Job', ('player:%s'):format(GetPlayerServerId(PlayerId())), function(_, _, value)
print('my job is now', value)
end)Client Character Checks#
JRS.IsCharacterReady()Local check backed by the CharacterReady state bag.
if not JRS.IsCharacterReady() then return endJRS.WaitForCharacterReady(timeoutMs?)Blocks the current thread until the character is ready or the time runs out.
CreateThread(function()
if JRS.WaitForCharacterReady(30000) then LoadMyHud() end
end)| Argument | Type | Meaning |
|---|---|---|
timeoutMs | numberoptional | Defaults to 10000. |
exports.jrs_core:GetCharacterStateLocal()Reads the character state bags of the local player into one table, without any server call.
local me = exports.jrs_core:GetCharacterStateLocal()
print(me.firstname, me.job)ready, charIdentifier, identifier, firstname, lastname, job, jobGrade, jobLabel, onDuty, gender.Events#
All server events are local events (AddEventHandler). Client events arrive from the server, so register them with RegisterNetEvent.
AddEventHandler('jrs_core:server:characterReady', function(source, character) end)Fires once the selected character is fully loaded. Start per-player work here instead of waiting for a spawn. jrs_core:server:characterLoaded fires right before it with the same arguments.
AddEventHandler('jrs_core:server:characterReady', function(src, char)
print(char.firstname .. ' is in game')
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
character | table | The character object. |
AddEventHandler('jrs_core:server:characterUnloaded', function(source, previous, reason) end)Fires when a character leaves play: logout, switch or disconnect. Clean up your per-player tables here.
AddEventHandler('jrs_core:server:characterUnloaded', function(src)
ActiveJobs[src] = nil
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
previous | table | nil | The character that was active. |
reason | string | Why it was unloaded. |
AddEventHandler('jrs_core:server:characterCreated', function(source, charId, identifier) end)A brand new character was written to the database.
AddEventHandler('jrs_core:server:characterCreated', function(src, charId)
print('welcome kit for char ' .. charId)
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
charId | number | New character id. |
identifier | string | Account identifier. |
AddEventHandler('jrs_core:server:characterSaved', function(source, character) end)The character service finished a save.
AddEventHandler('jrs_core:server:characterSaved', function(src) end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
character | table | The character object. |
AddEventHandler('jrs_core:server:jobChanged', function(source, job, grade) end)The active job or grade changed.
AddEventHandler('jrs_core:server:jobChanged', function(src, job, grade)
if job ~= 'sheriff' then RemoveBadge(src) end
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
job | string | New job. |
grade | number | New grade. |
AddEventHandler('jrs_core:server:multiJobChanged', function(source, jobs) end)A job was added to or removed from the held jobs.
AddEventHandler('jrs_core:server:multiJobChanged', function(src, jobs) end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
jobs | table | The new held jobs table. |
AddEventHandler('jrs_core:server:dutyChanged', function(source, onDuty, job) end)The duty flag changed.
AddEventHandler('jrs_core:server:dutyChanged', function(src, onDuty, job)
print(job, onDuty and 'clocked in' or 'clocked out')
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
onDuty | boolean | New state. |
job | string | Active job. |
AddEventHandler('jrs_core:server:metadataChanged', function(source, key, value) end)One metadata key was written.
AddEventHandler('jrs_core:server:metadataChanged', function(src, key, value) end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
key | string | Changed key. |
value | any | New value. |
AddEventHandler('jrs_core:server:skillLevelChanged', function(source, skill, newLevel, oldLevel) end)Fires when JRS.Skills.SetXP or JRS.Skills.AddXP (or the SetSkillXP / AddSkillXP exports) leaves a skill on a different level than before. A negative AddXP can drop the level, so compare newLevel with oldLevel to tell a gain from a loss.
AddEventHandler('jrs_core:server:skillLevelChanged', function(src, skill, new)
if skill == 'hunting' and new == 10 then GiveTitle(src, 'Tracker') end
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
skill | string | Skill name. |
newLevel | number | Level now. |
oldLevel | number | Level before. |
AddEventHandler('jrs_core:server:onPlayerDeath', function(source) end)Free edition. The player died. jrs_core:server:onPlayerRevived fires when they are revived or respawned.
AddEventHandler('jrs_core:server:onPlayerDeath', function(src)
CancelDelivery(src)
end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
AddEventHandler('jrs_core:server:onGroupChange', function(source, group) end)Free edition. Fired by the player object's SetGroup. Its SetJob fires jrs_core:server:onJobChange with (source, job, grade).
AddEventHandler('jrs_core:server:onGroupChange', function(src, group) end)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
group | string | New group. |
RegisterNetEvent('jrs_core:client:characterReady', function(charId) end)The local character is ready. The core also re-fires it locally as jrs_core:characterReady.
RegisterNetEvent('jrs_core:client:characterReady', function(charId)
SpawnCampProps()
end)| Argument | Type | Meaning |
|---|---|---|
charId | number | Character id. |
RegisterNetEvent('jrs_core:client:characterUnloaded', function(reason) end)The local character left play. Close menus and delete local entities here.
RegisterNetEvent('jrs_core:client:characterUnloaded', function()
DeleteCampProps()
end)| Argument | Type | Meaning |
|---|---|---|
reason | string | Why it was unloaded. |
RegisterNetEvent('jrs_core:client:jobChanged', function(job, grade) end)The local active job changed. Also re-fired locally as jrs_core:jobChanged.
RegisterNetEvent('jrs_core:client:jobChanged', function(job)
RefreshJobBlips(job)
end)| Argument | Type | Meaning |
|---|---|---|
job | string | New job. |
grade | number | New grade. |
RegisterNetEvent('jrs_core:client:dutyChanged', function(onDuty, job) end)The local duty flag changed.
RegisterNetEvent('jrs_core:client:dutyChanged', function(onDuty) end)| Argument | Type | Meaning |
|---|---|---|
onDuty | boolean | New state. |
job | string | Active job. |
RegisterNetEvent('jrs_core:client:skillLevelChanged', function(skill, newLevel, oldLevel) end)The server's copy of skillLevelChanged for the local character, sent from the same XP write. Also re-fired locally as jrs_core:skillLevelChanged.
RegisterNetEvent('jrs_core:client:skillLevelChanged', function(skill, new) end)| Argument | Type | Meaning |
|---|---|---|
skill | string | Skill name. |
newLevel | number | Level now. |
oldLevel | number | Level before. |
RegisterNetEvent('jrs:SelectedCharacter', function(charId) end)Sent the moment a character is picked in the selector, just before jrs:isPlayerready.
RegisterNetEvent('jrs:SelectedCharacter', function(charId) end)| Argument | Type | Meaning |
|---|---|---|
charId | number | Character id. |
RegisterNetEvent('jrs_core:instanceChanged', function(bucket) end)Sent by every SetPlayerInstance call, numeric or named, once the server has moved the local player.
RegisterNetEvent('jrs_core:instanceChanged', function(bucket)
InInterior = bucket ~= 0
end)| Argument | Type | Meaning |
|---|---|---|
bucket | number | New bucket, 0 for the shared world. |
AddEventHandler('jrs_core:client:onDeath', function(killer, cause) end)Free edition, local event. The local player died. jrs_core:client:onRevived and jrs_core:client:onHospitalRespawn (with the clinic name) follow when they come back.
AddEventHandler('jrs_core:client:onDeath', function(killer)
if killer ~= 0 then print('killed by player ' .. killer) end
end)| Argument | Type | Meaning |
|---|---|---|
killer | number | Killer server id, 0 when not a player. |
cause | number | Weapon or cause hash. |
Accounts And Money#
Currency types are numbers everywhere: 0 money, 1 gold, 2 rol, 3 dirty money.
JRS.getAccount(source, currencyType)Current balance of one currency, read from the live character.
local gold = JRS.getAccount(src, 1)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
currencyType | number | 0 to 3. |
JRS.addAccount(source, currencyType, quantity)Adds to a balance.
JRS.addAccount(src, 0, 20)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
currencyType | number | 0 to 3. |
quantity | number | Amount above 0. |
JRS.removeAccount(source, currencyType, quantity)Takes from a balance. Unless the config allows negative balances it never goes below zero: an empty account returns false and a larger amount is cut down to what is there.
if JRS.getAccount(src, 0) >= 15 then JRS.removeAccount(src, 0, 15) end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
currencyType | number | 0 to 3. |
quantity | number | Amount above 0. |
JRS.GetBalance(source)All balances in one call. Also an export.
local b = exports.jrs_core:GetBalance(src)
print(b.money, b.gold)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
{ money, gold, rol, dirtymoney, blackmoney }. blackmoney mirrors dirtymoney.Health, Death And PvP#
Whether a player is alive, hurt or fair game for other players. The death checks and revive calls come from server/jrs_death.lua and client/jrs_death.lua, which ship with the free edition; healing and the PvP flag work in every edition.
exports.jrs_core:IsPlayerDead(source)Whether the core has the player marked as dead.
if exports.jrs_core:IsPlayerDead(src) then return end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
exports.jrs_core:IsDead()Local check for the death screen.
if exports.jrs_core:IsDead() then return endexports.jrs_core:RevivePlayer(source)Brings the player back where they fell, full health.
exports.jrs_core:RevivePlayer(patient)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
exports.jrs_core:RespawnPlayer(source)Sends the player to the nearest clinic and revives them there.
exports.jrs_core:RespawnPlayer(src)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
JRS.HealPlayer([source])Fills health and stamina cores. On the server pass the player id; on the client it heals the local player.
JRS.HealPlayer(src)| Argument | Type | Meaning |
|---|---|---|
source | number | Server only. Player server id. |
exports.jrs_core:IsPlayerPvpEnabled(source)Whether a player can be damaged by other players. Reads the jrsPvp state bag, or the gameplay config when it is unset.
if not exports.jrs_core:IsPlayerPvpEnabled(target) then return end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
exports.jrs_core:SetPlayerPvp(source, state, silent?)Turns PvP on or off for one player. TogglePlayerPvp(source) flips it.
exports.jrs_core:SetPlayerPvp(src, false, true)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
state | boolean | true to allow PvP. |
silent | booleanoptional | true hides the on-screen notice. |
Online Players#
GetPlayers comes from the core table. The three exports after it belong to the free edition player object in server/jrs_player.lua, which wraps a loaded character in a table with methods.
JRS.GetPlayers()Online players that have a character loaded. GetOnlinePlayerCount() counts everyone connected.
for _, p in ipairs(JRS.GetPlayers().players) do
JRS.NotifyTip(p.source, 'Server event starting', 5000)
end{ players = { { source = id }, ... }, count = n }.exports.jrs_core:GetPlayer(source)Returns the player object, built on first use. Methods are called with a colon: GetName, GetCharId, GetJob, GetJobGrade, GetJobLabel, SetJob(job, grade), GetGroup, SetGroup(group), IsAdmin, GetMoney, AddMoney(amount), RemoveMoney(amount), the same three for Gold and Rol, GetXP, GetLevel, AddXP(amount, reason), RemoveXP(amount, reason) and Notify(text, duration).
local p = exports.jrs_core:GetPlayer(src)
if p and p:RemoveMoney(10) then
p:Notify('Paid $10 for the room', 4000)
end| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
exports.jrs_core:GetPlayerByCharId(charId)Finds the online player object for a character id.
local owner = exports.jrs_core:GetPlayerByCharId(house.owner)| Argument | Type | Meaning |
|---|---|---|
charId | number | Character id. |
exports.jrs_core:GetAllPlayers()Player objects for everyone in game with a character.
for _, p in ipairs(exports.jrs_core:GetAllPlayers()) do print(p:GetName()) endPosition And Instances#
Moving a player, pointing them somewhere, or putting them in a routing bucket of their own. Players in different buckets do not see or hit each other, and the client hears about every bucket change through jrs_core:instanceChanged (see Events).
JRS.TeleportPlayer(source, x, y, z, heading?)Sends a player to a position. On the client use JRS.TeleportToCoords(x, y, z, heading) or JRS.TeleportToWaypoint().
JRS.TeleportPlayer(src, 2717.1, -1441.3, 46.1, 120.0)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
x | number | X. |
y | number | Y. |
z | number | Z. |
heading | numberoptional | Heading. |
JRS.SetWaypoint(source, coords, name?, color?)Shows the 3D destination marker to a player. RemoveWaypoint(source) hides it.
JRS.SetWaypoint(src, vector3(-361.2, 791.7, 116.2), 'Doctor')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
coords | vector3 | Destination. |
name | stringoptional | Label above the marker. |
color | stringoptional | Marker colour. |
JRS.SetPlayerInstance(source, instance)Moves a player into a routing bucket. A number goes straight to that bucket. A string is treated as a room name: the core reuses the bucket of a live room with that name, or picks a free one between 1 and 63 and remembers the name, so two scripts never have to agree on bucket numbers.
local ok, bucket = JRS.SetPlayerInstance(src, 'house_' .. houseId)
-- later
JRS.SetPlayerInstance(src, 0)| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
instance | number | string | Bucket id, or a room name. Use 0 for the shared world. |
JRS.SetPlayerInstance(instance)Sends the move request for the local player to the server, which applies the same room-name rules. Passing 0 also takes the player out of every named room, and an empty room is freed. JRS.instancePlayers(instance) is kept as an alias for older scripts.
-- everyone seated at the same card table shares one room
JRS.SetPlayerInstance('cardtable_' .. tableId)| Argument | Type | Meaning |
|---|---|---|
instance | number | string | Room name, or 0 for the shared world. |
Notifications#
Start with the toast helpers: Notify, Toast, ShowNotification and the client shortcuts render in the core's own toast style and are what most JRS scripts use. The native game feeds come after them, grouped by job: quick feedback lines, icon cards, banners, then mission results and alerts that play a sound. Every native style exists on both sides; on the server pass the player id first, on the client start at the text. Durations are in milliseconds, and each style is also an export, for example exports.jrs_core:NotifyTip(...).
JRS.Notify([source,] text, notifyType?, duration?, title?)The general purpose notice. It goes through the right tip path, which the core routes to its toast renderer. On the server only text and duration are used.
JRS.Notify(src, 'Saved', 'success', 3000)| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
notifyType | stringoptional | Client only: info, success, error, warning or reward. |
duration | numberoptional | Defaults to 3500. |
title | stringoptional | Client only heading. |
JRS.Toast([source,] text, notifyType?, duration?, title?)Shows a styled toast and tags it with the name of the calling resource.
JRS.Toast(src, 'Horse stabled', 'info', 4000, 'Stable')| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
notifyType | stringoptional | info, success, error, warning or reward. |
duration | numberoptional | Time on screen. |
title | stringoptional | Heading. |
JRS.ShowNotification([source,] payload)Toast built from one table, for when you want to set several options at once.
JRS.ShowNotification(src, { text = 'Bounty claimed', type = 'reward', duration = 5000 })| Argument | Type | Meaning |
|---|---|---|
payload | table | { text, type, duration, title }. |
JRS.Success(text, duration?, title?)Shortcut toasts by type: Info, Success, ErrorNotify, WarningNotify and RewardNotify all take the same arguments.
JRS.Success('Recipe learned')
JRS.ErrorNotify('Not enough wood', 3000)| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
duration | numberoptional | Time on screen. |
title | stringoptional | Heading. |
JRS.NotifyRightTip([source,] text, duration)Short message on the right side. Good default for "you received" style feedback.
JRS.NotifyRightTip(src, 'You sold 4 pelts', 4000)| Argument | Type | Meaning |
|---|---|---|
source | number | Server only. Player server id. |
text | string | Message. |
duration | number | Time on screen. |
JRS.NotifyTip([source,] text, duration)Small hint in the top left.
JRS.NotifyTip('Press G to open the camp menu', 5000)| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
duration | number | Time on screen. |
JRS.NotifyBasicTop([source,] text, duration)One plain line at the top.
JRS.NotifyBasicTop(src, 'Storm incoming', 3000)| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
duration | number | Time on screen. |
JRS.NotifyBottomRight([source,] text, duration)Small text in the lower right corner.
JRS.NotifyBottomRight(src, 'Autosaved', 2000)| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
duration | number | Time on screen. |
JRS.NotifyCenter([source,] text, duration)Text in the middle of the screen.
JRS.NotifyCenter(src, 'Round two', 2500)| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
duration | number | Time on screen. |
JRS.NotifyLeft([source,] title, subtitle, dict, icon, duration, color?)Card on the left with a texture icon.
JRS.NotifyLeft(src, 'Bank', 'Deposit done', 'menu_textures', 'menu_icon_tick', 4000, 'COLOR_GREEN')| Argument | Type | Meaning |
|---|---|---|
title | string | Bold first line. |
subtitle | string | Second line. |
dict | string | Texture dictionary of the icon. |
icon | string | Texture name. |
duration | number | Time on screen. |
color | stringoptional | Colour name, defaults to COLOR_WHITE. |
JRS.NotifyLeftRank([source,] title, subtitle, dict, icon, duration, color?)Same layout as NotifyLeft in the rank-up style.
JRS.NotifyLeftRank(src, 'Level 12', 'Fishing', 'toast_awards_set_h', 'awards_set_h_006', 5000)| Argument | Type | Meaning |
|---|---|---|
title | string | First line. |
subtitle | string | Second line. |
dict | string | Texture dictionary. |
icon | string | Texture name. |
duration | number | Time on screen. |
color | stringoptional | Colour name. |
JRS.NotifyAdvanced([source,] text, dict, icon, textColor, duration, quality?)Transaction-style card on the right with a texture icon, coloured text and the positive transaction sound. The misspelled NotifyAvanced still works.
JRS.NotifyAdvanced(src, 'Bought: fishing rod', 'menu_textures', 'menu_icon_tick', 'COLOR_PURE_WHITE', 4000)| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
dict | string | Texture dictionary. |
icon | string | Texture name. |
textColor | string | Colour name. |
duration | number | Time on screen. |
quality | numberoptional | Accepted for compatibility. The feed only draws it when an internal flag is set, which this wrapper never does, so today it has no visible effect. |
JRS.NotifyTop([source,] text, location, duration)Big location banner at the top, like entering a town.
JRS.NotifyTop(src, 'Welcome', 'Valentine', 4000)| Argument | Type | Meaning |
|---|---|---|
text | string | Main text. |
location | string | Smaller location line. |
duration | number | Time on screen. |
JRS.NotifySimpleTop([source,] title, subtitle, duration)Two-line banner at the top centre.
JRS.NotifySimpleTop(src, 'Race', 'Starts in 10 seconds', 3000)| Argument | Type | Meaning |
|---|---|---|
title | string | First line. |
subtitle | string | Second line. |
duration | number | Time on screen. |
JRS.NotifyObjective([source,] text, duration)Mission objective line at the bottom of the screen.
JRS.NotifyObjective(src, 'Deliver the crate to Rhodes', 8000)| Argument | Type | Meaning |
|---|---|---|
text | string | Objective. |
duration | number | Time on screen. |
JRS.NotifyUpdate([source,] title, message, duration)"Mission updated" style banner.
JRS.NotifyUpdate(src, 'New stop', 'Head to Strawberry', 4000)| Argument | Type | Meaning |
|---|---|---|
title | string | First line. |
message | string | Second line. |
duration | number | Time on screen. |
JRS.NotifyFail([source,] title, subtitle, duration)Red "mission failed" style banner.
JRS.NotifyFail(src, 'Delivery failed', 'The wagon was destroyed', 5000)| Argument | Type | Meaning |
|---|---|---|
title | string | First line. |
subtitle | string | Second line. |
duration | number | Time on screen. |
JRS.NotifyWarning([source,] title, message, audioRef, audioName, duration)Warning banner with a sound.
JRS.NotifyWarning(src, 'Wanted', 'Lawmen are on the way', 'Ledger_Sounds', 'INFO_HIDE', 5000)| Argument | Type | Meaning |
|---|---|---|
title | string | First line. |
message | string | Second line. |
audioRef | string | Sound set. |
audioName | string | Sound name. |
duration | number | Time on screen. |
JRS.NotifyDead([source,] title, audioRef, audioName, duration)Death screen style title with a sound.
JRS.NotifyDead(src, 'You were shot', 'Ledger_Sounds', 'INFO_HIDE', 4000)| Argument | Type | Meaning |
|---|---|---|
title | string | Text. |
audioRef | string | Sound set. |
audioName | string | Sound name. |
duration | number | Time on screen. |
Native Buffers (DataView)#
Some RDR3 natives, including the UI feed calls behind the native notifications above, take pointers to C structs rather than plain values. Plain Lua cannot lay out those bytes, so the core carries DataView, a small byte buffer, and fills its own feed structs with it. The function below is the same call NotifyBasicTop makes inside the core, rebuilt for your own script:
local JRS = exports.jrs_core:GetCoreObject()
local function TopLine(text, duration)
local config = DataView.ArrayBuffer(8 * 7)
config:SetInt32(0, duration)
local data = DataView.ArrayBuffer(8 * 7)
data:SetInt64(8 * 1, JRS.BigInt(CreateVarString(10, 'LITERAL_STRING', text)))
Citizen.InvokeNative(0x7AE0589093A2E088, config:Buffer(), data:Buffer(), 1)
endDataView is a global from client/dataview.lua, so your resource gets it by listing '@jrs_core/client/dataview.lua' in its client_scripts.
DataView.ArrayBuffer(length)Makes a zero-filled buffer. Read and write it with GetInt32(offset), SetInt32(offset, value) and the same pair for Int8, Uint8, Int16, Uint16, Uint32, Int64, Uint64, Float32, Float64, LuaInt, LuaNum and String. Buffer() returns the raw string to pass to a native.
local view = DataView.ArrayBuffer(16)
view:SetFloat32(0, 1.5)
print(view:GetFloat32(0), view:ByteLength())| Argument | Type | Meaning |
|---|---|---|
length | number | Size in bytes. |
Server And Client Callbacks#
Callbacks let one side ask the other for a value. The object methods below are limited to 30 calls per second per player, 64 KB of data, and give up after 10 seconds.
JRS.RegisterServerCallback(name, handler)Answers client requests. The handler gets the player id and the client's arguments; what it returns goes back.
JRS.RegisterServerCallback('jrs_stores:price', function(src, item)
return Prices[item] or 0
end)| Argument | Type | Meaning |
|---|---|---|
name | string | Unique name, up to 128 characters. |
handler | function | function(source, ...) return values end. |
JRS.TriggerClientCallback(source, name, ...)Asks one client for a value and waits for the answer. Call it inside a thread.
local ok, street = JRS.TriggerClientCallback(src, 'myscript:street')| Argument | Type | Meaning |
|---|---|---|
source | number | Player server id. |
name | string | Client callback name. |
... | any | Arguments. |
timeout.JRS.Rpc(name, handler)Registers a callback in the older ticket system that client JRS.Rpc calls reach. The handler returns its answer.
JRS.Rpc('jrs_fishing:canFish', function(src, spot)
return JRS.GetItemCount(src, 'fishing_rod') > 0
end)| Argument | Type | Meaning |
|---|---|---|
name | string | Callback name. |
handler | function | function(source, ...) return values end. |
JRS.Rpc(name, callback, ...)Calls a server Rpc handler without blocking. Your callback runs with the answer.
JRS.Rpc('jrs_fishing:canFish', function(allowed)
if allowed then StartFishing() end
end, 'lake_owanjila')| Argument | Type | Meaning |
|---|---|---|
name | string | Callback name. |
callback | function | Receives the returned values. |
... | any | Arguments. |
JRS.CallServer(name, ...)Calls a RegisterServerCallback handler and waits. Run it in a thread.
CreateThread(function()
local ok, price = JRS.CallServer('jrs_stores:price', 'bread')
if ok then print('bread costs', price) end
end)| Argument | Type | Meaning |
|---|---|---|
name | string | Server callback name. |
... | any | Arguments. |
JRS.RegisterClientCallback(name, handler)Answers server requests on this client.
JRS.RegisterClientCallback('myscript:street', function()
local c = GetEntityCoords(PlayerPedId())
return GetStreetNameFromHashKey(GetStreetNameAtCoord(c.x, c.y, c.z))
end)| Argument | Type | Meaning |
|---|---|---|
name | string | Callback name. |
handler | function | function(...) return values end. |
Console Logging#
JRS.Debug(text)Prints a green tagged line to the server console. JRS.Error(text) prints a red one.
JRS.Debug('jrs_ranch loaded 14 ranches')
JRS.Error('jrs_ranch: missing config for ranch 3')| Argument | Type | Meaning |
|---|---|---|
text | string | Message. |
JRS.Report(id, title, text)Prints a highlighted report block, useful for problems an admin must see in the log.
JRS.Report('RANCH-01', 'Duplicate ranch id', 'Ranch 3 appears twice in config.lua')| Argument | Type | Meaning |
|---|---|---|
id | string | Short report id. |
title | string | Heading. |
text | string | Details. |