restructure ox_lib docs

This commit is contained in:
Linden committed 2022-05-12 18:07:54 +10:00
1 parent 8081132d6f
commit a8be760943
21 files changed
+5 -30

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
---
title: Clipboard
---
### lib.setClipboard
Sets the player's clipboard to the specified string value.
```lua
-- value: string
lib.setClipboard(value)
```
+147
View File
@@ -0,0 +1,147 @@
---
title: Context Menu
---
### lib.registerContext
Used for registering a context menu.
```lua
-- id: string
-- title: string
-- menu: string (optional)
-- options: table
-- item: key as string
-- menu: string (optional)
-- arrow: boolean (optional)
-- description: string (optional)
-- metadata: string table or key, value table (optional)
-- event: string (optional)
-- serverEvent: string (optional)
-- args: any (optional)
lib.registerContext(context)
```
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.
`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/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.
### lib.showContext
Opens a registered context menu by it's id.
```lua
-- id: string
lib.showContext(id)
```
### Usage Example
This is a simple command that will register and open a
context menu.
```lua
RegisterCommand('testcontext', function()
lib.registerContext({
id = 'example_menu',
title = 'Example Context',
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'}
}
},
{
id = 'other_example_menu',
title = 'Other Context Menu',
menu = 'example_menu',
options = {
['Nothing here'] = {}
}
}
})
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:
```lua
RegisterNetEvent('some_event', function(data)
print(json.encode(data, {indent=true}))
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')
end)
```
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`.
Using this event we also register a new context menu with it's own options.
By defining a `menu` param to be the id of the first menu we can get the
neat back arrow button next to the menu title that will take us back.
If we have a button that does not define either event, serverEvent or menu
the button will do nothing upon being clicked.
Of course just registering the event won't do much so we need to display it
with the `lib.showContext` function, passing in the menu's id.
As of the time writing this the buttons are sorted **alphabetically**.
![menu_example](https://i.imgur.com/aJu92dv.png)
![metadata](https://i.imgur.com/kFGSlBF.png)
![event_menu](https://i.imgur.com/r0Ln4VP.png)
### lib.getOpenContextMenu
Returns the id of the currently open context menu.
If not context menu is open returns `nil`.
```lua
lib.getOpenContextMenu()
```
+88
View File
@@ -0,0 +1,88 @@
---
title: Input Dialog
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
The input dialog window allows you to take data from the user
by setting input fields.
### lib.inputDialog
```lua
-- heading: string
-- rows: strings array or table
-- type: "input" or "checkbox" or "select"
-- label: string
-- options: table array (optional - used ONLY with "select" type)
-- value: string
-- label: string
-- password: boolean (optional - used ONLY with "input" type)
-- icon: string (optional - used ONLY with "input" type)
lib.inputDialog(heading, rows)
```
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
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...
The input rows will always return a string, if you want a row to be of
number data type, you can use the `tonumber` function to convert it to
a number instead.
If a user left an input field empty it will return `nil`.
You can also add checkboxes that will return `true` if checked and `nil` if unchecked.
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"`.
Doing so otherwise ***will*** result in errors.
:::
**Example:**
<Tabs>
<TabItem value="basic" label="Basic">
```lua
local input = lib.inputDialog('Police locker', {'Locker number', 'Locker passcode'})
if input then
local lockerNumber = tonumber(input[1])
local lockerPasscode = input[2]
print(lockerNumber, lockerPasscode)
end
```
![Example image](https://i.imgur.com/RvFFZqv.png)
</TabItem>
<TabItem value='advanced' label='Advanced'>
```lua
local input = lib.inputDialog('Police locker', {
{ type = "input", label = "Locker number" },
{ type = "checkbox", label = "Some checkbox" },
{ type = "input", label = "Locker PIN", password = true, icon = 'lock' },
{ type = "checkbox", label = "Some other checkbox" },
{ type = 'select', label = 'Value select', options = {
{ value = 'option1', label = 'Option 1' },
{ value = 'option2', label = 'Option 2' },
{ value = 'option3', label = 'Option 3'},
}}
})
print(json.encode(input, {indent=true}))
```
![Example image](https://i.imgur.com/RBn53LN.png) ![Select example](https://i.imgur.com/rLJuDu6.png)
</TabItem>
</Tabs>
+90
View File
@@ -0,0 +1,90 @@
---
title: Notifications
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
### lib.notify
Custom notifications with a lot of styling options.
```lua
-- id: string (optional)
-- title: string (if description then optional)
-- description: string (if title then optional)
-- duration: number (optional)
-- position: 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left' (optional)
-- type: 'inform' | 'error' | 'success'
-- style: table (optional)
-- icon: string (optional)
-- iconColor: string (optional)
lib.notify(data)
```
`id` - When set the current notification will be unique and only shown once on screen
`title` - Must provide if there is no description
`description` - Must provide if there is no title
`position` - Default: `'top-right'`
`type` - Default: `'inform'`
`style` - React CSS styling, works the same as in [TextUI](textui.md)
`icon` - Font Awesome 6 icon, works the same as in [TextUI](textui.md)
`iconColor` - Set a different color for the provided icon
**Example:**
<Tabs>
<TabItem value='standard' label="Standard">
```lua
lib.notify({
title = 'Notification title',
description = 'Notification description',
type = 'success'
})
```
![notification](https://i.imgur.com/cRxJICO.png)
</TabItem>
<TabItem value='custom' label="Custom">
```lua
lib.notify({
id = 'some_identifier',
title = 'Notification title',
description = 'Notification description',
position = 'top',
style = {
backgroundColor = '#141517',
color = '#909296'
},
icon = 'ban',
iconColor = '#C53030'
})
```
![custom_notification](https://i.imgur.com/0EK5APp.png)
</TabItem>
</Tabs>
### lib.defaultNotify
Default notifications provided by Chakra UI.
```lua
-- title: string (if description then optional)
-- description: string (if title then optional)
-- duration: number (optional)
-- position: ToastPositionWithLogical (optional)
-- status: "info" | "warning" | "success" | "error" (optional)
-- id: number (optional)
lib.defaultNotify(data)
```
**Example:**
```lua
lib.defaultNotify({
title = 'Notification title',
description = 'Notification description',
status = 'success'
})
```
![default_notification](https://i.imgur.com/EIibuY9.png)
+163
View File
@@ -0,0 +1,163 @@
---
title: Progress
---
### lib.progressBar
Displays a running progress bar.
```lua
-- duration: number
-- label: string
-- useWhileDead: boolean (optional)
-- canCancel: boolean (optional)
-- anim: table (optional)
-- dict: string (optional - either scenario or dict)
-- clip: string
-- flag: number (optional - default is 49)
-- blendIn: float (optional - default is 3.0)
-- blendOut: float (optional - default is 1.0)
-- duration: number (optional - default is -1)
-- flag: number (optional - default is 49)
-- playbackRate: number (optional - default is 0)
-- lockX: boolean (optional)
-- lockY: boolean (optional)
-- lockZ: boolean (optional)
-- scenario: string (optional - either scenario or dict)
-- playEnter: boolean (optional - default is true)
-- prop: table (optional)
-- model: hash
-- x: number
-- y: number
-- z: number
-- bone: number (optional - default is 60309)
-- pos: table
-- x: number
-- y: number
-- z: number
-- rot: table
-- x: number
-- y: number
-- z: number
-- disable: table (optional)
-- move: boolean (optional)
-- car: boolean (optional)
-- comabt: boolean (optional)
-- mouse: boolean (optional)
--- ...: number (optional - Keys to disable, can have unlimted)
lib.progressBar(data)
```
If you want to define multiple props, you can pass them
as individual tables in the `prop` table.
**Example:**
```lua
if lib.progressBar({
duration = 2000,
label = 'Drinking water',
useWhileDead = false,
canCancel = true,
disable = {
car = true,
},
anim = {
dict = 'mp_player_intdrink',
clip = 'loop_bottle'
},
prop = {
model = `prop_ld_flow_bottle`,
pos = vec3(0.03, 0.03, 0.02),
rot = vec3(0.0, 0.0, -1.5)
},
}) then print('Do stuff when complete') else print('Do stuff when cancelled') end
```
![progress_bar](https://i.imgur.com/7pAwktr.png)
### lib.progressCircle
Similar to `lib.progressBar` except it displays a circle and has no label and
you can define a position.
```lua
-- duration: number
-- position: "middle" or "bottom" (optional - default is "middle")
-- useWhileDead: boolean (optional)
-- canCancel: boolean (optional)
-- anim: table (optional)
-- dict: string (optional - either scenario or dict)
-- clip: string
-- flag: number (optional - default is 49)
-- blendIn: float (optional - default is 3.0)
-- blendOut: float (optional - default is 1.0)
-- duration: number (optional - default is -1)
-- flag: number (optional - default is 49)
-- playbackRate: number (optional - default is 0)
-- lockX: boolean (optional)
-- lockY: boolean (optional)
-- lockZ: boolean (optional)
-- scenario: string (optional - either scenario or dict)
-- playEnter: boolean (optional - default is true)
-- prop: table (optional)
-- model: hash
-- x: number
-- y: number
-- z: number
-- bone: number (optional - default is 60309)
-- pos: table
-- x: number
-- y: number
-- z: number
-- rot: table
-- x: number
-- y: number
-- z: number
-- disable: table (optional)
-- move: boolean (optional)
-- car: boolean (optional)
-- comabt: boolean (optional)
-- mouse: boolean (optional)
--- ...: number (optional - Keys to disable, can have unlimted)
lib.progressCircle(data)
```
**Example:**
```lua
if lib.progressCircle({
duration = 2000,
position = 'bottom',
useWhileDead = false,
canCancel = true,
disable = {
car = true,
},
anim = {
dict = 'mp_player_intdrink',
clip = 'loop_bottle'
},
prop = {
model = `prop_ld_flow_bottle`,
pos = vec3(0.03, 0.03, 0.02),
rot = vec3(0.0, 0.0, -1.5)
},
}) then print('Do stuff when complete') else print('Do stuff when cancelled') end
```
![progress_circle](https://i.imgur.com/nETRm5f.png)
### lib.progressActive
Returns true if a progress bar is currently active.
```lua
lib.progressActive()
```
### lib.cancelProgress
If there is a progress bar active and the
progress bar can be cancelled then it cancels it.
```lua
lib.cancelProgress()
```
+64
View File
@@ -0,0 +1,64 @@
---
title: TextUI
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
### lib.showTextUI
Show the TextUI window.
**DO NOT** run this every tick, it's intented to be used as a toggle.
```lua
-- text: string
-- options: table (optional)
-- position: "right-center" or "left-center" or "top-center" (default - "right-center")
-- icon: string or table
-- iconColor: string
-- style: React.CSSProperties
lib.showTextUI(text, options)
```
**Example:**
<Tabs>
<TabItem label="Basic" value="basic">
```lua
lib.showTextUI('[E] - Fuel vehicle')
```
![](https://i.imgur.com/3ptQyAq.png)
</TabItem>
<TabItem label="Custom style" value="custom">
```lua
lib.showTextUI('[E] - Pick apple', {
position = "top-center",
icon = 'hand',
style = {
borderRadius = 0,
backgroundColor = '#48BB78',
color = 'white'
}
})
```
![](https://i.imgur.com/gNDwPBN.png)
</TabItem>
</Tabs>
The icon library used is Font Awesome 6.0, if for the icon you define only a string
the default icon type will be `solid`.
If you want to use a different icon type, i.e
apple as a brand, you need to define icon as a table with the first value being
the icon type as a string, and the second being the icon name.
`icon = {'fab', 'apple'}`
### lib.hideTextUI
Hides the currently visible TextUI window
```lua
lib.hideTextUI()
```