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| Id | Names | Lasts | Used by |
|---|---|---|---|
source | A connected player | Until they leave; the next player can get the same number | Everything about someone online: GetPlayer, AddItem, NotifyPlayer |
{ charId = n } | A character, online or not | Forever | Calls that can reach someone offline: PayPlayer, GiveOnLogin, the bank (naming a person) |
userId | An account | Forever | Staff permissions (GrantPermission) |
player.session | One load of a character | Until logout | IsSessionCurrent, after your handler waited |
vehicleId | A car WHIP knows | Owned: forever. Others: until the restart | Every 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 data | Put it in | Saved by | Visible to |
|---|---|---|---|
| Items and cash a player carries | Their pockets: AddItem, PayPlayer | WHIP, with the action | The player; admins |
| Something about one item: a serial, rounds, wear | Its metadata: SetItemMetadata | WHIP, with the item | The holder's game too: never a secret |
| A fact about a character: a licence, quest progress | SetPlayerFlag while they're online; SetPlayerMetadata, GiveOnLogin or the bank for someone offline too | WHIP, with the character | Their game too: never a secret |
| Something about a car: a fitted part, a finance flag | SetVehicleData; a gauge (fuel, boost) is a vehicle stat | WHIP, with the car | Games near the car, for a stat |
| Items kept somewhere new: a mailbox, a vault | A container (EnsureContainer) or a store kind of your own | WHIP | Whoever its rules let open it |
| Your resource's settings | A settings page: Whip.configPage (Settings pages) | WHIP, in the database | Admins edit it in /whip; every game reads it unless the setting says sides = 'server' |
| A player's own choice: a volume, a toggle | Whip.playerSetting (player settings) | Their own PC | That player |
| Anything else: a ledger, a leaderboard | A table of your own, made with EnsureTable | You; use CommitWithAction after an inventory change | Whoever your code shows it to |
| An item for a character who's away | GiveOnLogin | WHIP, until their next login | Them, when it arrives |
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.
| Param | Type | Description |
|---|---|---|
| name | string | The table's name |
| createSql | string | The table as it is now, complete |
| migrations | table? | Changes made after release, in order, only ever appended. Each runs once per database, recorded as '<resource>:<id>' |
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)
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.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.
| Param | Type | Description |
|---|---|---|
| queries | table[] | { { query = '…', values = { … } }, … } |
| opts | table? | Called outside the handler that made the change? Name whose action with source (and vehicleId) |
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' } },
})
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.
| Param | Type | Description |
|---|---|---|
| who | number|table | A server id or { charId = n } |
| item | string | Item key |
| amount, metadata, opts | number?, table?, table? | As for AddItem; opts.reason goes in the log |
'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' })