Interfaces: menus, inputs and NUI · Lesson 1/3 · 9 min
Menus and forms with qb-menu and qb-input
The fastest way to have menus in QBCore without writing HTML: qb-menu for lists and qb-input for forms.
Before building your own NUI, QBCore gives you two ready-made resources: qb-menu (option menus) and qb-input (forms). For 80% of cases this is enough.
A menu with qb-menu
-- client.lua
exports['qb-menu']:openMenu({
{ header = 'Mechanic workshop', isMenuHeader = true },
{
header = 'Repair vehicle',
txt = 'Costs $500',
params = { event = 'mecanico:client:reparar' },
},
{
header = 'Close',
params = { event = 'qb-menu:client:closeMenu' },
},
})qb-menu
A form with qb-input
local dialog = exports['qb-input']:ShowInput({
header = 'Transfer money',
submitText = 'Send',
inputs = {
{ type = 'number', name = 'cantidad', text = 'Amount', isRequired = true },
},
})
if dialog and dialog.cantidad then
local cantidad = tonumber(dialog.cantidad)
TriggerServerEvent('banco:server:transferir', cantidad)
endqb-input
The menu and the input are ONLY interface. What the player chooses is sent to the server via an event, and the server validates and executes. Never trust what comes back from the input.
Practice what you learned
0/3¿Qué te resuelven qb-menu y qb-input sin tener que escribir HTML?
Completa el export que abre un menú de qb-menu con una cabecera.
exports['qb-menu']:({ { header = 'Tienda', isMenuHeader = true }, { header = 'Comprar', txt = '', params = { event = 'mi:evento', args = { item = 'water' } } },})Pista
Es el método que recibe el array de opciones del menú.
Este qb-input no devuelve nada al alumno. Falta guardar lo que devuelve ShowInput en una variable para poder leer la cantidad.
Este código tiene un fallo:
exports['qb-input']:ShowInput({ header = 'Cantidad', submitText = 'OK', inputs = { { name = 'cantidad', type = 'number', text = '¿Cuántos?' } },})print(dialog.cantidad)Reescríbelo corregido:
Pista
ShowInput DEVUELVE una tabla con los valores; tienes que capturarla con 'local dialog = ...'.
Challenge: code it yourself
Make a qb-menu with two options (Deposit, Withdraw) that fire their respective client events.
Write it yourself in your editor (VS Code) and test it on your server. You learn here by doing it, not by copying.
See hint
exports['qb-menu']:openMenu with an array of { header, params = { event = '...' } }.
Escribe aquí tu solución:
