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

Director runs from a script

Server exports to start, read and steer the Director's runs. Any server script may steer any run, and the history says which did. Events, and the rules every export follows, are under For other resources.

Starting a run

StartScenarioRun(key, who, opts?)SERVER#

Starts a run of a switched-on scenario for who (a server id, or { charId } online): a phone app's "take the job". For a scenario whose Settings say A run starts: From a script, or When it's switched on (the player joins its waiting run). The player becomes its starter; Players this close join applies. opts: the next card.

Returns: the run's id, or false, reason (not switched on, not "From a script", already in one, its runs full)
local runId, why = exports.whip_core:StartScenarioRun('bank_job', source)
if not runId then exports.whip_core:NotifyPlayer(source, why, 'error') end
StartScenarioRun(key, who, opts?) · optsSERVER#

Crew, variables and places of its own: one scenario, played at today's gang territory.

FieldTypeDescription
withtable?More players, as crew; 16 at most. One who is down, in the character screen or already in a run of it is left out
varstable?Its variables, of the types the scenario declares
placestable?By placed thing, where this run's NPCs, vehicles, items, containers and spots are: { x, y, z, heading } or a vector3 / vector4. Add interior = true inside an MLO. Refused for a Standing thing, a door or a prop
Returns: the run's id, or false, reason (a variable of the wrong type or one it doesn't have, a place it can't take, ...)
local runId, why = exports.whip_core:StartScenarioRun('turf_war', source, {
    with = { partner },
    vars = { reward = 2500, rival = 'Ballas' },
    places = { stash = { x = 102.4, y = -1940.2, z = 20.8, heading = 90 },
               boss  = vector4(-1150.2, -1520.6, 10.6, 35.0) },
})
When it's switched on. For a scenario that starts this way, the player and with join its waiting run: vars and places are refused.
CanStartScenarioRun(key, who)SERVER#

StartScenarioRun's checks, starting nothing: switched on, "From a script" (or When it's switched on, its waiting run not taken), on a character and up, not already in one, runs not full. A phone app greys out the jobs a player can't take.

ParamTypeDescription
keystringThe scenario's key
whonumber | { charId }A server id, or an online character
Returns: true, or false, reason

Reading runs and scenarios

GetScenarioRun(runId, opts?) · GetScenarioRuns(filter?)SERVER#

A run going now, or all of them, as a DirectorRunView: { id, tag, scenario, name, rev, test, kinds, where, players = { {source, charId, name} }, starter, startedAt, seconds, endsIn, vars, objectives = { {source, text, countdown} }, things = { [placedThingId] = { kind, netId, npcId, vehicleId, ... } } }. Give its tag to what you make for the run (ShowBlip, AddPoint, SpawnNpc's opts): it goes when the run ends.

ParamTypeDescription
filter.scenariostring?Runs of one scenario
filter.playernumber | { charId }?Runs a player is in
filter.kindstring?Runs of scenarios of that Kind (Settings)
filter.tests / opts.testsboolean?Include builders' Tests
Returns: GetScenarioRun: the view, or false, reason. GetScenarioRuns: a list (empty when none)
for _, run in ipairs(exports.whip_core:GetScenarioRuns({ kind = 'heist' })) do
    print(run.name, run.where and run.where.label, #run.players)
end
IsPlayerInScenarioRun(who, key?, opts?) · GetPlayerScenarioRuns(who, opts?)SERVER#

Whether a player is in a run now (of that scenario, or any), and which. who: a server id or { charId } (online).

Returns: true | false · a list of DirectorRunViews
if exports.whip_core:IsPlayerInScenarioRun(source, 'bank_job') then
    return false, 'Finish the job you are on first'
end
GetScenarioRunOf(ref, opts?)SERVER#

Which run a vehicle, an NPC or a tag belongs to: { netId }, { vehicleId }, { npcId } or { tag }. Is this car a heist's getaway car?

Returns: the run's DirectorRunView, or false, reason (not part of a run going now)
GetScenario(key) · GetScenarios(filter?)SERVER#

A scenario as a DirectorScenarioView: { key, name, description, kinds, where, on, rev, draftRev, startMode, source, runs }; GetScenario adds cards (the card types it uses), world (its placed things) and vars. It describes the revision switched on, or the draft when it's off, and never waits. filter: { on, kind, startMode }.

Returns: the view, or false, reason · a list
GetScenarioStats(key)SERVERWAITS#

How a stored scenario's runs have gone, Tests left out: { runs, succeeded, stopped, lastAt } (stopped: called off, stopped by an admin, cut short). It waits on the database: call it from a thread.

Returns: the numbers, or false, reason
GetDirectorCards(filter?)SERVER#

The editor's card types, each with its owner: { type, title, desc, category, inputs, outputs, labels, props, owner }. filter: { category }.

Returns: a list

Steering a run

EndScenarioRun(runId, outcome, reason?)SERVER#

Ends a run as a card would: 'succeeded', 'failed' or 'calledOff' (no result, nobody told). The reason gets your resource's name ('the crew was arrested (by police_mdt)') in whip_core:run:ended and the history. The one control call that also takes a builder's Test.

Returns: true, or false, reason
local ok, why = exports.whip_core:EndScenarioRun(runId, 'failed', 'the crew was arrested')
AddPlayerToScenarioRun(runId, who) · RemovePlayerFromScenarioRun(runId, who, why?)SERVER#

Puts a player into a run going now as crew, or takes one out. Crew get the run's doors, containers, payouts and items as the starter does, and what its cards gave "the run's players" (prompts, goals, the objective, guards' targets, blips); one taken out loses it all. Both are announced (run:playerJoined / :playerLeft, with by).

Adding is refused for a Test, a player down or with no character, one already in a run of it, and a full run (16). Police responding to a heist aren't crew: reach them with blips.

Returns: true, or false, reason
local ok, why = exports.whip_core:AddPlayerToScenarioRun(runId, friendSource)

CreateThread(function()   -- taking someone out waits
    exports.whip_core:RemovePlayerFromScenarioRun(runId, friendSource, 'left the crew')
end)
RemovePlayerFromScenarioRun waits. It takes back what the run handed them first: call it from a thread.
GetScenarioRunVar(runId, name) · SetScenarioRunVar(runId, name, value)SERVER#

Reads or sets a run's variable, of the type the scenario declares (number, text, true/false). The next card that reads it sees your value. Not written into the history.

Returns: Get: true, value (true first: a variable can hold false or nothing), or false, reason. Set: true, or false, reason
local ok, score = exports.whip_core:GetScenarioRunVar(runId, 'score')
if ok then exports.whip_core:SetScenarioRunVar(runId, 'score', (score or 0) + 10) end
SendDirectorEvent(name, payload?, opts?)SERVER#

Every Wait for Script Event card waiting for name carries on. name is in your namespace ('police.backupArrived'): the first running resource to send in one has it until it stops; whip_core's (npc., player. ...) are nobody's. payload.source is who it's about, and what follows acts for them (about none of its players: for whoever the card's branch was for). opts.runId: only that run hears it. At most 20 of one event a second, and 60 a second from one resource.

Returns: true, heardBy (how many runs heard it), or false, reason
-- an officer pressed "en route" on the MDT (checked in your own SecureEvent first)
exports.whip_core:SendDirectorEvent('police.backupArrived', { source = robber, unit = 'Adam-12' })
Testing a Wait card. A Test never hears a real script's event. /director send <event> [value] (any builder) puts one into your own Test, about you.
SwitchScenario(key, on, why?)SERVERWAITS#

Switches a scenario on (true) or off by script: heists only at night. Only one whose Settings say Scripts may switch it on and off, never while a builder tests it, and on only at the revision a person last switched on (never a draft, never one a person switched off). Off calls off its runs, with your reason and resource name. It waits: call it from a thread.

In memory only: a reboot puts back what a person chose, and a person switching it forgets yours. An off while its pack restarts or the server starts is remembered. The switch events and /whip show by = { resource }.

Returns: true, or false, reason
CreateThread(function()
    local wasNight
    while true do
        local hour = exports.whip_core:GetTime()
        local night = hour >= 22 or hour < 5
        if night ~= wasNight then
            exports.whip_core:SwitchScenario('bank_job', night, 'night only')
            wasNight = night
        end
        Wait(60000)
    end
end)