Jobs API
Server and client exports for jobs. New to jobs? Read Jobs first.
jobId or key; a person a source or { charId = 42 } (offline too); a role a roleId or name (any capitals). Each returns a value, or false and a reason a player can read. opts.by names the player acting, and WHIP checks their rank; leave it out when your code or an admin decides.Reading jobs
A job by jobId or key.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
table|nil: { jobId, key, name, icon, ownerCharId, settings }Every job, in jobId order.
table[]: job objectsA job's roles, highest level first.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
table[]: { roleId, name, level, permissions }, or false, 'No such job'Declaring and changing jobs
Finds or creates your job; declare it in Whip.register (example). Later calls update the name, icon, permissions and selfClockOn and add new roles; existing roles and the owner stay (UpdateJob changes the owner). Another running resource's key is refused. While whip_core starts, it waits up to 60 seconds.
| Param | Type | Description |
|---|---|---|
| key | string | Letters, numbers and _ ('police') |
| data.name | string | Display name |
| data.icon | string? | Icon |
| data.roles | table? | { { name, level, permissions } }, level 1–100. Default Config.JobDefaultRoles |
| data.permissions | table? | The job's own, beside the built-in five: { cuff = 'Cuff suspects' } |
| data.owner | person? | Used only when the job is made: holds the top role and the business account |
| data.selfClockOn | boolean? | false: the client's ClockOn is refused; your server code puts them on duty. Going off duty always works |
table: the job, or false, why (a bad key, 'roles[2] (Cadet): level must be...'). A new owned job whose business account couldn't be opened is still returned; the console says so.Changes a job's name, icon or owner. The business account follows a new owner; the old owner keeps what their role gives, or nothing if they don't work there.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
| patch | table | { name?, icon?, owner? }. owner = false removes the owner (refused while there's a business account) |
true (even if the account couldn't follow the new owner; the console says so), or false, why. Refused for a job another running resource declares; one made on the Jobs page, or whose resource is stopped, is open to any.Deletes a job, its roles and staff list, and closes its business accounts.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
true, or false, why: 'Empty the job's business account first' while one holds money. Refused for a job another running resource declares, as UpdateJob.Who works where
The job they clocked on at most recently, as the whipJob statebag and the client's GetPlayerJob name it. nil off duty.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId } |
table|nil: { jobId, key, name, icon, roleId, roleName, roleLevel }Every job they have a role at (employed, or the owner), on duty or not.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId } |
table, by jobId: { jobId, key, name, icon, roleId, roleName, roleLevel, clockedOn, permissions }; {}, why for nobodyOn duty at this job, or, with no job, at any.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId } |
| job | number|string? | jobId or key |
boolean; with false, a reason when there's no such player or job, so "off duty" and "asked about nobody" differTheir role at a job. The owner holds the top role, hired or not.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId } |
| job | number|string | jobId or key |
table|nil: { roleId, name, level, permissions }May they do this at this job? Level 100 holds every permission. Permissions hold on duty or off.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId } |
| job | number|string | jobId or key |
| permission | string | canHire, canFire, canPromote, canDemote, canManage, or the job's own |
| opts | table? | { onDuty = true } also requires being on duty there |
true, or false, why ('Not on duty at Police', 'Not allowed at Police', no such player or job)if not exports.whip_core:HasJobPermission(source, 'police', 'cuff', { onDuty = true }) then
return false, 'Only an officer on duty can do that'
end
Everyone on the payroll, online or not, by charId. The owner is listed only if also hired.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
table, by charId: { charId, roleId, roleName, roleLevel, hiredAt, hiredBy, onDuty, source } (hiredAt in epoch seconds; source only while online), or false, 'No such job'Everyone on duty at a job, the owner included. Each has a source, as duty ends at logout.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
table[]: { charId, source }, or false, reason for no such job (hence the or {})for _, cop in ipairs(exports.whip_core:GetClockedOnEmployees('police') or {}) do
exports.whip_core:NotifyPlayer(cop.source, '10-31 in progress at the bank')
end
Hiring and roles
Hires someone. Their business-account access follows the role; their client's job list updates itself.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId } (offline too) |
| job | number|string | jobId or key |
| role | number|string? | roleId or name; default the lowest role |
| opts | table? | { by = person }, recorded and checked: they outrank the role, hold canHire, and hold all it can do (its permissions, at least its account access) |
true, or false, why ('They already work there', 'No such role at that job', 'No such character', 'Your role is not allowed to do that', 'They (or that role) outrank you'...)Config.JobOneCharacterPerAccount (on by default) refuses hiring a character whose account already has one there, the owner included, so an alt can't keep a fired character's access. Trusted code obeys it too; false turns it off.Would HirePlayer allow it? Nothing is written: for a step that waits on someone, like the phone's job offer, which hires (checking again) once accepted.
true, or false, why (as HirePlayer)local ok, why = exports.whip_core:CanHirePlayer({ charId = typedId }, jobId, roleId, { by = source })
if not ok then return false, why end -- say why now, before asking them
Fires someone. They go off duty and lose their business-account access.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId } |
| job | number|string | jobId or key |
| opts | table? | { by = person }, checked: they outrank the person and hold canFire |
true, or false, why ('They do not work there'...)Changes someone's role. Their business-account access follows it.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId } |
| job | number|string | jobId or key |
| role | number|string | roleId or name |
| opts | table? | { by = person }, checked: they outrank the old and new role and hold canPromote (up) or canDemote (down); the new role gives nothing theirs can't do; nobody promotes themselves |
true, or false, whyAdds a role. Role names are unique within a job, ignoring case.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
| data | table | { name, level, permissions? }, level 1–100; permissions are built-ins, the job's own and bankAccess. One the job lacks is refused |
| opts | table? | { by = person }, checked: canManage; below level 100, the role sits below theirs and does no more (no permission they lack, no more account access) |
table: { roleId, name, level, permissions }, or false, why ('There is already a role called Shift Lead', 'They (or that role) outrank you', 'That rank can do more than yours: you cannot give more than you have'...)Changes a role's name, level or permissions. Unnamed permissions keep their value; false removes one. Its holders' account access follows.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
| role | number|string | roleId or name |
| patch | table | { name?, level?, permissions? } |
| opts | table? | { by = person }, checked: canManage; below level 100, the role and its new level sit below theirs and gain nothing their role lacks. Nobody may leave the job without a level 100 role |
true, or false, whyDeletes a role. Refused while anyone holds it.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
| role | number|string | roleId or name |
| opts | table? | { by = person }, checked as for UpdateJobRole |
true, or false, why ('Move the people in that role to another role first')Duty
Puts an online player on duty, until logout or a restart. With Config.JobDutyOneAtATime, every other job clocks off first.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId }; online |
| job | number|string | jobId or key |
| opts | table? | { by = person }, checked like the client's ClockOn: only themselves, at a job that allows it (selfClockOn) |
true, or false, why ('They do not work there', 'They are not online'...)Takes someone off duty at a job, or, with no job, at every job.
| Param | Type | Description |
|---|---|---|
| who | person | source or { charId } |
| job | number|string? | jobId or key |
true, or false, why ('They are not on duty'...)Client#
The local player's job state, cached: no server round trip except ClockOn and ClockOff. Client events are in Jobs.
Every job the local player has a role at.
table: { [jobId] = { jobId, key, name, icon, roleId, roleName, roleLevel, clockedOn, permissions } }On duty at this job, or, with no job, at any?
| Param | Type | Description |
|---|---|---|
| job | number|string? | jobId or key; nil for any |
booleanWhat the job list says the player may do: a hint for what to offer, such as a "Manage Stock" option. The server checks again when it's used.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
| permission | string | A built-in or the job's own |
booleanThe job of the most recent clock-on, as the server's GetPlayerJob names it. nil off duty.
table|nil: an entry of GetPlayerJobsGoes on duty. It waits for the server, so call it from a thread (a command, a key binding, an interaction callback). Refused ('This job puts people on duty itself') when the job has selfClockOn = false.
| Param | Type | Description |
|---|---|---|
| job | number|string | jobId or key |
true, or false, whyGoes off duty at a job, or, with none, at every job. Always allowed, even while dead. Waits for the server.
| Param | Type | Description |
|---|---|---|
| job | number|string? | jobId or key |
true, or false, why