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

How WHIP works

Five ideas explain most of WHIP. Read this page alongside Your First Resource.

1. Accounts, characters and sessions

account        userId     made the first time they connect; staff permissions belong here
 └ character   charId     up to Config.MaxCharacters per account; kept forever: save this one
    └ loaded on a server id (source), for one session (player.session), until logout
IdNamesLastsUsed by
sourceA connected playerUntil they leave; the next player can get the same numberEverything about someone online: GetPlayer, AddItem, NotifyPlayer
{ charId = n }A character, online or notForeverCalls that can reach someone offline: PayPlayer, GiveOnLogin, the bank (naming a person)
userIdAn accountForeverStaff permissions (GrantPermission)
player.sessionOne load of a characterUntil logoutIsSessionCurrent, after your handler waited
vehicleIdA car WHIP knowsOwned: forever. Others: until the restartEvery vehicle export (vehicle references)

2. Every place items sit is a store

Pockets, a stash, a car's boot, glovebox or ignition, a shop, a wallet: each is a store, addressed as { kind, id, sub, slot }. One call moves items between any two (StoreMove), with the same checks, so code that fills a stash can fill a boot.

3. Memory first, the database catches up

WHIP changes its memory at once and writes the changes within about a second. Everything one player action changes is written in one transaction, so a crash never leaves half of it (Save System).

4. Declarations live in whip_core's memory

Items, use handlers, prompts and secure events are forgotten when whip_core restarts. So they go in Whip.register, which declares them again (the one rule).

5. The server decides

A player's game only asks. A SecureEvent checks who asked, how often, from where and every value before your handler runs. What the client is shown (an action's require) is a courtesy, never the check.

Where your data lives#

Your dataPut it inSaved byVisible to
Items and cash a player carriesTheir pockets: AddItem, PayPlayerWHIP, with the actionThe player; admins
Something about one item: a serial, rounds, wearIts metadata: SetItemMetadataWHIP, with the itemThe holder's game too: never a secret
A fact about a character: a licence, quest progressSetPlayerFlag while they're online; SetPlayerMetadata, GiveOnLogin or the bank for someone offline tooWHIP, with the characterTheir game too: never a secret
Something about a car: a fitted part, a finance flagSetVehicleData; a gauge (fuel, boost) is a vehicle statWHIP, with the carGames near the car, for a stat
Items kept somewhere new: a mailbox, a vaultA container (EnsureContainer) or a store kind of your ownWHIPWhoever its rules let open it
Your resource's settingsA settings page: Whip.configPage (Settings pages)WHIP, in the databaseAdmins edit it in /whip; every game reads it unless the setting says sides = 'server'
A player's own choice: a volume, a toggleWhip.playerSetting (player settings)Their own PCThat player
Anything else: a ledger, a leaderboardA table of your own, made with EnsureTableYou; use CommitWithAction after an inventory changeWhoever your code shows it to
An item for a character who's awayGiveOnLoginWHIP, until their next loginThem, when it arrives
EnsureTable(name, createSql, migrations?)SERVERWAITS#

Creates a table of your own the way WHIP creates its own, so nobody imports a .sql file. createSql is one complete CREATE TABLE IF NOT EXISTS; text sorts by utf8mb4_unicode_ci unless you name a COLLATE.

ParamTypeDescription
namestringThe table's name
createSqlstringThe table as it is now, complete
migrationstable?Changes made after release, in order, only ever appended. Each runs once per database, recorded as '<resource>:<id>'
Returns: true, or false, why: a bad name or statement, or the first migration that failed (later ones wait for the next start)
Whip.register(function()
    Whip.core:EnsureTable('mycafe_orders', [[
        CREATE TABLE IF NOT EXISTS `mycafe_orders` (
            `id`     INT UNSIGNED NOT NULL AUTO_INCREMENT,
            `charId` INT          NOT NULL,
            `note`   VARCHAR(200) NULL,
            PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4]], {
        { id = '002_note', statements = {
            { sql = 'ALTER TABLE `mycafe_orders` ADD COLUMN `note` VARCHAR(200) NULL',
              unless = { column = { 'mycafe_orders', 'note' } } },
        } },
    })
end)
Put each change in both places. The CREATE for a new server, a migration for one that has the table. When this call creates the table, migrations are recorded as done without running. Guard a statement with unless or onlyIf and { column = { table, name } }, { index = … } or { constraint = … }; or give a migration a run function that returns false to be retried next start.
CommitWithAction(queries, opts?)SERVERWAITS#

Runs your queries in one transaction with everything the player's current action changed that WHIP hasn't written yet: the item taken and your ledger row land together, or neither does. Outside an action, it runs the queries alone.

ParamTypeDescription
queriestable[]{ { query = '…', values = { … } }, … }
optstable?Called outside the handler that made the change? Name whose action with source (and vehicleId)
Returns: true, or false, why (nothing of the transaction landed; WHIP writes its own part again later)
local ok, why = exports.whip_core:RemoveItem(source, 'mycafe_coffee', 1)
if not ok then return false, why end
ok, why = exports.whip_core:CommitWithAction({
    { query = 'INSERT INTO `mycafe_orders` (`charId`, `note`) VALUES (?, ?)', values = { player.charId, 'coffee' } },
})
GiveOnLogin(who, item, amount?, metadata?, opts?)SERVERWAITS#

Gives an item to someone who may not be playing: a prize, a refund owed. Online, they get it now, like AddItem. Offline, it's kept in the database and handed over at their next login (at their feet if their pockets are full), logged with your reason.

ParamTypeDescription
whonumber|tableA server id or { charId = n }
itemstringItem key
amount, metadata, optsnumber?, table?, table?As for AddItem; opts.reason goes in the log
Returns: 'now' or 'login', or false, why (unknown item, bad amount, no such charId)
exports.whip_core:GiveOnLogin({ charId = winner }, 'mycafe_voucher', 1, false, { reason = 'raffle prize' })