The satellite helper
@whip_core/lib/satellite.lua is a file your resource loads, giving you Whip.register, safe calls to whip_core and a few tools. It runs inside your resource so it can remember your registrations across a whip_core restart.
-- fxmanifest.lua
dependency 'whip_core'
shared_script '@whip_core/lib/satellite.lua'| Call | What it does |
|---|---|
Whip.register(fn) | Runs fn once whip_core is ready (whichever started first) and again after every whip_core restart. Your declarations go in it, through Whip.core, and a refusal is printed (what it prints). Server and client. |
Whip.core:Name(…) | Calls an export safely, with its types in your editor: Whip.core:AddItem(source, 'cookie', 1). Returns what the export returns, or false, why when whip_core is down or the call errored. If whip_core stops during a wait it returns false, 'whip_core stopped', meaning "no answer", not "didn't happen": a charge already sent may still land. |
Whip.call(name, …) | The same, for a name built at run time: Whip.call(exportName, …). Otherwise use Whip.core, which your editor checks. |
Whip.ready(timeoutMs?) | Waits (in a thread) until whip_core is ready. false on timeout. |
Whip.isReady() | Is whip_core running and ready right now? |
Whip.command(name, opts, fn) (server) | A chat command behind a SecureEvent's checks: refused while the player is down (whileDead = true allows it), rate limited (three at once, then one a second; rateLimit = false for none), ace = 'my.perm', and dev = true for the console and whip.devtools with developer mode on. fn(source, args, raw) runs in its own thread. Use it instead of RegisterCommand with your own checks. |
Whip.sayStarted() · Whip.startProblem(fmt, …) (server) | One start line in the console instead of one per system. Once your Whip.register functions have run, it prints <your resource> started successfully!, unless something went wrong since your resource started (one of them threw, an error was caught, or something was printed in red); then those lines are all it prints. Whip.startProblem('engines.json is unreadable: %s', why) prints a problem in red with your resource's name. Call Whip.sayStarted() once, in a server file. |
Whip.registry(name, opts) · Whip.caller() | A registry of your own with WHIP's registration rule, for a resource others extend (phone apps, MDT plugins): local Apps = Whip.registry('app', { label = 'app' }), then in your export return Apps:add(Whip.caller(), id, def). Read Apps.entries, Apps:get(id), Apps:keysOf(owner). |
Whip.registerWith(resource, fn) | Runs fn now if resource is running and each time it starts, so registering with another resource's registry survives its restart. |
Whip.requires('1.0') · Whip.has(name) | Version checks. Put whip_requires '1.0' in your fxmanifest and the setup report flags an older whip_core; Whip.requires does the same from code. Whip.has('GetBalance') checks for one export. whip_updates 'you/myresource' there tells server owners when your GitHub repository has a newer release (Update checks). |
Whip.onCoreLost(fn) | Only for a resource without dependency 'whip_core': runs when whip_core stops, to let go of anything that needed it. Every player has been logged out by then with no whip_core:player:logout, so drop per-player state too. |
Whip.voice(name, …) · Whip.voiceSystem() | Calls whichever voice system runs (Voice for other resources). |
Declaring in Whip.register#
One function can hold every declaration: a loop over your Config, an answer you keep (an AddAction id), state of your own to reset. It runs again after each whip_core restart, so it reads Config as it is then, settings-page values included.
Whip.register(function()
Whip.core:RegisterItem('mycafe_cup', { name = 'Cup', weight = 0.1 })
for key, drink in pairs(Config.Drinks) do
Whip.core:RegisterItem(key, drink)
end
end)While it runs, a declaring call that whip_core refuses prints one line in your console, naming your resource, the export and the reason: Register…, Ensure…, Add…, On…, Watch…, SecureEvent and SecureCallback, called through Whip.core or Whip.call. A call straight through exports.whip_core isn't printed: check its return yourself.
What else it does
- With
dependency 'whip_core', a whip_core restart stops and restarts your resource, so you start fresh and there's nothing to clean up. Without it, your resource keeps running:Whip.onCoreLostruns, then yourWhip.registerfunctions run again when whip_core is back. - It reports your errors to WHIP's tools (
GetErrorLog, the Monitor) by wrappingCreateThread,SetTimeout,RegisterCommand,AddStateBagChangeHandler,RegisterNUICallbackandprint. They behave as before, at about half a microsecond per handler. Opt out withwhip_error_tap 'no'in your fxmanifest. - Autocomplete: copy
whip_core/types/luarc.template.jsonto your resource as.luarc.json. It finds WHIP's types next to your resource (../whip_core/types) or next to a[whip]folder; edit the path for any other layout.
Calling whip_core#
| Where the call is | Call | Why |
|---|---|---|
Inside a handler whip_core runs: SecureEvent, SecureCallback, a use handler, a right-click action, a hook | exports.whip_core:Name(…) | whip_core is up while it runs, and a payment and what it pays for are written together |
Your own code: Whip.register, a thread, a command, a timer, an NUI callback, your own net event, a key press | Whip.core:Name(…) | whip_core may not be ready yet (early in a start, or while a player's game loads); this returns false, why where a direct call would throw. In Whip.register, a refused declaration is printed |
| Code that runs every frame | exports.whip_core:Name(…) behind Whip.isReady(), quick exports only | Whip.core checks whip_core and guards every call, and an export that waits (WAITS) gets a thread of its own: too much at 60 a second |
A card marked WAITS can wait on the database or the player. Call it from a thread or handler, and afterwards re-read anything that may have changed meanwhile. Never call it at file scope or inside a table.sort or gsub function: Lua can't pause there, and on FiveM's Enhanced server such a call can crash the server. Whip.core and Whip.call start it in a thread of its own there, and answer that it started. Your editor shows these as async.