mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-01 14:38:50 +00:00
wip js/ts examples
This commit is contained in:
1 parent
3aee4976c3
commit
d44c42104e
7 files changed
+602
-163
No files matched your search
+85
-10
@@ -1,44 +1,119 @@
|
||||
Wrapper around the built-in ACL system. Handles lib.addCommand and ox_groups permissions.
|
||||
Refer to [Basic Aces & Principals overview/guide](https://forum.cfx.re/t/basic-aces-principals-overview-guide/90917) for more information.
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
|
||||
### lib.addAce
|
||||
Assigns the ace permission to a principal. Third parameter defaults to 'allow', while false sets the permission to 'deny'.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- principal: string
|
||||
-- ace: string
|
||||
-- allow: boolean
|
||||
lib.addAce(principal, ace, allow)
|
||||
|
||||
lib.addAce('group.admin', 'command.say')
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/server'
|
||||
|
||||
lib.addAce(principal, ace, allow)
|
||||
|
||||
lib.addAce('group.admin', 'command.say')
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* principal: `string`
|
||||
* ace: `string`
|
||||
* allow: `boolean`
|
||||
|
||||
### lib.removeAce
|
||||
Removes the ace permission from a principal. Third parameter defaults to 'allow', while false sets the permission to 'deny'.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
|
||||
```lua
|
||||
-- principal: string
|
||||
-- ace: string
|
||||
-- allow: boolean
|
||||
lib.removeAce(principal, ace, allow)
|
||||
|
||||
lib.removeAce('group.admin', 'command.say')
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/server'
|
||||
|
||||
lib.removeAce(principal, ace, allow)
|
||||
|
||||
lib.removeAce('group.admin', 'command.say')
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* principal: `string`
|
||||
* ace: `string`
|
||||
* allow: `boolean`
|
||||
|
||||
### lib.addPrincipal
|
||||
Assigns a principal to a parent principal. Children inherit permissions from the parent.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- child: string
|
||||
-- parent: string
|
||||
lib.addPrincipal(child, parent)
|
||||
|
||||
lib.addPrincipal('player.1', 'group.moderator')
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='js/ts'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/server'
|
||||
|
||||
lib.addPrincipal(child, parent)
|
||||
|
||||
lib.addPrincipal('player.1', 'group.moderator')
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* child: `string`
|
||||
* parent: `string`
|
||||
|
||||
|
||||
### lib.removePrincipal
|
||||
Removes a principal from a parent principal.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- child: string
|
||||
-- parent: string
|
||||
lib.removePrincipal(child, parent)
|
||||
|
||||
lib.removePrincipal('player.1', 'group.moderator')
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/server'
|
||||
|
||||
lib.removePrincipal(child, parent)
|
||||
|
||||
lib.removePrincipal('player.1', 'group.moderator')
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* child: `string`
|
||||
* parent: `string`
|
||||
|
||||
@@ -2,23 +2,38 @@
|
||||
title: Alert Dialog
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
Simple alert dialog that can display a message to the player.
|
||||
Returns whether the player pressed the confirm button or canceled the dialog.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- data: table
|
||||
-- header: string
|
||||
-- content: string
|
||||
-- centered: boolean (optional)
|
||||
-- cancel: boolean (optional)
|
||||
lib.alertDialog(data)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.alertDialog(data)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
`header` - Dialog title.
|
||||
`content` - Dialog body content, supports markdown.
|
||||
`centered` - Centers the dialog vertically and horizontally.
|
||||
`cancel` - Displays a cancel button (ESC is still available if this is not defined).
|
||||
* data: `table` (`object`)
|
||||
* header: `string`
|
||||
* Dialog title.
|
||||
* content: `string`
|
||||
* Dialog body content, supports markdown.
|
||||
* centered?: `boolean`
|
||||
* Centers the dialog vertically and horizontally.
|
||||
* cancel?: `boolean`
|
||||
* Displays a cancel button (ESC is still available if this is not defined).
|
||||
|
||||
Returns `confirm` if the player pressed the confirm button, otherwise if the player pressed the cancel button
|
||||
or has exited the dialog with ESC the return will be `cancel`.
|
||||
@@ -36,4 +51,4 @@ local alert = lib.alertDialog({
|
||||
print(alert)
|
||||
```
|
||||
|
||||

|
||||

|
||||
@@ -2,12 +2,28 @@
|
||||
title: Clipboard
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
### lib.setClipboard
|
||||
|
||||
Sets the player's clipboard to the specified string value.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- value: string
|
||||
lib.setClipboard(value)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.setClipboard(value)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* value: `string`
|
||||
@@ -8,52 +8,59 @@ import TabItem from '@theme/TabItem';
|
||||
### lib.registerContext
|
||||
Used for registering a context menu.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- id: string
|
||||
-- title: string
|
||||
-- menu: string (optional)
|
||||
-- onExit: function (optional)
|
||||
-- options: table
|
||||
-- item: key as string or table
|
||||
-- title: string (optional - if item isn't key)
|
||||
-- menu: string (optional)
|
||||
-- icon: string (optional)
|
||||
-- iconColor: string (optional)
|
||||
-- arrow: boolean (optional)
|
||||
-- description: string (optional)
|
||||
-- metadata: string table or key, value table or table (optional)
|
||||
-- event: string (optional)
|
||||
-- serverEvent: string (optional)
|
||||
-- args: any (optional)
|
||||
lib.registerContext(context)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.registerContext(context)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* id: `string`
|
||||
* Unique menu identifier, will be used to open the menu.
|
||||
* title: `string`
|
||||
* Title display in the menu.
|
||||
* menu?: `string`
|
||||
* Menu identifier - if defined there will be a back arrow next to the menu title that will take you to the menu you defined.
|
||||
* onExit?: `function`
|
||||
* Function that will be ran when the user closes their context menu with ESC.
|
||||
* options: `table` (`object` or `array`)
|
||||
* item: `key` (`string`) or `table` (`object`)
|
||||
* title?: `string`
|
||||
* If not using keys then sets the title for the button.
|
||||
* menu?: `string`
|
||||
* Menu identifier that the button will take you to, when defined an arrow.
|
||||
* onSelect: `function`
|
||||
* Function that's ran when the button is clicked.
|
||||
* icon?: `string`
|
||||
* FontAwesome icon that will be displayed on the left side, works the same as notification and textui icons.
|
||||
* iconColor?: `string`
|
||||
* Colour of the displayed icon.
|
||||
* arrow?: `boolean`
|
||||
* Shows an arrow on the right side like `menu` does, useful when you are opening a menu from an event. Can be set to false to hide it.
|
||||
* description?: `string`
|
||||
* Description that will appear under the button title that is defined as a key.
|
||||
* metadata?: `string[]` or `object` or `array`
|
||||
* Information that will display on the side upon hovering a button.
|
||||
* event?: `string`
|
||||
* Event that the button is going to trigger.
|
||||
* serverEvent?: `string`
|
||||
* Server event that the button is going to trigger.
|
||||
* args?: `any`
|
||||
* Arguments that will be sent to the events or onSelect function.
|
||||
|
||||
You can register as many context menus in one `lib.registerContext` function
|
||||
as you'd like.
|
||||
|
||||
`id` - Unique menu identifier, will be used to open the menu.
|
||||
`title` - Every menu must have a title.
|
||||
`menu` - Menu identifier - if defined there will be a back arrow next to the menu title
|
||||
that will take you to the menu you defined.
|
||||
`onExit` - Function that will be ran when the user closes their context menu with ESC.
|
||||
`options` - Contains all the clickable menu items.
|
||||
`item` - Defined as a key, can be empty if you don't want it to do anything.
|
||||
`item/title` - If not using keys then sets the title for the button.
|
||||
`item/onSelect` - Function that triggers when a button is pressed, returns it's args.
|
||||
`item/image` - Image url, puts the image at the top of the metadata popover.
|
||||
`item/icon` - FontAwesome icon that will be displayed on the left side, works the same as notification and textui icons.
|
||||
`item/iconColor` - Color of the displayed icon.
|
||||
`item/menu` - Menu identifier that the button will take you to, when defined an arrow
|
||||
pointing to the right to indicate a menu will be shown.
|
||||
`item/arrow` - Shows an arrow on the right side like `menu` does, useful when you are
|
||||
opening a menu from an event.
|
||||
`item/description` - Description that will appear under the button title that is defined
|
||||
as a key.
|
||||
`item/metadata` - Information that will display on the side upon hovering a button.
|
||||
`item/event` - Event that the button is going to trigger.
|
||||
`item/serverEvent` - Server event that the button is going to trigger.
|
||||
`args` - Arguments that will be sent to the events.
|
||||
|
||||
The menu can be either in the order you write it in, or sorted alphabetically.
|
||||
To sort the menu alphabetically the buttons (and/or metadata) need to be defined as keys,
|
||||
otherwise not using keys and instead using tables will make the menu be in the order you
|
||||
@@ -62,33 +69,70 @@ define it as.
|
||||
### lib.showContext
|
||||
Opens a registered context menu by it's id.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- id: string
|
||||
lib.showContext(id)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.showContext(id)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* id: `string`
|
||||
|
||||
### lib.hideContext
|
||||
Hides any currently visible context menu.
|
||||
|
||||
`onExit` param defines whether the onExit function for the
|
||||
menu should be ran or not.
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
|
||||
-- onExit: boolean
|
||||
lib.hideContext(onExit)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.hideContext(onExit)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* onExit: `boolean`
|
||||
* Defines whether the onExit function for the menu should be ran or not.
|
||||
|
||||
### lib.getOpenContextMenu
|
||||
|
||||
Returns the id of the currently open context menu.
|
||||
|
||||
If not context menu is open returns `nil`.
|
||||
If no context menu is open returns `nil`.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
lib.getOpenContextMenu()
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.getOpenContextMenu()
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### Usage Example
|
||||
First we register the menu with our specified options then we call the show function in the command.
|
||||
@@ -98,7 +142,7 @@ Avoid constantly re-registering a menu that does not depend on any outside value
|
||||
:::
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='custom' label='Custom order'>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
lib.registerContext({
|
||||
@@ -144,59 +188,81 @@ lib.registerContext({
|
||||
}
|
||||
})
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='ordered' label='Alphabetically ordered'>
|
||||
|
||||
```lua
|
||||
lib.registerContext({
|
||||
id = 'example_menu',
|
||||
title = 'Example Context',
|
||||
onExit = function()
|
||||
print('Hello there')
|
||||
end,
|
||||
options = {
|
||||
['Empty button'] = {},
|
||||
['Example button'] = {
|
||||
description = 'Example button description',
|
||||
metadata = {
|
||||
['Value 1'] = 'Some value',
|
||||
['Value 2'] = 300
|
||||
}
|
||||
},
|
||||
['Menu button'] = {
|
||||
menu = 'other_example_menu',
|
||||
description = 'Takes you to another menu',
|
||||
metadata = {'It also has metadata support'}
|
||||
},
|
||||
['Event button'] = {
|
||||
description = 'Open a menu and send event data',
|
||||
arrow = true,
|
||||
event = 'some_event',
|
||||
args = {value1 = 300, value2 = 'Other value'}
|
||||
}
|
||||
RegisterCommand('testcontext', function()
|
||||
lib.showContext('example_menu')
|
||||
end)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
```
|
||||
|
||||
```ts
|
||||
lib.registerContext([
|
||||
{
|
||||
id: 'example_menu',
|
||||
title: 'Example Context',
|
||||
onExit: () => {
|
||||
console.log('Hello there');
|
||||
},
|
||||
{
|
||||
id = 'other_example_menu',
|
||||
title = 'Other Context Menu',
|
||||
menu = 'example_menu',
|
||||
options = {
|
||||
['Nothing here'] = {}
|
||||
}
|
||||
}
|
||||
})
|
||||
options: [
|
||||
{ title: 'Empty button' },
|
||||
{
|
||||
title: 'Example button',
|
||||
description: 'Example button description',
|
||||
onSelect: (args) => {
|
||||
console.log('Pressed the button!');
|
||||
},
|
||||
metadata: [
|
||||
{ label: 'Value 1', value: 'Some value' },
|
||||
{ label: 'Value 2', value: 300 },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Menu button',
|
||||
menu: 'other_example_menu',
|
||||
description: 'Takes you to another menu!',
|
||||
metadata: ['It also has metadata support'],
|
||||
},
|
||||
{
|
||||
title: 'Event button',
|
||||
description: 'Open a menu and send event data',
|
||||
arrow: true,
|
||||
event: 'some_event',
|
||||
args: { value1: 300, value2: 'Other value' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'other_example_menu',
|
||||
title: 'Other Context Menu',
|
||||
menu: 'example_menu',
|
||||
options: {
|
||||
['Nothing here']: {},
|
||||
},
|
||||
},
|
||||
]);
|
||||
```
|
||||
|
||||
```ts
|
||||
RegisterCommand('testcontext', () => {
|
||||
lib.showContext('example_menu')
|
||||
}, false)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
```lua
|
||||
RegisterCommand('testcontext', function()
|
||||
lib.showContext('example_menu')
|
||||
end)
|
||||
```
|
||||
|
||||
To trigger the event from the `Event button` and get it's data we first
|
||||
need to register the event properly:
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
RegisterNetEvent('some_event', function(data)
|
||||
print(json.encode(data, {indent=true}))
|
||||
@@ -217,6 +283,32 @@ RegisterNetEvent('some_event', function(data)
|
||||
lib.showContext('another_context_menu')
|
||||
end)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
onNet('some_event', () => {
|
||||
console.log(JSON.stringify(data, null, 2))
|
||||
lib.registerContext({
|
||||
id: 'another_context_menu',
|
||||
title: 'Event Menu',
|
||||
menu: 'example_menu',
|
||||
options: {
|
||||
['Menu data']: {
|
||||
description: 'Data from the previous menu',
|
||||
metadata: {
|
||||
['Value1']: data.value1,
|
||||
['Value2']: data.value2,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
lib.showContext('another_context_menu');
|
||||
});
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
The data from the `args` table in the menu is passed as a first argument to
|
||||
the event you register, in this case that argument is called `data`.
|
||||
|
||||
|
||||
@@ -10,34 +10,57 @@ by setting input fields.
|
||||
|
||||
### lib.inputDialog
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- heading: string
|
||||
-- rows: strings array or table
|
||||
-- type: "input" or "number" or "checkbox" or "select" or "slider"
|
||||
-- label: string
|
||||
-- options: table array (optional - used ONLY with "select" type)
|
||||
-- value: string
|
||||
-- label: string
|
||||
-- default: string (optional - any of the values)
|
||||
-- password: boolean (optional - used ONLY with "input" type)
|
||||
-- icon: string (optional - used ONLY with "input" type)
|
||||
-- placeholder: string (optional - used ONLY with "input" or "number" type)
|
||||
-- default: string or number (optional)
|
||||
-- checked: boolean (optional - used ONLY with "checkbox" type)
|
||||
-- min: number (optional - used ONLY with "slider" type)
|
||||
-- max: number (optional - used ONLY with "slider" type)
|
||||
-- step: number (optional - used ONLY with "slider" type)
|
||||
lib.inputDialog(heading, rows)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.inputDialog(heading, rows)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* heading: `string`
|
||||
* rows: `string[]` or `table` (`array`)
|
||||
* type: `'input'` or `'number'` or `'checkbox'` or `'select'` or `'slider'`
|
||||
* label: `string`
|
||||
* options?: `table` (`array`)
|
||||
* [ Only used with `'select'` type ]
|
||||
* value: `string`
|
||||
* label: `string`
|
||||
* default?: `string`
|
||||
* password?: `boolean`
|
||||
* Hides input characters with ability to toggle them on. Used only with `'input'` type.
|
||||
* icon?: `string`
|
||||
* Used only with `'input'` and `'number'` types.
|
||||
* placeholder?: `string`
|
||||
* Used only with `'input'` and `'number'` types.
|
||||
* default?: `string` or `number`
|
||||
* Default value for the field.
|
||||
* checked?: `boolean`
|
||||
* Whether the checkbox should be checked by default. Used only with `'checkbox'` type.
|
||||
* min?: `number`
|
||||
* Used only with `'slider'` and `'number'` types.
|
||||
* max?: `number`
|
||||
* Used only with `'slider'` and `'number'` types.
|
||||
* step?: `number`
|
||||
* Amount of change per slider step. Used only with `'slider'` type.
|
||||
|
||||
The callback data is promise based meaning that the thread will
|
||||
not continue executing until the user either sends the data
|
||||
or exits the popup.
|
||||
|
||||
The data returned will be a table, indexes represent the rows
|
||||
The data returned will be a table (array), indexes represent the rows
|
||||
sent to the dialog, so if we want data from the first field that
|
||||
would be index `1`, if we want data from the third field, that would
|
||||
be index `3`, etc...
|
||||
would be index `1` (`0`), if we want data from the third field, that would
|
||||
be index `3` (`2`), etc...
|
||||
|
||||
The standard input rows will always return a string, if you want a row to be of
|
||||
number data type, you can use set the `type` to `number`.
|
||||
@@ -49,31 +72,56 @@ Look at the *Advanced* example for it's usage.
|
||||
|
||||
:::caution
|
||||
|
||||
When using the advanced method you can define `icon` and `password` **ONLY** with type `"input"` and
|
||||
you can define `options` **ONLY** with type `"select"`.
|
||||
When using the advanced method you can define `icon` and `password` **ONLY** with type `'input'` and `'number'` and
|
||||
you can define `options` **ONLY** with type `'select'`.
|
||||
|
||||
|
||||
Doing so otherwise ***will*** result in errors.
|
||||
:::
|
||||
|
||||
**Example:**
|
||||
## Usage Example
|
||||
|
||||
### Basic
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="basic" label="Basic">
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
local input = lib.inputDialog('Police locker', {'Locker number', 'Locker passcode'})
|
||||
|
||||
if input then
|
||||
local lockerNumber = tonumber(input[1])
|
||||
local lockerPasscode = input[2]
|
||||
if not input then return end
|
||||
local lockerNumber = tonumber(input[1])
|
||||
local lockerPasscode = input[2]
|
||||
|
||||
print(lockerNumber, lockerPasscode)
|
||||
end
|
||||
print(lockerNumber, lockerPasscode)
|
||||
```
|
||||

|
||||
</TabItem>
|
||||
<TabItem value='advanced' label='Advanced'>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
:::caution
|
||||
|
||||
This function is **asynchronous** requiring you to do a `.then` callback on the promise or make your function `async`.
|
||||
:::
|
||||
|
||||
|
||||
```ts
|
||||
const input = await lib.inputDialog('Police locker', ['Locker number', 'Locker passcode'])
|
||||
|
||||
if (!input) return
|
||||
const lockerNumber = input[0] as number
|
||||
const lockerPasscode = input[1] as number
|
||||
|
||||
console.log(lockerNumber, lockerPasscode)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||

|
||||
|
||||
### Advanced
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="Lua">
|
||||
|
||||
```lua
|
||||
local input = lib.inputDialog('Police locker', {
|
||||
@@ -90,6 +138,31 @@ local input = lib.inputDialog('Police locker', {
|
||||
})
|
||||
print(json.encode(input, {indent=true}))
|
||||
```
|
||||
 
|
||||
</TabItem>
|
||||
<TabItem value="JS/TS">
|
||||
|
||||
:::caution
|
||||
|
||||
This function is **asynchronous** requiring you to do a `.then` callback on the promise or make your function `async`.
|
||||
:::
|
||||
|
||||
```ts
|
||||
const input = await lib.inputDialog('Police locker', [
|
||||
{ type: 'input', label: 'Locker number', placeholder: '123' },
|
||||
{ type: 'checkbox', label: 'Some checkbox' },
|
||||
{ type: 'input', label: 'Locker PIN', password: true, icon: 'lock' },
|
||||
{ type: 'checkbox', label: 'Some other checkbox', checked: true },
|
||||
{ type: 'select', label: 'Value select', options: [
|
||||
{ value: 'option1', label: 'Option 1' },
|
||||
{ value: 'option2', label: 'Option 2' },
|
||||
{ value: 'option3', label: 'Option 3' },
|
||||
]},
|
||||
{ type: 'number', label: 'Number counter', default: 12 },
|
||||
]);
|
||||
|
||||
console.log(JSON.stringify(input, null, 2));
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
 
|
||||
@@ -2,72 +2,169 @@
|
||||
title: Menu
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
Keyboard navigation menu with specific event functions.
|
||||
|
||||
### lib.registerMenu
|
||||
Registers and caches a menu under the specified id.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- data: table
|
||||
-- id: string
|
||||
-- title: string
|
||||
-- options: table
|
||||
-- label: string
|
||||
-- icon: string (optinal)
|
||||
-- values: table of strings (optional - if provided creates a side scrollable list)
|
||||
-- description?: string (optional)
|
||||
-- defaultIndex: number (optional - sets the current index for the list to specified number)
|
||||
-- args: any (optional)
|
||||
-- position: 'top-left' or 'top-right' or 'bottom-left' or 'bottom-right' (optional - default is top-left)
|
||||
-- disableInput: boolean (optional - default false)
|
||||
-- onClose: function (optional)
|
||||
-- onSelected: function (optional - triggers every time a new button is selected)
|
||||
-- onSideScroll: function (optional - triggers every time a side list is scrolled)
|
||||
-- cb: function
|
||||
lib.registerMenu(data, cb)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.registerMenu(data, cb)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* data: `table` (`object`)
|
||||
* id: `string`
|
||||
* title: `string`
|
||||
* options: `table` (`array`)
|
||||
* label: `string`
|
||||
* icon?: `string`
|
||||
* values?: `table` (`string[]`)
|
||||
* If provided creates a side scrollabel list.
|
||||
* description?: `string`
|
||||
* Displays tooltip below menu on hovered item with provided description.
|
||||
* defaultIndex?: `number`
|
||||
* Sets the current index for the list to specified number.
|
||||
* args?: `any`
|
||||
* position?: `'top-left'` or `'top-right'` or `'bottom-left'` or `'bottom-right'`
|
||||
* Default: `'top-left'`
|
||||
* disableInput?: `boolean`
|
||||
* Default: `false`
|
||||
* onClose: `function`
|
||||
* Function that runs when the menu is exited via ESC/Backspace.
|
||||
* onSelected: `function`(selected: `number`: scrollIndex: `number`: args: `any`)
|
||||
* Function being ran when the selected button in the menu changes.
|
||||
* onSideScroll: `function`(selected: `number`: scrollIndex: `number`: args: `any`)
|
||||
* Function ran whenever a scroll list item is changed.
|
||||
* cb: `function`(selected: `number`: scrollIndex: `number`: args: `any`)
|
||||
* Callback function when the menu item is pressed.
|
||||
|
||||
### lib.showMenu
|
||||
Displays the menu with the provided id.
|
||||
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- id: string
|
||||
lib.showMenu(id)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.showMenu(id)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* id: `string`
|
||||
|
||||
|
||||
|
||||
### lib.hideMenu
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- onExit: boolean (optional - if true runs the menu's onClose function)
|
||||
lib.hideMenu(onExit)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.hideMenu(onExit)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* onExit?: `boolean`
|
||||
* If true runs the menu's `onClose` function.
|
||||
|
||||
### lib.getOpenMenu
|
||||
Returns the id of the currently open menu.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
lib.getOpenMenu()
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.getOpenMenu()
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
||||
### lib.setMenuOptions
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
-- id: string
|
||||
-- options: table
|
||||
-- index: number (optional - if specified only sets the options table on the specified options index)
|
||||
lib.setMenuOptions(id, options, index)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.setMenuOptions(id, options, index)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
* id: `string`
|
||||
* options: `table` (`object` or `array`)
|
||||
* index?: `number`
|
||||
* If specified only sets the options table on the specified options index.
|
||||
|
||||
**Example:**
|
||||
|
||||
```lua
|
||||
-- Replaces the option on 3rd index of specified menu
|
||||
Replaces the 3rd index option of the specified menu
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
lib.setMenuOptions('some_menu_id', {label = 'New option', icon = 'plus'}, 3)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.setMenuOptions('some_menu_id', {label: 'New option', icon: 'plus'}, 3)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### Usage Example
|
||||
First we register the menu with our specified options then we call the show function in the command.
|
||||
@@ -77,6 +174,9 @@ Avoid constantly re-registering a menu that does not depend on any outside value
|
||||
:::
|
||||
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
```lua
|
||||
lib.registerMenu({
|
||||
id = 'some_menu_id',
|
||||
@@ -107,4 +207,42 @@ RegisterCommand('testmenu', function()
|
||||
lib.showMenu('some_menu_id')
|
||||
end)
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
|
||||
lib.registerMenu({
|
||||
id: 'some_menu_id',
|
||||
title: 'Menu title',
|
||||
position: 'top-right',
|
||||
onSideScroll: (selected, scrollIndex, args) => {
|
||||
console.log(selected, scrollIndex, args)
|
||||
},
|
||||
onSelected: (selected, scrollIndex, args) => {
|
||||
console.log(selected, scrollIndex, args)
|
||||
},
|
||||
onClose: () => {
|
||||
console.log('Menu closed')
|
||||
},
|
||||
options: [
|
||||
{label: 'Simple button', description: 'It has a description!'},
|
||||
{label: 'Simple button with icon', icon: 'arrows-up-down-left-right'},
|
||||
{label: 'Button with args', args: 'nice_button'},
|
||||
{label: 'List button', values: ['You', 'can', 'side', 'scroll', 'this'], description: 'It also has a description!'},
|
||||
{label: 'List button with default index', values: ['You', 'can', 'side', 'scroll', 'this'], defaultIndex: 5},
|
||||
{label: 'List button with args', values: ['You', 'can', 'side', 'scroll', 'this'], args: {someValue: 3, otherValue: 'value'}},
|
||||
]
|
||||
}, (selected, scrollIndex, args) => {
|
||||
console.log(selected, scrollIndex, args)
|
||||
})
|
||||
|
||||
RegisterCommand('testmenu', () => {
|
||||
lib.showMenu('some_menu_id')
|
||||
}, false)
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||

|
||||
@@ -3,11 +3,17 @@ title: Getting Started
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
ox_lib is a collection of Lua and UI functions to utilise in other resources.
|
||||
|
||||
The UI is built in React so the code needs to be compiled into standard JS.
|
||||
If you don't know how to do this then please download the [release](https://github.com/overextended/ox_lib/releases/latest) (ox_lib.zip) which is *already* compiled into a working resource.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value='Lua'>
|
||||
|
||||
To enable the library inside of your resource just add `@ox_lib/init.lua` to `shared_scripts` or
|
||||
a `shared_script` in your `fxmanifest.lua` file.
|
||||
|
||||
@@ -22,6 +28,30 @@ Or if the library is the only shared script you use you can do:
|
||||
```lua
|
||||
shared_script '@ox_lib/init.lua'
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value='JS/TS'>
|
||||
|
||||
:::caution
|
||||
Npm package for the lib does **not** support all the functions that are available for Lua.
|
||||
|
||||
All supported functions are located inside the `resource` folder in the lib.
|
||||
:::
|
||||
|
||||
You can get the npm package [here](https://npmjs.com/package/@overextended/ox_library).
|
||||
|
||||
**Usage:**
|
||||
You can either import the whole library object which contains all the functions for that scope (client/server/shared) or
|
||||
you can deconstruct it and import the functions you find needed at the time.
|
||||
|
||||
```ts
|
||||
import lib from '@overextended/ox_lib/client'
|
||||
```
|
||||
|
||||
```ts
|
||||
import { versionCheck } from '@overextended/ox_lib/server'
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
**ACE Permissions:**
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user