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
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.
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
Crew, variables and places of its own: one scenario, played at today's gang territory.
| Field | Type | Description |
|---|---|---|
| with | table? | 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 |
| vars | table? | Its variables, of the types the scenario declares |
| places | table? | 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 |
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) },
})
with join its waiting run: vars and places are refused.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.
| Param | Type | Description |
|---|---|---|
| key | string | The scenario's key |
| who | number | { charId } | A server id, or an online character |
true, or false, reasonReading runs and scenarios
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.
| Param | Type | Description |
|---|---|---|
| filter.scenario | string? | Runs of one scenario |
| filter.player | number | { charId }? | Runs a player is in |
| filter.kind | string? | Runs of scenarios of that Kind (Settings) |
| filter.tests / opts.tests | boolean? | Include builders' Tests |
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
Whether a player is in a run now (of that scenario, or any), and which. who: a server id or { charId } (online).
true | false · a list of DirectorRunViewsif exports.whip_core:IsPlayerInScenarioRun(source, 'bank_job') then
return false, 'Finish the job you are on first'
end
Which run a vehicle, an NPC or a tag belongs to: { netId }, { vehicleId }, { npcId } or { tag }. Is this car a heist's getaway car?
false, reason (not part of a run going now)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 }.
false, reason · a listHow 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.
false, reasonThe editor's card types, each with its owner: { type, title, desc, category, inputs, outputs, labels, props, owner }. filter: { category }.
Steering a run
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.
true, or false, reasonlocal ok, why = exports.whip_core:EndScenarioRun(runId, 'failed', 'the crew was arrested')
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.
true, or false, reasonlocal ok, why = exports.whip_core:AddPlayerToScenarioRun(runId, friendSource)
CreateThread(function() -- taking someone out waits
exports.whip_core:RemovePlayerFromScenarioRun(runId, friendSource, 'left the crew')
end)
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.
true, value (true first: a variable can hold false or nothing), or false, reason. Set: true, or false, reasonlocal ok, score = exports.whip_core:GetScenarioRunVar(runId, 'score')
if ok then exports.whip_core:SetScenarioRunVar(runId, 'score', (score or 0) + 10) end
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.
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' })
/director send <event> [value] (any builder) puts one into your own Test, about you.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 }.
true, or false, reasonCreateThread(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)