Settings pages for your resource
Put your resource's settings in /whip → Settings beside Config, so server owners never open your config file. You declare the settings; WHIP builds the page, checks and saves values, sends changes to every player and calls you back.
The page is named by your label, and only permanent admins see it. Declare it with Whip.configPage from WHIP's helper, in a shared script: the server checks and saves, and each player's game needs your defaults.
mycafe to mycafe-v2) starts from your defaults again, so tell owners to keep the name across updates.Your config.lua as the page#
Your resource reads a Config table, and Whip.configPage (from @whip_core/lib/satellite.lua) puts chosen Config values on your page. Each key is a path in Config, its default is config.lua's value, and saved values are written into Config on both sides, so your code keeps reading Config.X.
Saved values arrive when whip_core is ready, after your files load. Code that reads Config at file scope sees config.lua's values first: rebuild what it works out with Whip.onConfigChanged. whip_autos's shared/settings.lua is a worked example.
Call once at file scope (not in Whip.register), in a shared script after config.lua; it declares the page on both sides whenever whip_core is ready. Entries are the setting entries below, without default; tables are changed in place, so a local copy of Config.Shop sees new values.
Saved values are checked again: one that no longer passes (you lowered a max) is dropped with a console line, and config.lua's value stands. The page goes when your resource stops; saved values stay.
Values are kept as their check returns them (text trimmed, keyKind = 'hash' maps keyed by hash). sides = 'server' values go into the server's Config only. Only data goes on a page: an entry holding a function, or an undeclared table or position field in a row, is left off with a console line.
| Field | Type | Description |
|---|---|---|
| label | string | The page's name in Settings |
| settings | table | The entries, in order; each key a path such as 'Tuning.EngineSwapPrice' |
| groups | table|nil | Instead of settings, for a long page: { { label = 'Prices', settings = { … } }, … }, each a group on the left |
| config | table|nil | The table the keys are in. Default Config |
boolean: false when def isn't a page (printed). whip_core's own refusal is printed when the page is declared-- settings.lua (shared_script, after config.lua)
Whip.configPage({
label = 'My Cafe',
groups = {
{ label = 'Prices', settings = {
{ key = 'Prices.coffee', type = 'int', min = 1, max = 500, unit = '$', label = 'Coffee' },
} },
{ label = 'Counter', settings = {
{ key = 'Counter.coords', type = 'vec3', here = true, label = 'Where it stands' },
{ key = 'Counter.open', type = 'bool', label = 'Open' },
} },
},
})
config.lua value its own row would refuse leaves that row off the page, with the reason in the console, and your code keeps reading the raw value.Rebuilds what you worked out from Config at load. fn runs after a page value changes on this side, including saved values written in as the page is declared. It hears its path, anything under it, and changes to a table it's inside. Call it at file scope: inside Whip.register it would be added again at every whip_core restart.
| Param | Type | Description |
|---|---|---|
| path | string | A path in Config |
| fn | function | function(value, old, key): key is the path that changed, so a hook on 'Counter.coords' hearing 'Counter' gets the whole table. Read Config when in doubt. Mustn't wait |
Whip.onConfigChanged('Counter.coords', function()
local c = Config.Counter.coords
SetBlipCoords(counterBlip, c.x, c.y, c.z)
end)
Setting entries#
Each entry of a page's settings, and of an item's own settings:
| Field | Type | Description |
|---|---|---|
| key | string | Letters, digits, _ and ., starting with a letter or _, up to 64; unique on the page. A dot makes a path: a callback on 'prices' also hears 'prices.coffee' |
| type | string | 'int', 'number', 'bool', 'string', 'enum', 'vec3', 'vec4', 'list', 'records', 'map' or 'record' (one card of fields, each its own setting: 'turbo.gain', its default from the card's default table) |
| default | any | The value until an admin changes it: an item's setting gives one; on a Whip.configPage page it's config.lua's value. It must pass the entry's checks or the row is left off (the console says which); the page is refused only when none pass |
| shownWhen | table|nil | { path = 'key', equals = value }: show the row (or whole card) only while that setting has that value |
| label / help | string | The row's name, and the line under it |
| min / max / step | number|nil | int and number: range, and the arrows' step |
| unit | string|nil | int and number: '$' goes in front, anything else ('m', 'ms') after |
| options | table | enum: { { value = 'slow', label = 'Slow' }, … } |
| maxLen / pattern / patternWhy | number / string | string: most characters; a Lua pattern it must match (use ^…$ for the whole text); the message when it doesn't |
| nullable / emptyLabel | boolean / string | An empty box is nil, and the row calls it this (default 'none') |
| offWhenEmpty | boolean | int, number, string: an empty box is false ("off"), for a cap that can be switched off |
| apply | string|nil | 'live' (default): in force at once, everywhere. 'restart': in force when your resource or whip_core next starts; read it at start, Whip.onConfigChanged isn't called. 'readonly': shown, never changed |
| why | string|nil | For 'restart' or 'readonly': the reason shown on the row |
| sides | string|nil | 'both' (default), or 'server': never sent to players, for a key or password. Admins still see it |
| cross | function|nil | function(get), run on the server when this setting is in a save; get(key) returns any setting as it will be saved. Return true, or false, 'why' to refuse. Give both entries of a two-setting rule the check |
| here / limits | boolean / table | vec3, vec4: a Use where I stand button, and { x = { min, max }, … } per ranged axis |
| place | boolean / table | vec3, vec4: a Place button: the panel steps aside and the point is placed in the world (PlacePoint). { model = 's_f_y_shop_mid', ped = true } picks the ghost |
| item | table | list: every entry's shape, as an entry with no key: { type = 'int', min = 1, max = 9 }. int, number, string or enum, edited as one comma-separated line. For positions, use records with a vec3 field |
| fields | table | records, a map of rows, or record: the fields, each an entry with a key |
| widget / marker | string / table | widget = 'mapPoints': records with a vec3 and a string field show as map icons, dragged to move, clicked to rename or remove, added where the admin stands. marker = { sprite = 361, colour = 1, name = 'Gas Station' }: the blip and a new row's name |
| each | table | map of single values: each value's shape, e.g. { type = 'string', maxLen = 20 } |
| minItems / maxItems / unique | number / string | How many entries or rows (a map takes maxItems only), and for records a field no two rows share. Set them equal to fix a table's rows |
| keyKind / keyPattern / keyWhy | string|nil | map: keyKind = 'hash' takes a model name and keeps its hash (as GetEntityModel returns). 'number' keeps a digits-only key as a number (a mod slot, a wheel type). Name keys are checked against keyPattern |
Each player's own settings#
A choice each player makes for their own screen (volume, units, shown or hidden) goes on the pause menu's Server Settings page, as a row of yours. Your resource stores the value (its own KVP, on the player's PC); the page calls your get and set. The row goes when your resource stops and comes back when whip_core restarts.
Adds a row to Settings, under Server. From WHIP's helper; call it at file scope, it registers inside Whip.register itself. A refusal is printed with the reason.
| Field | Type | Description |
|---|---|---|
| key | string | Unique: letters, digits, dots, dashes or underscores, up to 64. Start with your resource's name ('mycafe.sounds') |
| label | string | The row's name |
| type | string | 'toggle' (true / false), 'choice' (one of options) or 'slider' (a number) |
| get | function | function() returns the current value |
| set | function | function(value) stores the new value. The page keeps nothing of yours |
| default | any | Required. What "Reset this page to server defaults" restores: true, an option's value, a number in range |
| group | string? | The tab: 'Controller', 'Vehicles', 'Map & HUD', 'Chat & voice' or your own. Default 'Other' |
| help | string? | One line under the row |
| options | table? | A choice's options, each { value, label }: at least two |
| min, max, step, unit | number?, string? | A slider's range, step (default 1) and the text after the number |
boolean: false (printed) when def has no key, get or set, or this is the serverlocal sounds = GetResourceKvpInt('sounds') ~= 2 -- 2 is off; unset reads 0, so on
Whip.playerSetting({
key = 'mycafe.sounds', group = 'Map & HUD', type = 'toggle', default = true,
label = 'Café sounds', help = 'The till and the coffee machine.',
get = function() return sounds end,
set = function(on)
sounds = on
SetResourceKvpInt('sounds', on and 1 or 2)
end,
})
A row's value on this player's PC: their choice, else the default. Reads whip_core's own rows too.
| Param | Type | Description |
|---|---|---|
| key | string | The row's key |
any, or nil for a key not on the pagelocal unit = exports.whip_core:GetPlayerSetting('dial.speedUnit') -- 'mph' or 'kmh'
Changes a row's value on this player's PC, as the page does, for your own screen that shows the same setting. A resource's row goes through its set; out-of-range values are clamped. whip_phone's call volume is voice.callVolume this way.
| Param | Type | Description |
|---|---|---|
| key | string | The row's key |
| value | any | A value its type takes |
true, or false, reason (no such setting, or a value its type doesn't take)local ok, why = exports.whip_core:SetPlayerSetting('voice.callVolume', 75)