Add a job#
Multi-job is built into rsg-core. Job definitions live in the database (the multijob_jobs table), not in shared/jobs.lua, which only keeps unemployed as a fallback. The tables multijob_jobs and player_jobs are created automatically. The details are in the rsg-core documentation.
1. Create the job in game#
An admin opens the job editor with /jobadmin. Define the job name, label, type, icon, whether players start on duty, and the grades with their pay. Players then see their jobs with /myjobs and can switch between them, up to MaxJobs (3 by default).
2. Or create it from code#
A job definition looks like this. Grade keys are strings, and isboss marks the grades that can manage the job.
{
name = 'ranchhand', label = 'Ranch Hand', type = 'none', icon = 'fa-solid fa-horse',
defaultDuty = true, offDutyPay = false,
grades = {
['0'] = { name = 'Hand', payment = 8 },
['1'] = { name = 'Foreman', payment = 18, isboss = true },
},
}
Save it at runtime with SaveJobDefinition. It is validated, stored and synced to clients:
local def, err = exports['rsg-core']:SaveJobDefinition(definition)
if not def then print('save failed:', err) end -- 'not_loaded' or an adm_err_* key
Call it only after the server event rsg-multijob:server:jobsLoaded has fired, otherwise it returns 'not_loaded'.
3. Give the job to a player#
-- source = online server id, or an offline citizenid
local ok, reason = exports['rsg-core']:AddPlayerJob(source, 'ranchhand', 0)
if not ok then
print('could not add job:', reason) -- 'max_jobs', 'invalid_job', 'invalid_grade', 'player_not_found'
end
Use CanTakePlayerJob(source, job) first when an NPC offers the job, and RemovePlayerJob(source, job) to take it away.
4. Gate a feature on the job#
local held, grade = exports['rsg-core']:HasPlayerJob(source, 'ranchhand')
if held and grade >= 1 then
-- foreman or above
end
HasPlayerJob checks every job the player holds. To check only the active job, read Player.PlayerData.job.name and Player.PlayerData.job.onduty on the server.
Duty and pay#
Player.Functions.SetJobDuty(true) -- server
TriggerServerEvent('RSGCore:ToggleDuty') -- client toggles its own duty
Wages come from each grade's payment. Setting offDutyPay = false means players are not paid while off duty. If you use rsg-society, wages can be paid out of the society's account.
Related#
- rsg-core: Jobs, Gangs & Multi-Job
- rsg-society for ranks, payroll and finances