Employment
The employment providers provide a service that allows resources to interact with players their jobs.
Usage
To retrieve the employment provider, use the load function with "employment" for the service parameter.
Lua:
local employmentProvider = exports.r3_servicesmanager:load("employment")JavaScript:
const employmentProvider = exports.r3_servicesmanager.load("employment");Client
On the client side, the following methods are available:
getPlayerJob
Returns the job of the player.
employmentProvider.getPlayerJob()Returns:
playerHasJob
Checks whether a player has a certain job, and optionally checks if their grade is bigger or equal to the specified grade.
employmentProvider.playerHasJob(jobName, jobGrade)Parameters:
- jobName:
string - jobGrade:
integer(optional)
Returns:
trueif the player has the job and their grade satisfies the specified grade.falseif the player does not have the job and grade.
onPlayerJobChanged
Can be used to register a callback which will be invoked when the player’s job changes.
employmentProvider.onPlayerJobChanged(callback)Parameters:
- callback:
fun(playerJob: PlayerJob): nil
Returns:
Server
On the server side, the following methods are available:
getJob
Retrieves a job object based on the name of the job.
employmentProvider.getJob(jobName)Parameters:
- jobName:
string
Returns:
jobExists
Checks whether or not a job exists, optionally with a certain grade.
employmentProvider.jobExists(jobName, jobGrade)Parameters:
- jobName:
string - jobGrade:
integer
Returns:
boolean
getOnlineJobCount
Returns the number of players currently online that have the specified job (and are on duty, if the provider supports it).
employmentProvider.getOnlineJobCount(jobName)Parameters:
- jobName:
string
Returns:
integer
getPlayerJob
Returns the job of a player, or nil if the player is not online.
employmentProvider.getPlayerJob(playerId)Parameters:
- playerId:
integer
Returns:
PlayerJobnilif the player could not be found.
setPlayerJob
Sets the player job to the specified job name and grade, and returns whether or not it was succesful.
employmentProvider.setPlayerJob(playerId, jobName, jobGrade)Parameters:
- playerId:
integer - jobName:
string - jobGrade:
integer
Returns:
trueif the job was successfully set.falseif the job wasn’t successfully set (i.e. it did not exist or the player could not be found).
playerHasJob
Checks whether a player has a certain job, and optionally checks if their grade is bigger or equal to the specified grade.
employmentProvider.playerHasJob(playerId, jobName, jobGrade)Parameters:
- playerId:
integer - jobName:
string - jobGrade:
integer(optional)
Returns:
trueif the player has the job and their grade satisfies the specified grade.falseif the player does not have the job and grade, or if the player could not be found.
Types
The following types are used within the employment provider:
Job
An object containing the data of a job.
Fields:
- name:
string - label:
string - grades:
table<integer, JobGrade>
PlayerJob
An object containing the job data of a player.
Fields:
- name:
string - label:
string - grade:
{ rank: integer }&JobGrade
JobGrade
An object containing a job grade.
Fields:
- name:
string - label:
string - salary:
integer - isBoss:
boolean
Subscription
A subscription to an event emitter.
Fields:
- unsubscribe:
fun(): nil
Registration
To register an employment provider, ensure it implements all methods described above. Check out employment.lua and employment.ts for type definitions.
When your provider object implements all methods, you can register it as follows:
Lua:
exports.r3_servicesmanager:register("employment", provider, priority, GetCurrentResourceName())JavaScript:
exports.r3_servicesmanager.register("employment", provider, priority, GetCurrentResourceName());For priority, it is recommended to use priority 2, this corresponds to ServicePriority.Normal. It would be even better to allow server owners to configure the used priority in the configuration of your resource so that they can choose which resource takes priority.