Esc to clear, Enter to open the best match, click an export to open it in its page
Jobs & Shops

Jobs

A job is a business with ranks, staff and a bank account. Players clock on and off; your resource declares the job and checks duty and permissions.

Declaring a job

A job has a key, roles with levels and permissions, and employees; its owner holds the top role and the business account. Declare it with EnsureJob, in Whip.register:

Whip.register(function()
    Whip.core:EnsureJob('police', {
        name  = 'Police Department',
        icon  = 'shield',
        roles = {
            { name = 'Chief',    level = 100 },
            { name = 'Sergeant', level = 50, permissions = { canHire = true, canFire = true, cuff = true } },
            { name = 'Officer',  level = 20, permissions = { cuff = true, bankAccess = 'view' } },
            { name = 'Cadet',    level = 1 },
        },
        permissions = { cuff = 'Cuff suspects' },   -- the job's own, beside the built-ins
    })
end)

The first call makes the job, with your roles or Config.JobDefaultRoles. Later calls update the name, icon, permissions and selfClockOn, and add new roles; a role that exists (a server owner may have edited it) and the owner are never changed.

Roles and permissions

Levels run 1–100; level 100 has every permission. Built-ins are canHire, canFire, canPromote / canDemote and canManage (roles, shop stock and prices). A job's own show as toggles on each role on the Jobs page. HasJobPermission checks both, on duty or off unless you pass { onDuty = true }.

A role's bankAccess ('none', 'view', 'deposit', 'withdraw', 'manager') is its access to the business account, kept in step as people are hired, promoted and fired.

Pass { by = source } and WHIP checks the player's rank on HirePlayer, FirePlayer, SetPlayerRole and the role exports: they outrank the person's role and the role given, and hold the permission. Below level 100, nobody gives what they don't have. Leave by out when your code or an admin decides.

-- A boss menu
local ok, why = exports.whip_core:HirePlayer(target, 'police', 'Cadet', { by = source })
if not ok then return false, why end   -- 'They (or that role) outrank you'...

Clocking on and off

Duty isn't saved: logging out or a restart ends it. A player can be on duty at several jobs; their current job is the latest clock-on, which GetPlayerJob and the whipJob statebag name. Config.JobDutyOneAtATime = true makes a clock-on end every other.

Players clock on in the phone's Business app; your resource can add a command or a prompt. For duty at the station only, declare selfClockOn = false (the app's clock-on is refused) and call ClockOn from your server code.

exports.whip_core:ClockOn(source, 'police')            -- server: a prompt at the station
exports.whip_core:IsPlayerClockedOn(source, 'police')  -- server: on duty?
exports.whip_core:ClockOn('burgershot')                -- client, from a thread: waits for the server
Only need "works here"? Skip clocking: GetPlayerRole(source, 'police') ~= nil.

In game: /whip → Economy → JobsServer owners#

+ New Job asks for a name (the key, used by doors, shops and scripts, is made from it, then fixed), ranks from a template, an owner (without one, no bank account) and staff. A job's page shows its staff on duty, account and shops; Change reopens the wizard, and nothing is written before Save changes.

Events

Server events pass one table: { jobId, key }, and for a person { charId, source } (source only while online).

EventExtra fields
whip_core:job:createdname
whip_core:job:updatedname, icon, ownerCharId, oldOwnerCharId
whip_core:job:deleted—
whip_core:job:hiredcharId, source, roleId, role, by
whip_core:job:firedcharId, source
whip_core:job:roleChangedcharId, source, roleId, role, oldRoleId
whip_core:job:clockedOn / clockedOffcharId, source

Client, for the local player: whip_core:job:clockedOn / clockedOff with { jobId, key }, and whip_core:job:listChanged with { jobs }.

Data shapes

ObjectFields
JobjobId, key, name, icon, ownerCharId, settings
RoleroleId, jobId, name, level, permissions
EmployeejobId, charId, roleId, hiredAt, hiredBy
Job list entry (GetPlayerJobs)jobId, key, name, icon, roleId, roleName, roleLevel, clockedOn, permissions