This page is for developers making scripts for JRS Core.
Getting the API#
getCoreApi returns one table with every function of the side your code runs on. Call it once at the top of the file.
Shared (server and client have different functions)
getCoreApi#
returntableThe API table. Server side and client side tables are different.
local JRS = exports.jrs_core:getCoreApi()Characters#
Server Side
GetCharacter#
Returns the loaded character of a player, or nil if the player has not selected a character yet.
sourcenumberrequiredThe player source.
returntable | nilThe character table: identifier, charIdentifier, firstname, lastname, job, jobGrade, money, gold, dirtymoney, rol, xp.
local character = JRS.GetCharacter(source)
if character then print(character.firstname, character.money) endGetCharacterData#
Same as GetCharacter but returns a clean copy that also contains group.
local data = JRS.GetCharacterData(source)GetCharacterName#
returnstring | nilfirstname lastname, or the Steam name when the character has no name.
local name = JRS.GetCharacterName(source)IsCharacterReady#
True when the player finished selecting a character. Money, items and XP functions refuse to run before this is true.
if not JRS.IsCharacterReady(source) then return endGetCharacterById#
Reads any character (online or offline) by its character id.
local character = exports.jrs_core:GetCharacterById(charId)FindCharactersByName#
local rows = exports.jrs_core:FindCharactersByName('John', 'Marston')SaveCharacter#
Forces a save of the player character to the database.
exports.jrs_core:SaveCharacter(source)Money#
Server Side
Currency types: 0 = cash, 1 = gold, 3 = dirty money.
AddMoney / RemoveMoney#
sourcenumberrequiredThe player source.
amountnumberrequiredAmount, must be greater than 0.
JRS.AddMoney(source, 25)
JRS.RemoveMoney(source, 10)AddGold / RemoveGold#
JRS.AddGold(source, 1)
JRS.RemoveGold(source, 1)AddDirtyMoney / RemoveDirtyMoney / GetDirtyMoney#
JRS.AddDirtyMoney(source, 100)
JRS.RemoveDirtyMoney(source, 25)
local dirty = JRS.GetDirtyMoney(source)addMoney / removeMoney#
The generic form with a currency type.
sourcenumberrequiredThe player source.
currencynumberrequired0 cash, 1 gold, 3 dirty.
quantitynumberrequiredAmount.
JRS.addMoney(source, 0, 100)
JRS.removeMoney(source, 0, 50)GetBalance#
local balance = JRS.GetBalance(source)AddReward#
Pays a gameplay reward. The amount is scaled by Config.Economy (RewardMultiplier, GoldMultiplier, MinReward) and by the player level perks. Use this for jobs and missions instead of AddMoney.
sourcenumberrequiredThe player source.
currencynumberrequired0 cash or 1 gold.
amountnumberrequiredBase amount before scaling.
reasonstringReason, used for logs and job pay perks.
JRS.AddReward(source, 0, 2.5, 'hunting_sale')ScaleReward#
Returns the scaled amount without paying anything.
local pay = JRS.ScaleReward(10, 0)Jobs and groups#
Server Side
setJob#
sourcenumberrequiredThe player source.
jobstringrequiredThe job name.
gradenumberrequiredThe job grade.
JRS.setJob(source, 'police', 2)Jobs.Get / Add / Remove / Switch#
Multi-job functions. The maximum number of jobs per player is MaxJobs in jrs_core/config/config.lua.
local jobs = exports.jrs_core:GetJobs(source)
exports.jrs_core:AddJob(source, 'doctor', 0, 'Doctor')
exports.jrs_core:RemoveJob(source, 'doctor')
exports.jrs_core:SwitchJob(source, 'police')SetDuty / ToggleDuty / GetDutyPlayers#
exports.jrs_core:SetDuty(source, true)
exports.jrs_core:ToggleDuty(source)
local officers = exports.jrs_core:GetDutyPlayers('police')GetGroup / SetGroup / IsAdmin#
local group = JRS.GetGroup(source)
JRS.SetGroup(source, 'admin')
if exports.jrs_core:IsAdmin(source) then endXP and levels#
Server Side
Character level goes to 100. XP per level is in config/levels.lua.
AddXP / RemoveXP / SetXP / GetXP#
sourcenumberrequiredThe player source.
amountnumberrequiredXP amount.
reasonstringReason for logs.
JRS.AddXP(source, 10, 'mission_reward')
local xp = JRS.GetXP(source)GetLevel / SetLevel / AddLevel / RemoveLevel#
local level = JRS.GetLevel(source)
JRS.SetLevel(source, 25, 'admin')GetLevelData / GetTotalXpForLevel#
local info = JRS.GetLevelData(totalXp)
local needed = JRS.GetTotalXpForLevel(30)AddJobXP / GetJobLevel / GetJobXP / GetAllJobLevels#
Every job has its own XP and level.
JRS.AddJobXP(source, 'mining', 15, 'ore')
local level = JRS.GetJobLevel(source, 'mining')
local all = JRS.GetAllJobLevels(source)Level perks#
Perks give discounts and bonuses by level. Apply them in your payout code:
price = exports.jrs_core:ApplyShopDiscount(source, price)
sell = exports.jrs_core:ApplySellBonus(source, sell)
tax = exports.jrs_core:ApplyTaxReduction(source, tax)
local capacity = exports.jrs_core:GetCarryCapacity(source)Items (through jrs_inventory)#
Server Side
These helpers call jrs_inventory for you and fail safely when it is not started.
AddItem / RemoveItem / GetItemCount / CanCarryItem#
if JRS.CanCarryItem(source, 'bread', 2) then
JRS.AddItem(source, 'bread', 2, {})
end
local count = JRS.GetItemCount(source, 'bread')
JRS.RemoveItem(source, 'bread', 1)Inventory.Transaction#
Runs several item operations atomically: all of them succeed or none.
local ok, reason = exports.jrs_inventory:InventoryTransaction(source, {
{ type = 'remove', item = 'wood', amount = 5 },
{ type = 'add', item = 'plank', amount = 2, metadata = {} },
}, { owner = 'sawmill' })
if not ok then print('transaction failed', reason) endNotifications#
The first argument is the player source.
JRS.NotifyRightTip(source, 'Reward received', 3000)
JRS.NotifyTip(source, 'Tip text', 3000)
JRS.NotifyLeft(source, 'Title', 'Subtitle', 'menu_textures', 'menu_icon_alert', 4000, 'COLOR_WHITE')
JRS.NotifyTop(source, 'Text', 'Location', 4000)
JRS.NotifyObjective(source, 'Objective text', 4000)
JRS.NotifySimpleTop(source, 'Title', 'Subtitle', 4000)
JRS.NotifyCenter(source, 'Text', 4000)
JRS.NotifyBottomRight(source, 'Text', 4000)
JRS.NotifyFail(source, 'Title', 'Subtitle', 4000)
JRS.NotifyUpdate(source, 'Title', 'Message', 4000)
JRS.NotifyWarning(source, 'Title', 'Message', 'Transaction_Feed_Sounds', 'Transaction_Positive', 4000)JRS.NotifyRightTip('Ready', 3000)
JRS.NotifyTip('Tip text', 3000)
JRS.Notify('Saved', 'success', 3000, 'Title')
JRS.Info('Information', 3000)
JRS.Success('Done', 3000)
JRS.WarningNotify('Careful', 3000)
JRS.ErrorNotify('Failed', 3000)The server list is also available as exports, e.g. exports.jrs_core:NotifyRightTip(source, text, ms).
Callbacks (RPC)#
Calls are rate limited (30 per second per player), payloads are limited to 64 KB and calls time out after 10 seconds.
Client helpers#
Client Side
GetPlayerData / WaitForCharacterReady#
JRS.WaitForCharacterReady()
local data = JRS.GetPlayerData()TeleportToCoords / TeleportToWaypoint#
JRS.TeleportToCoords(x, y, z, heading)
JRS.TeleportToWaypoint()SetCustomDestination / RemoveCustomDestination#
Sets a 3D waypoint marker.
JRS.SetCustomDestination(vector3(0.0, 0.0, 0.0), 'Destination')LoadModel / LoadAnimDict / LoadTextureDict#
Safe loaders with a timeout.
JRS.LoadModel(`a_c_horse_arabian_white`)
JRS.LoadAnimDict('amb_camp@world_camp_fire_sit@male_a@base')GetClosestPlayer / GetNearbyPlayers#
local player, distance = JRS.GetClosestPlayer()Input / Confirm#
Opens the themed input or confirm dialog.
local amount = JRS.InputAwait('Amount', 'How many?')
local ok = JRS.ConfirmAwait('Are you sure?')