Director: tasks and buttons of your own
Besides cards, your resource can add tasks to the Tasks list of NPCs and vehicles, buttons on placed things, and add-on weapons to every weapon list. They use your cards' namespace, and go away when your resource stops.
A button can keep data on a thing, saved with the scenario, and a run hands it back when it makes the thing. A tuning resource, say, adds a Customise button that saves paint and parts on a placed vehicle, and applies them when it hears whip_core:run:thingMade.
Tasks
Adds a task, or changes one. Call it once, in a file both sides load: every game keeps your run, which plays the step on the game that owns the NPC or vehicle. The world builder's Play here runs it on its own copy, with info.preview set.
| Field | Type | Description |
|---|---|---|
| label | string | Its name in the + Task picker (40 letters at most) |
| desc | string? | One line about what it does |
| group | string? | The picker's group: move, look, fight, act, car, body, wait, or your own, named by groupTitle (default: your namespace) |
| kinds | string[] | Who can do it: 'npc', 'vehicle'. A prop's tasks are whip_core's only |
| timing | string? | 'instant' (done once started), 'timed' (lasts sec seconds: the default), 'until' (until done, giving up after giveUp seconds), 'either' (the builder picks; next = 'done' or 'time' is the default) |
| sec | number? | A timed step's seconds (3), up to 86399; 0 is no end: it lasts until its list is stopped. The builder can change it |
| giveUp | number? | An until step's limit in seconds (30), up to 86399; 0 is never: it waits until it's done. The builder can change it |
| lasting | boolean? | It keeps going after its slot: a Wait after it keeps the thing at it |
| once | boolean? | A new owner never plays it again (it would happen twice: a line of speech, a throw) |
| standing | boolean? | false: a standing NPC passes it over (it needs a run) |
| fields | table[]? | Up to 8, each { key, kind, label, hint?, default?, required? }. Kinds: number (min, max, unit; slider = true with a step needs min and max), bool, select (1 to 200 options; look = 'seg' shows 2 to 4 as buttons), text (max), world (a placed thing; worldKind limits it), point (key 'at'), target (key 'target': the nearest player, who set the card off, a placed thing or a point) |
| run | function | run(entity, args, info), on the game that owns the thing, in a thread of its own (it may wait). In args, a world field is that thing's entity on this game (nil when it isn't here), a target { kind, entity, coords }, a point { x, y, z, heading }. info: { type, kind, timing, ms, preview }, ms being the step's time (a week for a step with no end) |
| done | function? | An until step's check, asked every quarter second: true done, 'failed' failed, anything else not yet. Without it, the step is done when run returns (false or an error: failed) |
true, or false when it isn't a task (printed). whip_core's own answer is printed when it refuses one. Whip.removeTask(type) takes one away on the side it's called on.-- shared/director.lua, in shared_scripts
Whip.task('mycafe.flash', {
label = 'Flash the Lights', group = 'car', kinds = { 'vehicle' }, timing = 'timed', sec = 4,
fields = { { key = 'times', kind = 'number', label = 'Times', min = 1, max = 20, default = 5 } },
run = function(car, args)
for _ = 1, args.times do
SetVehicleLights(car, 2) Wait(200)
SetVehicleLights(car, 1) Wait(200)
end
SetVehicleLights(car, 0)
end,
})
run to what the entity itself does.Buttons and their data
Adds a button for a kind of placed thing, or changes one: under Tools on the thing's page, under the world builder's bubble, or both. Pressed, your press runs on that player's game, in a thread of its own. A thing not in the scenario yet is added first, as Configure does.
| Field | Type | Description |
|---|---|---|
| label | string | The button's text (24 letters at most) |
| kinds | string[] | Which placed things have it: npc, vehicle, prop, spot, groundItem, container, door, route |
| where | string? | 'page', 'bubble' or 'both' (the default) |
| takesOver | boolean? | The Director steps aside first (the page hides, the mouse is let go) until you call thing:back(), your code throws, or your resource stops; then the world builder opens on the thing again |
| icon | string? | One of WHIP's icons by its key, as AddAction's ('turbo', 'lock') |
| hint | string? | Its tooltip |
| press | function | press(thing): thing is { id, kind, label, model, models, coords, scenario, data, entity, builder }. data is what you keep on it; entity the world builder's copy while it's open (never for a button that takes over); builder whether it was pressed there |
thing:save(t)keepston the thing: plain data, 4 KB of JSON at most;niltakes it away. It's an edit like any other, so Save keeps it and Ctrl+Z undoes it.thing:back(t?)hands the screen back after a button that takes over, keepingtfirst when given.- A random vehicle has
models, every model a run picks from, and is pressed for one of them:model. - A button for kind
'card'fills your card'sentriesfield. Its thing is the card, withcard = { type, field, entry, value, props, world }(entrynil for a new one), andthing:save(t)keepstas that entry.
true, or false when it isn't a button (printed). Whip.removeDirectorButton(id) takes one away. thing:save and thing:back: true, or false, reason-- client.lua
Whip.directorButton('mycafe.customise', {
label = 'Customise', icon = 'turbo', kinds = { 'vehicle' }, takesOver = true,
press = function(thing)
local paint = OpenMyTuningScreen(thing.model, thing.coords, thing.data) -- yours; waits until it closes
thing:back(paint and { paint = paint } or nil)
end,
})
A copy of what your buttons saved on a placed thing. where is a run's id (that run's revision) or a scenario's key (the revision on now). A card reads it with card:made(id).data.
whip_core:run:thingMade brings it too, each time a run makes something for a placed thing: { run, world, kind, label, netId, npcId, vehicleId, containerId, groundId, doorId, data }, with yours in data[GetCurrentResourceName()]. An Always present thing fires it when the scenario is switched on (or a Test starts), with no run: { scenario, standing = true, test, world, kind, ... }. netId may be nil for a moment after a car is made.
nil (nothing saved), or false, reason (no such run, scenario or thing)AddEventHandler('whip_core:run:thingMade', function(e)
if GetInvokingResource() ~= 'whip_core' then return end
local mine = e.data[GetCurrentResourceName()]
if e.kind == 'vehicle' and mine and mine.paint then PaintRunCar(e.vehicleId, mine.paint) end -- yours
end)
run.test if yours mustn't act on one.Weapons
Offers your add-on weapons (the WEAPON_* names in your weapons.meta) beside GTA's wherever WHIP lists weapons: an NPC's Weapon, the Hold a Weapon task, the world builder (a firearm with a world model can be a Remote Control Firearm's Gun), Dungeon Mode, the Object Viewer. Each shows your tag: Pump Shotgun (gunny).
Call it once, in a file both sides load: the server's list decides what Check and a run accept, each game's what its editor offers. Calling it again replaces your list.
| Field | Type | Description |
|---|---|---|
| list[n].name | string | WEAPON_ and capitals, digits or _ (64 at most); never GTA's own |
| list[n].label | string | Its name in the lists (40 letters at most) |
| list[n].group | string | pistol, smg, rifle, machine gun, shotgun, sniper, heavy, thrown, stun gun or melee |
| list[n].model | string? | A firearm's world model (its <Model>), so it can be a Remote Control Firearm; never GTA's |
| opts.tag | string? | What shows after each label (16 letters at most). Default: your resource's name |
true, or false when it isn't a list (printed). When whip_core refuses one, its answer is printed and none of the list is added. Whip.removeWeapons() takes yours away on the side it's called on.-- config/weapon_catalog.lua, in shared_scripts
Whip.weapons({
{ name = 'WEAPON_MY_PUMP', label = 'Pump Shotgun', group = 'shotgun', model = 'w_sg_my_pump' },
{ name = 'WEAPON_MY_KNIFE', label = 'Knife', group = 'melee' },
}, { tag = 'mine' })
A scenario using one of your weapons waits at server start until your resource adds it. An NPC given one carries the gun itself, never your item, so your ammo and reload code isn't on it.
Object Viewer options
An option of yours in the Object Viewer's list (the /w developer tool: G on what it has picked out opens its options), for the kinds you name. whip = true shows it for WHIP's own things only (a saved car, a player), false for the game's only (a street car, an NPC walking by), left out for both. id is '<your namespace>.<name>'; every field is in the full reference.
true, or false (printed). tint: blue, teal, green, amber, red, violet or slate. Whip.removeObjectViewerOption(id) takes one away; it goes when your resource stopsselect asks of your server must check for itself (HasDevTools).