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
- Prompts (
AddAction): A uses the one in view; D-pad up and down step its options. - The F1 wheel: holding D-pad down opens it.
- Bars and dialogs:
Progress,Input,Confirm,SkillCheckand WHIP's panels read the pad themselves. - Typing:
OpenKeyboard, an on-screen keyboard. - Hints:
{pad:a}inShowTextdraws the A button. Alsob,x,y,lb,rb,lt,rt,ls,rs,l3,r3,dpad,dpad_up...dpad_right,view,menu; as images athttps://cfx-nui-whip_core/html/img/pad/a.svg.
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.
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.
| Param | Type | Description |
|---|---|---|
| id | string | A letter, then letters, digits, _; up to 32. Layouts save it by this |
| def.label | string | Its name on the Controller screen, up to 32 characters |
| def.command | string? | A key command ('+my_action'; its - half runs on release). This or onPress |
| def.onPress / def.onRelease | function? | On button down and (optionally) up. Must not wait |
| def.slot | string? | 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.where | string? | 'car' or 'foot'. A ready 'car' action shows over the dial, so keep it not ready where it does nothing |
| def.menus | boolean? | true: works with a screen open (talk). Otherwise it waits for IsGameInputFree |
| def.ready | boolean? | Default true; see SetPadActionReady |
boolean ok, string? why: a bad field (named), one of WHIP's ids, or an id another resource holdsWhip.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.
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.
boolean ok, string? why (not your id)exports.whip_core:SetPadActionReady('nitrous', true)
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.
'lb_y'), pictures for ShowText ('{pad:lb}{pad:y}'), name ('LB+Y'); nil on no button or no such actionlocal 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.
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.
| Field | Type | Description |
|---|---|---|
| buttons | string[]? | Default up, down, left, right, a, b, x, y; also lb (on release without a combo), rb, menu |
| stick | boolean? | false: the left stick doesn't step like the D-pad |
| releases | table? | { a = true }: also send down = false on release |
| keepInput | string? | 'always': the game keeps its input with the mouse too (an orbit camera). Default 'pad' |
| block | table|false? | Held off while a pad drives, in BlockControls form. Default: walking, looking, fighting, wheels, jump, getting in, cover, reload, Start / Esc |
| onButton / onDevice | function? | (cmd, down, rep) and (pad), instead of the messages |
| onFrame | function? | Every frame a pad drives, for a stick of your own |
: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
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.
| Param | Type | Description |
|---|---|---|
| opts.title | string? | Shown over the keys: 'Search' |
| opts.value | string? | Starting text |
| opts.placeholder | string? | Ghost text |
| opts.numeric | boolean? | A number pad (digits, minus, point) |
| opts.maxLength | integer? | Character limit |
| opts.predict | boolean? | false: no suggestions, nothing learned (a plate, a code) |
string, or nil when left (B) or replaced by another keyboardlocal 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.
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).
boolean for the readers, string for the hintsexports.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
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.
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
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 }).
booleanAddEventHandler('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.