-- Example name of admin group, if you do not have an admin group you can use a not used group name.localname_of_admin_group='admin'---@typeNssLibsCharacterApicharacter_api=exports.nss_libs:getCharacterApi(GetCurrentResourceName(), name_of_admin_group)
Methods
addMoney(_source, amount)
_source (integer) - The server player id of a joined player.
amount (float) - The amount of money to add.
Returns nothing.
localexample_player_id=99-- The server player id of a joined playercharacter_api:addMoney(example_player_id, 1000)
getCharacterByName(character_name)
character_name (string) - The full character name to search for.
Important: This method loads the data from the database and not from the VORP (or other framework) cache. In case of VORP a change of group or job will be not saved at the moment the job or group is changed.
char_id (integer) - The character id to search for.
Important: This method loads the data from the database and not from the VORP (or other framework) cache. In case of VORP a change of group or job will be not saved at the moment the job or group is changed.
local full_name = 'John Doe'
local character = character_api:getCharacterByName(full_name)
if character then
print('Character found: ' .. tostring(character.char_id) .. ' :)')
else
print('Character ' .. tostring(full_name) .. ' found :(')
end
local char_id = 1
local character = character_api:getCharacterByCharId(char_id)
if character then
print('Character found: ' .. tostring(character.full_name) .. ' :)')
else
print('Character ' .. tostring(char_id) .. ' found :(')
end
local example_player_id = 99 -- The server player id of a joined player
local character = character_api:getCharData(example_player_id)
if character then
print('Character found: ' .. tostring(character.full_name) .. ' :)')
else
print('Character ' .. tostring(example_player_id) .. ' found :(')
end
local example_player_id = 99 -- The server player id of a joined player
local discord_id = character_api:getDiscordId(example_player_id)
print('Discord id: ' .. discord_id)
local example_player_id = 99 -- The server player id of a joined player
local discord_profile_url = character_api:getDiscordProfileUrl(example_player_id)
print('Discord profile url: ' .. discord_profile_url)
local example_player_id = 99 -- The server player id of a joined player
local fivem_id = character_api:getFivmId(example_player_id)
print('Fivem id: ' .. fivem_id)
local example_player_id = 99 -- The server player id of a joined player
local identifiers = character_api:getIdentifiers(example_player_id)
print('Steam id: ' .. identifiers.steam)
print('Discord id: ' .. identifiers.discord)
local example_player_id = 99 -- The server player id of a joined player
local ip = character_api:getIp(example_player_id)
print('Ip: ' .. ip)
local example_player_id = 99 -- The server player id of a joined player
local redm_character_name = character_api:getRedmCharacterName(example_player_id)
print('Redm character name: ' .. redm_character_name)
local example_player_id = 99 -- The server player id of a joined player
local steam_id = character_api:getSteamId(example_player_id)
print('Steam id: ' .. steam_id)
local example_player_id = 99 -- The server player id of a joined player
local steam_profile_url = character_api:getSteamProfileUrl(example_player_id)
print('Steam profile url: ' .. steam_profile_url)
local example_player_id = 99 -- The server player id of a joined player
if character_api:hasMoney(example_player_id, 1.99) then
print('Player has at least 1.99 money')
end
local example_player_id = 99 -- The server player id of a joined player
character_api:subMoney(example_player_id, 999)
local example_player_id = 99 -- The server player id of a joined player
character_api:addGold(example_player_id, 1000.29)
local example_player_id = 99 -- The server player id of a joined player
if character_api:hasGold(example_player_id, 1.99) then
print('Player has at least 1.99 gold')
end
local example_player_id = 99 -- The server player id of a joined player
character_api:subGold(example_player_id, 999.99)
local event_handler = character_api:onGroupChange(function(source, char_id, new_group)
print('Group changed for ' .. char_id .. ' to ' .. new_group)
end)
local event_handler = character_api:onJobChange(function(source, char_id, new_job)
print('Job changed for ' .. char_id .. ' to ' .. new_job)
end)
local event_handler = character_api:onJobGradeChange(function(source, char_id, new_job_grade)
print('Job grade changed for ' .. char_id .. ' to ' .. new_job_grade)
end)
local char_id = 205
local steam_id = character_api:getSteamIdOfChar(char_id)
if steam_id then
print('Steam id: ' .. steam_id)
else
print('Steam id not found')
end
local char_id = 205
local server_player_id = character_api:getSourceOfChar(char_id)
if server_player_id then
print('Server player id: ' .. server_player_id)
else
print('Server player id not found')
end
-- Simple job list
local jobs = { 'police', 'ambulance' }
if char_data:hasOneOfTheJobs(jobs) then
print('Character has one of the jobs')
end
--- Job list with job grades
local jobs = {
["police"] = 3,
["ambulance"] = 2
}
if char_data:hasOneOfTheJobs(jobs) then
print('Character has one of the jobs with the correct grade')
end
local job = 'police'
if char_data:hasJob(job) then
print('Character has the job')
end
local grade = 3
if char_data:hasJobGrade(grade) then
print('Character has the job grade')
end
if char_data:isEmployed() then
print('Character has a job')
end