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

Controller support

A player on a gamepad gets most of WHIP without you writing anything for it. Beyond that, you can put an action on a button, drive your own screen with the pad, and give a mode WHIP's confirm and cancel.

What you get free

LB is WHIP's combo key. LB + A talks, LB + X is the radio, and players can put other actions on LB + a button. Everything here leaves those presses to WHIP.

An action on a button

FiveM's pad key bindings never fire, so put your action on WHIP's buttons: it shows on the pause menu's Controller screen, players can move it, and WHIP reads the button. The phone, talk, the radio and nitrous work this way.

RegisterPadAction(id, def) / RemovePadAction(id)CLIENT#

Puts your action on the button it asks for, if that button is free in WHIP's default (or a player's layout never set it). Registering again replaces it; it goes when your resource stops.

ParamTypeDescription
idstringA letter, then letters, digits, _; up to 32. Layouts save it by this
def.labelstringIts name on the Controller screen, up to 32 characters
def.commandstring?A key command ('+my_action'; its - half runs on release). This or onPress
def.onPress / def.onReleasefunction?On button down and (optionally) up. Must not wait
def.slotstring?dpad_up, dpad_down, dpad_left, dpad_right, l3, veh_a (A in a vehicle), foot_b (B on foot), lb_a, lb_b, lb_x, lb_y, lb_dpad_up ... lb_dpad_right. None: players place it
def.wherestring?'car' or 'foot'. A ready 'car' action shows over the dial, so keep it not ready where it does nothing
def.menusboolean?true: works with a screen open (talk). Otherwise it waits for IsGameInputFree
def.readyboolean?Default true; see SetPadActionReady
Returns: boolean ok, string? why: a bad field (named), one of WHIP's ids, or an id another resource holds
Whip.register(function()
    Whip.core:RegisterPadAction('mycafe_menu', { label = 'Cafe menu', command = 'mycafe_menu', slot = 'lb_y' })
end)

Config.Controller.Layout holds WHIP's own (D-pad up phone, LB + A talk, LB + B Gunny ammo check, LB + X radio, A in a vehicle nitrous, B on foot Gunny reload), so LB + Y and LB + D-pad are yours. A taken slot leaves the action registered on no button, and F8 says once what has it. Two resources asking for one free button: the id first alphabetically wins.

SetPadActionReady(id, ready)CLIENT#

While your action isn't ready it keeps its button, but presses reach GTA: nitrous is ready only with a bottle, so a motorbike keeps A for ducking.

Returns: boolean ok, string? why (not your id)
exports.whip_core:SetPadActionReady('nitrous', true)
GetPadActionButton(id)CLIENT#

Which button any action is on in this player's layout (yours, another resource's, or WHIP's 'radial', 'inventory', 'engine', 'sprint'). Ask each time you show a hint.

Returns: slot ('lb_y'), pictures for ShowText ('{pad:lb}{pad:y}'), name ('LB+Y'); nil on no button or no such action
local slot, pictures = Whip.core:GetPadActionButton('mycafe_menu')
if type(slot) == 'string' then exports.whip_core:ShowText(pictures .. ' Cafe menu') end

A pad on your own screen

The browser can't read a gamepad in FiveM. Whip.padScreen (in @whip_core/lib/satellite.lua) reads it while your screen is open, sends presses to your page, owns your NUI focus (no cursor while a pad drives) and holds the pad's world actions off.

Whip.padScreen(def?)CLIENT#

Make one at file scope; screen:open() when your screen opens, screen:close() on every close. Your page gets { action = 'pad', cmd, down, rep } per press (rep: a held D-pad's repeats) and { action = 'padDevice', pad } when the player swaps devices.

FieldTypeDescription
buttonsstring[]?Default up, down, left, right, a, b, x, y; also lb (on release without a combo), rb, menu
stickboolean?false: the left stick doesn't step like the D-pad
releasestable?{ a = true }: also send down = false on release
keepInputstring?'always': the game keeps its input with the mouse too (an orbit camera). Default 'pad'
blocktable|false?Held off while a pad drives, in BlockControls form. Default: walking, looking, fighting, wheels, jump, getting in, cover, reload, Start / Esc
onButton / onDevicefunction?(cmd, down, rep) and (pad), instead of the messages
onFramefunction?Every frame a pad drives, for a stick of your own
Returns: the screen: :open() (returns whether a pad is in use), :close(), :typing(on) (your text field has the keyboard), :pause(on) (another screen of yours has the pad), :isPad()
local screen = Whip.padScreen()
SendNUIMessage({ action = 'open', pad = screen:open() })   -- on open
screen:close()                                             -- on every close
OpenKeyboard(opts?)CLIENTWAITS#

WHIP's on-screen keyboard for a pad player; open it only on a pad (IsControllerActive). It opens over any page and waits, so call it from a thread. It suggests word endings in the player's language (Config.Keyboard), learning their words. While it's up the pad is its alone: your own pad reader waits between whip_core:keyboard:opened and whip_core:keyboard:closed.

ParamTypeDescription
opts.titlestring?Shown over the keys: 'Search'
opts.valuestring?Starting text
opts.placeholderstring?Ghost text
opts.numericboolean?A number pad (digits, minus, point)
opts.maxLengthinteger?Character limit
opts.predictboolean?false: no suggestions, nothing learned (a plate, a code)
Returns: string, or nil when left (B) or replaced by another keyboard
local text = Whip.core:OpenKeyboard({ title = 'Search', value = current, maxLength = 40 })

A mode's confirm and cancel

A mode of your own (placing, aiming, a minigame) confirms with Interact (E, or wherever the player moved it) and cancels with C; on a pad, A and B, never with LB.

IsAcceptPressed() / IsAcceptHeld() / IsCancelPressed() · AcceptHint() / CancelHint()CLIENT#

Read the first three every frame; they follow whichever device is in use and read through a block. The hints return '[E]' / '[C]' or '{pad:a}' / '{pad:b}'. Hold a BlockControls block with mode = true, naming what the keys also do in GTA: C look behind (26), B reload and melee (45, 140).

Returns: boolean for the readers, string for the hints
exports.whip_core:BlockControls('placing', { controls = { 26, 45, 140 }, mode = true })
while placing do
    if exports.whip_core:IsAcceptPressed() then place() end
    if exports.whip_core:IsCancelPressed() then placing = false end
    Wait(0)
end
IsKeyPressed(key, button) / IsKeyHeld(key, button) · KeyHint(keyText, button)CLIENT#

Any other key, by the same rules: key on a keyboard, button on a pad, never both, never with LB. Either may be nil. GTA control numbers; a pad's are frontend ones: 201 A, 202 B, 203 X, 204 Y, 206 RB, 199 Start, D-pad 187-190, never LB (205). KeyHint takes a key name and a picture name, or a list of them.

Returns: boolean; KeyHint: '[Space]', '{pad:x}' or ''
if exports.whip_core:IsKeyPressed(22, 203) then flip() end   -- Space, or X
local hint = exports.whip_core:KeyHint('Scroll', { 'lt', 'rt' }) .. ' Turn'

Reading the pad yourself

IsControllerActive()CLIENT#

Is the player on a gamepad? Use it to pick hint pictures, not to change controls. Ask once, then listen for whip_core:pad:deviceChanged ({ pad }).

Returns: boolean
AddEventHandler('whip_core:pad:deviceChanged', function(e) onPad = e.pad == true end)

A pad screen of your own: Whip.padScreen leaves a press with LB held to WHIP's combos for you.