Esc to clear, Enter to open the best match, click an export to open it in its page
Get Started
Your First Job
Add staff to the coffee stand from Your First Resource: a job, a counter with different options for customers and staff on duty, brewing under a bar the server times, and pay for each cup. About 30 minutes more, in the same four files.
1. The job
In server.lua, declare the job. The first start creates it; later starts find it again.
Whip.register(function()
Whip.core:EnsureJob('mycafe', {
name = 'Bean Machine',
roles = {
{ name = 'Owner', level = 100 },
{ name = 'Barista', level = 1 },
},
})
end)Hire yourself in /whip → Economy → Jobs → Bean Machine → Change. (From code, use HirePlayer.)
2. One counter, several options
Customers buy; baristas clock on, brew and clock off. One prompt carries them all as options, and each option's require decides who sees it. In client.lua, replace the counter's AddAction:
Whip.register(function()
Whip.core:AddAction({
id = 'counter',
at = { coords = Config.Counter },
options = {
{ id = 'buy', label = ('Buy coffee ($%d)'):format(Config.Price), icon = 'cash',
onSelect = function() TriggerServerEvent('mycafe:buy') end },
-- Staff only. whipJob is the job they're on duty at (false when off duty)
{ id = 'clockon', label = 'Clock on', require = { job = 'mycafe' },
canInteract = function() return LocalPlayer.state.whipJob ~= 'mycafe' end,
onSelect = function(ctx)
local ok, why = exports.whip_core:ClockOn('mycafe')
if not ok then ctx.refuse(why) end
end },
{ id = 'brew', label = 'Brew a coffee', require = { job = 'mycafe', onDuty = true },
onSelect = function() TriggerServerEvent('mycafe:brew') end },
{ id = 'clockoff', label = 'Clock off', require = { job = 'mycafe', onDuty = true },
onSelect = function() exports.whip_core:ClockOff('mycafe') end },
},
})
end)require only decides what's offered. Anything that matters is checked again on the server, as the brew below is.3. Brewing, and pay
Add BrewPay = 5 to Config in shared.lua. Then, in server.lua:
Whip.register(function()
Whip.core:SecureEvent('mycafe:brew', {
rateLimit = 2000,
near = { at = Config.Counter, range = 3.0, message = 'Stand at the counter' },
}, function(source, player)
if not exports.whip_core:IsPlayerClockedOn(source, 'mycafe') then
return false, 'Clock on first'
end
local done, reason = exports.whip_core:Progress(source, {
label = 'Brewing...',
duration = 6000,
near = { coords = Config.Counter, range = 3.0 }, -- still at the counter when it ends
})
if not done then return false, reason end
-- Six seconds went by: still the same character?
if not exports.whip_core:IsSessionCurrent(source, player.session) then return end
local given, gwhy = exports.whip_core:AddItem(source, 'mycafe_coffee', 1, false, 'brewed')
if not given then return false, gwhy end
exports.whip_core:PayPlayer(source, Config.BrewPay, { reason = 'Brewed a coffee' })
end)
end)- The server checks duty; the client's
requireonly chose what to show. Progresson the server times the bar itself, and itsnearchecks they're still at the counter when it ends (the event'snearis checked once, on arrival).IsSessionCurrentchecks the character is still the one playing after a wait, before giving anything.PayPlayerpays cash; whatever doesn't fit their pockets lands at their feet.
4. Try it
restart mycafeand hire yourself (step 1).- At the counter, clock on, then brew: a six-second bar, a coffee, $5.
- Walk away during the bar: it stops with "too far", and nothing is given.
/whip→ System → Monitor shows eachmycafe:brewand any refusal's reason.