Skip to content

nss_libs - Character ​

Wraps player characters from the VORP framework and provides a unified API for both server and client side. On the server, it exposes character data, currency management, player identifiers, and event listeners for group/job changes. On the client, it provides a listener for the currently selected character.


How to use ​

lua
local name_of_admin_group = 'admin'
local example_player_id = 99 -- The server player id of a joined player

---@type NssLibsCharacterApi
local character_api = exports.nss_libs:getCharacterApi(GetCurrentResourceName(), name_of_admin_group)

-- Get the character data of a player
---@type NssLibsCharacterItem|nil
local char_data = character_api:getCharData(example_player_id)
if char_data then
    print('Character name: ' .. char_data.full_name)
    print('Job: ' .. char_data.job)
    print('Is admin: ' .. tostring(char_data.is_admin))
end

-- Currency management
character_api:addMoney(example_player_id, 1000)
character_api:subMoney(example_player_id, 999)

if character_api:hasMoney(example_player_id, 1) then
    print('Player has at least $1')
end

character_api:addGold(example_player_id, 5)

-- Player identifiers
print(character_api:getSteamId(example_player_id))
print(character_api:getSteamProfileUrl(example_player_id))
print(character_api:getDiscordProfileUrl(example_player_id))
print(character_api:getRedmCharacterName(example_player_id))

-- Listen for job changes
character_api:onJobChange(function(_source, old_job, new_job)
    print('Player ' .. _source .. ' changed job from ' .. old_job .. ' to ' .. new_job)
end)
lua
---@type NssLibsClientCharacterApi
local char_api = exports.nss_libs:getClientCharacterApi(GetCurrentResourceName())

-- Listen for the currently selected character
char_api:listenSelectedCharacter(
    function(char_data)
        print('Character selected: ' .. tostring(char_data))
    end,
    function()
        print('Character listener destroyed.')
    end
)

Methods ​

exports.nss_libs:getCharacterApi(resource_name, name_of_admin_group) ​

Returns the server character API NssLibsCharacterApi for the given resource.

ParamTypeDefaultDescription
resource_namestring—The name of the resource that wants to use the API
name_of_admin_groupstring—The VORP group name that is considered the admin group. Used to populate is_admin on NssLibsCharacterItem

NssLibsCharacterApi ​

getCharData(_source) ​

Returns the currently used VORP character of the player as a wrapped object.

ParamTypeDefaultDescription
_sourcenumber—The server player ID

Returns NssLibsCharacterItem | nil — The character data, or nil if no character is found.

addGold(_source, amount) ​

Adds gold to the character.

ParamTypeDefaultDescription
_sourcenumber—The server player ID
amountnumber—The amount of gold to add

subGold(_source, amount) ​

Subtracts gold from the character.

ParamTypeDefaultDescription
_sourcenumber—The server player ID
amountnumber—The amount of gold to subtract

hasGold(_source, amount) ​

Checks if the character has at least the given amount of gold.

ParamTypeDefaultDescription
_sourcenumber—The server player ID
amountnumber—The required gold amount

Returns boolean — true if the character has enough gold, otherwise false.

addMoney(_source, amount) ​

Adds money to the character.

ParamTypeDefaultDescription
_sourcenumber—The server player ID
amountnumber—The amount of money to add

subMoney(_source, amount) ​

Subtracts money from the character.

ParamTypeDefaultDescription
_sourcenumber—The server player ID
amountnumber—The amount of money to subtract

hasMoney(_source, amount) ​

Checks if the character has at least the given amount of money.

ParamTypeDefaultDescription
_sourcenumber—The server player ID
amountnumber—The required money amount

Returns boolean — true if the character has enough money, otherwise false.

getIdentifiers(_source, refresh) ​

Returns all identifiers for the player.

ParamTypeDefaultDescription
_sourcenumber—The server player ID
refreshboolean?falseIf true, forces a re-read of identifiers instead of using the cached value

Returns NssLibsCharacterIdentifiers — The player identifiers object.

getSteamId(_source) ​

Returns the Steam ID of the player.

ParamTypeDefaultDescription
_sourcenumber—The server player ID

Returns string — The Steam ID.

getSteamProfileUrl(_source) ​

Returns the Steam profile URL of the player.

ParamTypeDefaultDescription
_sourcenumber—The server player ID

Returns string — The Steam profile URL.

getDiscordId(_source) ​

Returns the Discord ID of the player.

ParamTypeDefaultDescription
_sourcenumber—The server player ID

Returns string — The Discord ID.

getDiscordProfileUrl(_source) ​

Returns the Discord profile URL of the player.

ParamTypeDefaultDescription
_sourcenumber—The server player ID

Returns string — The Discord profile URL.

getIp(_source) ​

Returns the IP address of the player.

ParamTypeDefaultDescription
_sourcenumber—The server player ID

Returns string — The IP address.

getRedmCharacterName(_source) ​

Returns the RedM player name as returned by GetPlayerName.

ParamTypeDefaultDescription
_sourcenumber—The server player ID

Returns string — The RedM character name.

getFivmId(_source) ​

Returns the FiveM ID of the player.

ParamTypeDefaultDescription
_sourcenumber—The server player ID

Returns string — The FiveM ID.

getCharacterByName(character_name) ​

Finds a character by their full name in the database.

ParamTypeDefaultDescription
character_namestring—The full name of the character (firstname + lastname)

WARNING

This method loads data from the database, not from the VORP cache. Changes to group or job that have not yet been persisted will not be reflected.

Returns NssLibsCharacterItem | nil — The character data, or nil if no character is found.

getCharacterByCharId(char_id) ​

Finds a character by their VORP charidentifier in the database.

ParamTypeDefaultDescription
char_idnumber—The VORP character identifier

WARNING

This method loads data from the database, not from the VORP cache. Changes to group or job that have not yet been persisted will not be reflected.

Returns NssLibsCharacterItem | nil — The character data, or nil if no character is found.

getSteamIdOfChar(char_id) ​

Returns the Steam ID for a given character ID. Uses a cache to avoid repeated DB lookups.

ParamTypeDefaultDescription
char_idstring | number—The VORP character identifier

Returns string | nil — The Steam ID, or nil if not found.

getSourceOfChar(char_id) ​

Returns the server player ID for a given character ID by iterating over all active players.

ParamTypeDefaultDescription
char_idstring | number—The VORP character identifier

Returns number | nil — The server player ID, or nil if the character is not currently online.

onGroupChange(cb) ​

Registers a listener that is called whenever a player's VORP group changes.

ParamTypeDefaultDescription
cbNssLibsCharacterOnGroupChangeCallback—function(_source, old_group, new_group)

Returns NssLibsSharedHelperEventHandlerApi — The event handler instance.

onJobChange(cb) ​

Registers a listener that is called whenever a player's job changes.

ParamTypeDefaultDescription
cbNssLibsCharacterOnJobChangeCallback—function(_source, old_job, new_job)

Returns NssLibsSharedHelperEventHandlerApi — The event handler instance.

onJobGradeChange(cb) ​

Registers a listener that is called whenever a player's job grade changes.

ParamTypeDefaultDescription
cbNssLibsCharacterOnJobGradeChangeCallback—function(_source, old_grade, new_grade)

Returns NssLibsSharedHelperEventHandlerApi — The event handler instance.


NssLibsCharacterItem ​

Represents a wrapped VORP character with additional computed properties.

Properties ​

ParamTypeDefaultDescription
char_idnumber—The VORP character identifier
groupstring—The VORP group of the character (e.g. 'user', 'admin')
jobstring—The current job of the character
job_gradenumber—The current job grade of the character
firstnamestring—The first name of the character
lastnamestring—The last name of the character
full_namestring—The full name of the character (firstname .. ' ' .. lastname)
moneynumber—The current money of the character
is_adminboolean—true if the character's group matches the configured admin group
server_player_idnumber | nil—The server player ID if the character is currently online, otherwise nil

char_data:hasJob(job) ​

Checks if the character currently has the given job (exact match).

ParamTypeDefaultDescription
jobstring—The job identifier to check

Returns boolean — true if the character has this job, otherwise false.

char_data:hasJobGrade(grade) ​

Checks if the character's job grade is greater than or equal to the given grade.

ParamTypeDefaultDescription
gradenumber—The minimum required job grade

Returns boolean — true if job_grade >= grade, otherwise false.

char_data:hasOneOfTheJobs(jobs) ​

Checks if the character has one of the given jobs. Supports both a plain array of job names and a map of job names to minimum required grades.

ParamTypeDefaultDescription
jobsstring[] | table—A list of job identifiers, or a table mapping job names to minimum required grades
lua
-- Any of these jobs qualifies
char_data:hasOneOfTheJobs({ 'sheriff', 'ranger', 'bounty_hunter' })
lua
-- Job qualifies only if the character also meets the minimum grade
char_data:hasOneOfTheJobs({ sheriff = 2, ranger = 1 })

Returns boolean — true if the character has at least one of the given jobs (respecting grade requirements), otherwise false.

char_data:isEmployed() ​

Checks if the character currently has any job assigned.

Returns boolean — true if the character has a job, otherwise false.


exports.nss_libs:getClientCharacterApi(resource_name) ​

Returns the client character API NssLibsClientCharacterApi for the given resource.

ParamTypeDefaultDescription
resource_namestring—The name of the resource that wants to use the API

NssLibsClientCharacterApi ​

char_api:listenSelectedCharacter(callback, on_destroy_callback) ​

Registers a listener that is called when the currently selected character is loaded via the framework bridge. The callback fires immediately with the current character if one is already selected.

ParamTypeDefaultDescription
callbackfunction—Called with the character data when a character is selected
on_destroy_callbackfunction—Called when the listener is destroyed

Returns NssLibsSharedHelperEventHandlerApi — The event handler instance.

char_api:resetAllSelectedCharacterListener() ​

Removes all character selection listeners registered by this resource.

Returns NssLibsClientCharacterApi — The API instance for chaining.

char_api:resetApi() ​

Resets the framework bridge for this resource. Use this if the resource needs to re-initialise its connection to the character system.

Returns NssLibsClientCharacterApi — The API instance for chaining.


Objects / Types ​

NssLibsCharacterIdentifiers ​

Contains all player identifiers as returned by the RedM identifier system.

ParamTypeDefaultDescription
steamstring—Steam identifier
licensestring—Rockstar license identifier
discordstring—Discord identifier
ipstring—IP address
fivemstring—FiveM identifier
xblstring—Xbox Live identifier
livestring—Microsoft Live identifier
license2string—Secondary Rockstar license identifier

NssLibsCharacterOnGroupChangeCallback ​

lua
---@alias NssLibsCharacterOnGroupChangeCallback fun(_source: number, old_group: string, new_group: string)

NssLibsCharacterOnJobChangeCallback ​

lua
---@alias NssLibsCharacterOnJobChangeCallback fun(_source: number, old_job: string, new_job: string)

NssLibsCharacterOnJobGradeChangeCallback ​

lua
---@alias NssLibsCharacterOnJobGradeChangeCallback fun(_source: number, old_grade: number, new_grade: number)

NIGHTSHIFT STUDIO Documentation