mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 06:28:54 +00:00
wip js/ts examples
This commit is contained in:
1 parent
3aee4976c3
commit
d44c42104e
7 files changed
+601
-162
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.
|
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.
|
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
|
### lib.addAce
|
||||||
Assigns the ace permission to a principal. Third parameter defaults to 'allow', while false sets the permission to 'deny'.
|
Assigns the ace permission to a principal. Third parameter defaults to 'allow', while false sets the permission to 'deny'.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- principal: string
|
|
||||||
-- ace: string
|
|
||||||
-- allow: boolean
|
|
||||||
lib.addAce(principal, ace, allow)
|
lib.addAce(principal, ace, allow)
|
||||||
|
|
||||||
lib.addAce('group.admin', 'command.say')
|
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
|
### lib.removeAce
|
||||||
Removes the ace permission from a principal. Third parameter defaults to 'allow', while false sets the permission to 'deny'.
|
Removes the ace permission from a principal. Third parameter defaults to 'allow', while false sets the permission to 'deny'.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- principal: string
|
|
||||||
-- ace: string
|
|
||||||
-- allow: boolean
|
|
||||||
lib.removeAce(principal, ace, allow)
|
lib.removeAce(principal, ace, allow)
|
||||||
|
|
||||||
lib.removeAce('group.admin', 'command.say')
|
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
|
### lib.addPrincipal
|
||||||
Assigns a principal to a parent principal. Children inherit permissions from the parent.
|
Assigns a principal to a parent principal. Children inherit permissions from the parent.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- child: string
|
|
||||||
-- parent: string
|
|
||||||
lib.addPrincipal(child, parent)
|
lib.addPrincipal(child, parent)
|
||||||
|
|
||||||
lib.addPrincipal('player.1', 'group.moderator')
|
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
|
### lib.removePrincipal
|
||||||
Removes a principal from a parent principal.
|
Removes a principal from a parent principal.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- child: string
|
|
||||||
-- parent: string
|
|
||||||
lib.removePrincipal(child, parent)
|
lib.removePrincipal(child, parent)
|
||||||
|
|
||||||
lib.removePrincipal('player.1', 'group.moderator')
|
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
|
title: Alert Dialog
|
||||||
---
|
---
|
||||||
|
|
||||||
|
import Tabs from '@theme/Tabs';
|
||||||
|
import TabItem from '@theme/TabItem';
|
||||||
|
|
||||||
Simple alert dialog that can display a message to the player.
|
Simple alert dialog that can display a message to the player.
|
||||||
Returns whether the player pressed the confirm button or canceled the dialog.
|
Returns whether the player pressed the confirm button or canceled the dialog.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- data: table
|
lib.alertDialog(data)
|
||||||
-- header: string
|
```
|
||||||
-- content: string
|
</TabItem>
|
||||||
-- centered: boolean (optional)
|
<TabItem value='JS/TS'>
|
||||||
-- cancel: boolean (optional)
|
|
||||||
|
```ts
|
||||||
|
import lib from '@overextended/ox_lib/client'
|
||||||
|
|
||||||
lib.alertDialog(data)
|
lib.alertDialog(data)
|
||||||
```
|
```
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
`header` - Dialog title.
|
* data: `table` (`object`)
|
||||||
`content` - Dialog body content, supports markdown.
|
* header: `string`
|
||||||
`centered` - Centers the dialog vertically and horizontally.
|
* Dialog title.
|
||||||
`cancel` - Displays a cancel button (ESC is still available if this is not defined).
|
* 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
|
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`.
|
or has exited the dialog with ESC the return will be `cancel`.
|
||||||
|
|||||||
@@ -2,12 +2,28 @@
|
|||||||
title: Clipboard
|
title: Clipboard
|
||||||
---
|
---
|
||||||
|
|
||||||
|
import Tabs from '@theme/Tabs';
|
||||||
|
import TabItem from '@theme/TabItem';
|
||||||
|
|
||||||
### lib.setClipboard
|
### lib.setClipboard
|
||||||
|
|
||||||
Sets the player's clipboard to the specified string value.
|
Sets the player's clipboard to the specified string value.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- value: string
|
lib.setClipboard(value)
|
||||||
|
```
|
||||||
|
</TabItem>
|
||||||
|
<TabItem value='JS/TS'>
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import lib from '@overextended/ox_lib/client'
|
||||||
|
|
||||||
lib.setClipboard(value)
|
lib.setClipboard(value)
|
||||||
```
|
```
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
* value: `string`
|
||||||
@@ -8,52 +8,59 @@ import TabItem from '@theme/TabItem';
|
|||||||
### lib.registerContext
|
### lib.registerContext
|
||||||
Used for registering a context menu.
|
Used for registering a context menu.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```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)
|
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
|
You can register as many context menus in one `lib.registerContext` function
|
||||||
as you'd like.
|
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.
|
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,
|
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
|
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
|
### lib.showContext
|
||||||
Opens a registered context menu by it's id.
|
Opens a registered context menu by it's id.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- id: string
|
lib.showContext(id)
|
||||||
|
```
|
||||||
|
</TabItem>
|
||||||
|
<TabItem value='JS/TS'>
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import lib from '@overextended/ox_lib/client'
|
||||||
|
|
||||||
lib.showContext(id)
|
lib.showContext(id)
|
||||||
```
|
```
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
* id: `string`
|
||||||
|
|
||||||
### lib.hideContext
|
### lib.hideContext
|
||||||
Hides any currently visible context menu.
|
Hides any currently visible context menu.
|
||||||
|
|
||||||
`onExit` param defines whether the onExit function for the
|
<Tabs>
|
||||||
menu should be ran or not.
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
|
||||||
-- onExit: boolean
|
|
||||||
lib.hideContext(onExit)
|
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
|
### lib.getOpenContextMenu
|
||||||
|
|
||||||
Returns the id of the currently open context menu.
|
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
|
```lua
|
||||||
lib.getOpenContextMenu()
|
lib.getOpenContextMenu()
|
||||||
```
|
```
|
||||||
|
</TabItem>
|
||||||
|
<TabItem value='JS/TS'>
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import lib from '@overextended/ox_lib/client'
|
||||||
|
|
||||||
|
lib.getOpenContextMenu()
|
||||||
|
```
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
### Usage Example
|
### Usage Example
|
||||||
First we register the menu with our specified options then we call the show function in the command.
|
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>
|
<Tabs>
|
||||||
<TabItem value='custom' label='Custom order'>
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
@@ -144,59 +188,81 @@ lib.registerContext({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
</TabItem>
|
|
||||||
<TabItem value='ordered' label='Alphabetically ordered'>
|
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.registerContext({
|
RegisterCommand('testcontext', function()
|
||||||
id = 'example_menu',
|
lib.showContext('example_menu')
|
||||||
title = 'Example Context',
|
end)
|
||||||
onExit = function()
|
```
|
||||||
print('Hello there')
|
</TabItem>
|
||||||
end,
|
<TabItem value='JS/TS'>
|
||||||
options = {
|
|
||||||
['Empty button'] = {},
|
```ts
|
||||||
['Example button'] = {
|
import lib from '@overextended/ox_lib/client'
|
||||||
description = 'Example button description',
|
```
|
||||||
metadata = {
|
|
||||||
['Value 1'] = 'Some value',
|
```ts
|
||||||
['Value 2'] = 300
|
lib.registerContext([
|
||||||
}
|
{
|
||||||
},
|
id: 'example_menu',
|
||||||
['Menu button'] = {
|
title: 'Example Context',
|
||||||
menu = 'other_example_menu',
|
onExit: () => {
|
||||||
description = 'Takes you to another menu',
|
console.log('Hello there');
|
||||||
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'}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
options: [
|
||||||
id = 'other_example_menu',
|
{ title: 'Empty button' },
|
||||||
title = 'Other Context Menu',
|
{
|
||||||
menu = 'example_menu',
|
title: 'Example button',
|
||||||
options = {
|
description: 'Example button description',
|
||||||
['Nothing here'] = {}
|
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>
|
</TabItem>
|
||||||
</Tabs>
|
</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
|
To trigger the event from the `Event button` and get it's data we first
|
||||||
need to register the event properly:
|
need to register the event properly:
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
RegisterNetEvent('some_event', function(data)
|
RegisterNetEvent('some_event', function(data)
|
||||||
print(json.encode(data, {indent=true}))
|
print(json.encode(data, {indent=true}))
|
||||||
@@ -217,6 +283,32 @@ RegisterNetEvent('some_event', function(data)
|
|||||||
lib.showContext('another_context_menu')
|
lib.showContext('another_context_menu')
|
||||||
end)
|
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 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`.
|
the event you register, in this case that argument is called `data`.
|
||||||
|
|
||||||
|
|||||||
@@ -10,34 +10,57 @@ by setting input fields.
|
|||||||
|
|
||||||
### lib.inputDialog
|
### lib.inputDialog
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- heading: string
|
lib.inputDialog(heading, rows)
|
||||||
-- rows: strings array or table
|
```
|
||||||
-- type: "input" or "number" or "checkbox" or "select" or "slider"
|
</TabItem>
|
||||||
-- label: string
|
<TabItem value='JS/TS'>
|
||||||
-- options: table array (optional - used ONLY with "select" type)
|
|
||||||
-- value: string
|
```ts
|
||||||
-- label: string
|
import lib from '@overextended/ox_lib/client'
|
||||||
-- 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)
|
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
|
The callback data is promise based meaning that the thread will
|
||||||
not continue executing until the user either sends the data
|
not continue executing until the user either sends the data
|
||||||
or exits the popup.
|
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
|
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
|
would be index `1` (`0`), if we want data from the third field, that would
|
||||||
be index `3`, etc...
|
be index `3` (`2`), etc...
|
||||||
|
|
||||||
The standard input rows will always return a string, if you want a row to be of
|
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`.
|
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
|
:::caution
|
||||||
|
|
||||||
When using the advanced method you can define `icon` and `password` **ONLY** with type `"input"` and
|
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"`.
|
you can define `options` **ONLY** with type `'select'`.
|
||||||
|
|
||||||
|
|
||||||
Doing so otherwise ***will*** result in errors.
|
Doing so otherwise ***will*** result in errors.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
**Example:**
|
## Usage Example
|
||||||
|
|
||||||
|
### Basic
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<TabItem value="basic" label="Basic">
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local input = lib.inputDialog('Police locker', {'Locker number', 'Locker passcode'})
|
local input = lib.inputDialog('Police locker', {'Locker number', 'Locker passcode'})
|
||||||
|
|
||||||
if input then
|
if not input then return end
|
||||||
local lockerNumber = tonumber(input[1])
|
local lockerNumber = tonumber(input[1])
|
||||||
local lockerPasscode = input[2]
|
local lockerPasscode = input[2]
|
||||||
|
|
||||||
print(lockerNumber, lockerPasscode)
|
print(lockerNumber, lockerPasscode)
|
||||||
end
|
|
||||||
```
|
```
|
||||||

|
|
||||||
</TabItem>
|
</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
|
```lua
|
||||||
local input = lib.inputDialog('Police locker', {
|
local input = lib.inputDialog('Police locker', {
|
||||||
@@ -90,6 +138,31 @@ local input = lib.inputDialog('Police locker', {
|
|||||||
})
|
})
|
||||||
print(json.encode(input, {indent=true}))
|
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>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
|
 
|
||||||
@@ -2,72 +2,169 @@
|
|||||||
title: Menu
|
title: Menu
|
||||||
---
|
---
|
||||||
|
|
||||||
|
import Tabs from '@theme/Tabs';
|
||||||
|
import TabItem from '@theme/TabItem';
|
||||||
|
|
||||||
Keyboard navigation menu with specific event functions.
|
Keyboard navigation menu with specific event functions.
|
||||||
|
|
||||||
### lib.registerMenu
|
### lib.registerMenu
|
||||||
Registers and caches a menu under the specified id.
|
Registers and caches a menu under the specified id.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- data: table
|
lib.registerMenu(data, cb)
|
||||||
-- id: string
|
```
|
||||||
-- title: string
|
</TabItem>
|
||||||
-- options: table
|
<TabItem value='JS/TS'>
|
||||||
-- label: string
|
|
||||||
-- icon: string (optinal)
|
```ts
|
||||||
-- values: table of strings (optional - if provided creates a side scrollable list)
|
import lib from '@overextended/ox_lib/client'
|
||||||
-- 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)
|
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
|
### lib.showMenu
|
||||||
Displays the menu with the provided id.
|
Displays the menu with the provided id.
|
||||||
|
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- id: string
|
lib.showMenu(id)
|
||||||
|
```
|
||||||
|
</TabItem>
|
||||||
|
<TabItem value='JS/TS'>
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import lib from '@overextended/ox_lib/client'
|
||||||
|
|
||||||
lib.showMenu(id)
|
lib.showMenu(id)
|
||||||
```
|
```
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
* id: `string`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### lib.hideMenu
|
### lib.hideMenu
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```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)
|
lib.hideMenu(onExit)
|
||||||
```
|
```
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
* onExit?: `boolean`
|
||||||
|
* If true runs the menu's `onClose` function.
|
||||||
|
|
||||||
### lib.getOpenMenu
|
### lib.getOpenMenu
|
||||||
Returns the id of the currently open menu.
|
Returns the id of the currently open menu.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.getOpenMenu()
|
lib.getOpenMenu()
|
||||||
```
|
```
|
||||||
|
</TabItem>
|
||||||
|
<TabItem value='JS/TS'>
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import lib from '@overextended/ox_lib/client'
|
||||||
|
|
||||||
|
lib.getOpenMenu()
|
||||||
|
```
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
|
||||||
### lib.setMenuOptions
|
### lib.setMenuOptions
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- id: string
|
lib.setMenuOptions(id, options, index)
|
||||||
-- options: table
|
```
|
||||||
-- index: number (optional - if specified only sets the options table on the specified options index)
|
</TabItem>
|
||||||
|
<TabItem value='JS/TS'>
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import lib from '@overextended/ox_lib/client'
|
||||||
|
|
||||||
lib.setMenuOptions(id, options, index)
|
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:**
|
**Example:**
|
||||||
|
|
||||||
```lua
|
Replaces the 3rd index option of the specified menu
|
||||||
-- Replaces the option on 3rd index of specified menu
|
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='Lua'>
|
||||||
|
|
||||||
|
```lua
|
||||||
lib.setMenuOptions('some_menu_id', {label = 'New option', icon = 'plus'}, 3)
|
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
|
### Usage Example
|
||||||
First we register the menu with our specified options then we call the show function in the command.
|
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
|
```lua
|
||||||
lib.registerMenu({
|
lib.registerMenu({
|
||||||
id = 'some_menu_id',
|
id = 'some_menu_id',
|
||||||
@@ -107,4 +207,42 @@ RegisterCommand('testmenu', function()
|
|||||||
lib.showMenu('some_menu_id')
|
lib.showMenu('some_menu_id')
|
||||||
end)
|
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
|
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.
|
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.
|
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.
|
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
|
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.
|
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
|
```lua
|
||||||
shared_script '@ox_lib/init.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:**
|
**ACE Permissions:**
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in new issue
Block a user