API - FiveM-Scripts/fivem-universal-menu GitHub Wiki
API
Notes
-
* - Optional, can be nil (Change to false if arg doesn't use it for functionality instead for now, otherwise nothing might happen, this is a FiveM bug currently)
-
Item/Menu Names cut off at 25 chars by default, limit adjustable by user.
-
The API Reference only applies for the newest version.
API Reference
menu:registerModuleMenu
Adds a new menu to the root.
Accepts:
- name - Name of the menu
- *cbdone - Callback once the menu was created
- *cbclicked - Callback once the menu was opened
Callbacks:
cbdone
- id - Unique ID of the created menu or nil on error or if any of the passed non-optional args are nil
cbclicked
- id - Unique ID of the created menu
menu:addModuleSubMenu
Adds a new sub-menu to a existing menu.
Accepts:
- parent - Menu to add the sub-menu to
- name - Name of the sub-menu
- *cbdone - Callback once the sub-menu was created
- *cbclicked - Callback once the sub-menu was opened
Callbacks:
cbdone
- id - Unique ID of the created menu or nil on error or if any of the passed non-optional args are nil or parent is invalid
cbclicked
- id - Unique ID of the created menu
menu:addModuleItem
Adds a new item to a existing menu.
Accepts:
- *menu- Menu to add the item to (adds to root if nil)
- name - Name of the item
- *onoff - Append ON/OFF switch to the item, either true or false for start state, nil to disable
- *cbdone - Callback once the item was created
- *cbclicked - Callback once the item was selected
Callbacks:
cbdone
- id - Unique ID of the created menu or nil on error or if any of the passed non-optional args are nil or parent is invalid
cbclicked
- id - Unique ID of the created menu
- *datastate - Either
true
if "ON" orfalse
if "OFF" if onoff ~= nil, otherwisenil
(can be left off ifonoff
==nil
)
menu:blockInput
Blocks all input to the trainer.
Accepts:
- state - Block input, either
true
orfalse
menu:isIDRegistered
Checks if an ID is registered.
Accepts:
- id - The id
- cb - Callback
Callbacks:
cb
- result - Either true if registered or false if not
menu:hideMenu
Hides (or rather closes) the menu (if menu is open).
menu:exists
Calls the callback if the menu resource exists, useful for checking.
Accepts:
- cb - Callback
menu:getVersion
Returns the installed menu resource's version as a string arg in the callback
(newest version is 2.4.2
as of 08/07/18
).
Accepts:
- cb - Callback
Callbacks:
cb
- version - Version of the installed menu resource
menu:setDesc
Sets the description of a specific item/menu. Also updates in realtime!
Accepts:
- id - ID of the element
- text - The text (Note: cuts off at 125 chars by default, limit adjustable by user) (v2.4.1 or higher: pass nil to remove description)
menu:setGreyedOut
Makes an item/menu greyed out. Same as above, updates in realtime.
This won't block any input, it's just visual.
As of v2.3.3, greyed out items block input. cbclicked
won't be called on greyed out items either.
Notice the reversed args. That's because making state
the last arg turns false
into nil
for some reason sigh.
Accepts:
- state -
true
for greyed out,false
for not - id - ID of the element
menu:isGreyedOut
Returns to callback if item is greyed out.
Accepts:
- id - ID of the element
- cb - The callback
Callbacks:
cb
- state -
true
for greyed out,false
for not
menu:setRightText
Sets a right text on an item. Does not work with menus or on-off switches! Also again reeeeeeealtime!
Also text length limit is 6 chars by default. It's user-configurable.
Accepts:
- id - ID of the element
- text - The text (
nil
to remove text)
menu:getRightText
Returns to callback the right text of an item to callback
Accepts:
- id - ID of the element
- cb - The callback
Callbacks:
cb
- text - Either the text or
nil
if there's none
menu:isMenuShown
Returns to callback if menu is being shown.
Accepts:
- cb - The callback
Callbacks:
cb
- state - Either
true
if menu is visible orfalse
if not
menu:removeByID
Removes an item/menu by ID.
Note that empty menus will be automatically removed and the user gets thrown to the main menu if that happens.
Since v2.4 menus will go back into "empty" state once they contain no items anymore.
Accepts:
- id - ID of the element
menu:goBackMenu
Goes back a menu (if menu is open). Genius.
menu:goToMainMenu
Goes back to main menu (if menu is open).
menu:setOnOffState
Sets the state of an ON/OFF switch item.
Accepts:
- id - ID of the ON/OFF switch item
- state - Either
true
for "ON" orfalse
for "OFF"
menu:getOnOffState
Gets the state of an ON/OFF switch item.
Accepts:
- id - ID of the ON/OFF switch item
- cb - The callback
Callbacks:
cb
- state - Either
true
if "ON",false
if "OFF" ornil
if item has no ON/OFF switch.