Merge pull request #46 from overextended/lib-update

Lib update
This commit is contained in:
Luke authored and GitHub committed 2022-09-18 12:40:41 +02:00
commit 538d62a350
30 files changed
+3918 -2137

No files matched your search

+85 -10
View File
@@ -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`
+7 -5
View File
@@ -1,11 +1,13 @@
```lua
-- principal: string or string[] or false
-- command: string
-- callback: function
-- parameters: table (optional)
-- help: string (optional)
lib.addCommand(principal, command, callback, parameters, help)
```
* principal: `string` or `string[]` or `false`
* command: `string`
* callback: `function`
* parameters?: `table` (`array`)
* help?: `string`
```lua
lib.addCommand('group.admin', {'additem', 'giveitem'}, function(source, args)
args.item = Items(args.item)
if args.item and args.count > 0 then
+56 -17
View File
@@ -1,26 +1,65 @@
Caches data related to the player and handling some events or statebags.
An interval runs every 100ms to update data that cannot be checked via handlers.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
https://github.com/overextended/ox_lib/blob/master/resource/cache/client.lua
Caches data related to the player and handling some events or statebags.
An interval runs every 100ms to update data that cannot be checked via handlers.
## States
```lua
cache.ped -- player entity id
cache.playerId -- player id
cache.serverId -- player server id
cache.vehicle -- vehicle entity id
cache.seat -- vehicle seat index
cache.resource -- invoking resource name
```
- ped: `number`
- player entity id
- playerId: `number`
- player id
- serverId: `number`
- player server id
- vehicle: `number` or `false`
- vehicle entity id
- seat: `number` or `false`
- vehicle seat index
- resource: `string`
- invoking resource name
## lib.onCache
Register a callback function when the value is changed.
Register an event handler that is triggered when the cached value is updated.
<Tabs>
<TabItem value='Lua'>
```lua
lib.onCache(key, function(value) end)
```
- key: `string`
- value: `any`
```lua
lib.onCache('vehicle', function(value)
print('vehicle', value)
end)
lib.onCache('seat', function(value)
print('seat', value)
print('old vehicle:', cache.vehicle)
print('new vehicle:', value)
end)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import { onCache } from '@overextended/ox_lib/client';
onCache(key, (value) => {});
```
- key: `string`
- value: `any`
```ts
import { cache, onCache } from '@overextended/ox_lib/client';
lib.onCache('vehicle', (value) => {
console.log('old vehicle:', cache.vehicle);
console.log('new vehicle:', value);
});
```
</TabItem>
</Tabs>
+42 -12
View File
@@ -1,25 +1,55 @@
Triggers a registered server callback and registers an event handler for the response.
## Client -> Server callback
### lib.callback
The response is handled in a separate coroutine.
```lua
-- name: string
-- delay: number or false
-- cb: function
lib.callback(name, delay, cb, ...)
The response is handled in a separate coroutine.
```lua
lib.callback(name, delay, cb, ...)
```
- name: `string`
- delay: `number` or `false`
- cb: `function`
- ...: `any`
```lua
lib.callback('ox_inventory:getItemCount', false, function(count)
print(count)
end, 'water', {type = 'fresh'})
```
### lib.callback.await
The current coroutine is yielded until a response is received.
```lua
-- name: string
-- delay: number or false
lib.callback.await(name, delay, ...)
The current coroutine is yielded until a response is received.
```lua
lib.callback.await(name, delay, ...)
```
- name: `string`
- delay: `number` or `false`
- ...: `any`
```lua
local count = lib.callback.await('ox_inventory:getItemCount', false, 'water', {type = 'fresh'})
print(count)
```
## Server -> Client callback
### lib.callback.register
```lua
lib.callback.register(name, cb)
```
- name: `string`
- cb: `function`
```lua
lib.callback.register('ox:getNearbyVehicles', function(radius)
local nearbyVehicles = lib.getNearbyVehicles(GetEntityCoords(cache.ped), radius, true)
return nearbyVehicles
end
```
+54 -5
View File
@@ -1,9 +1,58 @@
### lib.callback.register
```lua
-- name: string
-- cb: function
lib.callback.register(name, cb)
## Server -> Client callback
### lib.callback
The response is handled in a separate coroutine.
```lua
lib.callback(name, source, cb, ...)
```
- name: `string`
- source: `number`
- cb: `function`
- ...: `any`
```lua
lib.callback('ox:getNearbyVehicles', source, function(vehicles)
for i = 1, #vehicles do
DeleteEntity(entity)
end
end, args.radius)
```
### lib.callback.await
The current coroutine is yielded until a response is received.
```lua
lib.callback.await(name, source, ...)
```
- name: `string`
- source: `number`
- ...: `any`
```lua
local vehicles = lib.callback.await('ox:getNearbyVehicles', source, args.radius)
for i = 1, #vehicles do
DeleteEntity(entity)
end
```
## Client -> Server callback
### lib.callback.register
```lua
lib.callback.register(name, cb)
```
- name: `string`
- cb: `function`
```lua
lib.callback.register('ox_inventory:getItemCount', function(source, item, metadata, target)
local inventory = target and Inventory(target) or Inventory(source)
return (inventory and Inventory.GetItem(inventory, item, metadata, true)) or 0
+5 -5
View File
@@ -1,23 +1,23 @@
### lib.disableControls
Call on frame to disable all stored keys.
```lua
-- Call on frame to disable all stored keys.
lib.disableControls()
```
### lib.disableControls:Add
```lua
-- vararg: number
lib.disableControls:Add(...)
```
* vararg: `number`
### lib.disableControls:Remove
```lua
-- vararg: number
lib.disableControls:Remove(...)
```
* vararg: `number`
### lib.disableControls:Clear
```lua
-- vararg: number
lib.disableControls:Clear(...)
```
* vararg: `number`
+11 -6
View File
@@ -3,11 +3,16 @@
Get the id, ped, and coords of the closest player to a set of coordinates.
```lua
---@param coords vector3 The coords to check from.
---@param maxDistance number The max distance to check.
---@param includePlayer boolean Whether or not to include the current player.
---@return number? playerId
---@return number? playerPed
---@return vector3? playerCoords
function lib.getClosestPlayer(coords, maxDistance, includePlayer) end
```
* coords: `vector3`
* The coords to check from.
* maxDistance: `number`
* The max distance to check.
* includePlayer: `boolean`
* Whether or not to include the current player.
Return:
* playerId?: `number`
* playerPed?: `nubmer`
* playerCoords?: `vector3`
+11 -5
View File
@@ -3,10 +3,16 @@
Get the id and coords of the closest vehicle to a set of coordinates.
```lua
---@param coords vector3 The coords to check from.
---@param maxDistance number The max distance to check.
---@param includePlayerVehicle boolean Whether or not to include the player's current vehicle.
---@return number? vehicle
---@return vector3? vehicleCoords
function lib.getClosestVehicle(coords, maxDistance, includePlayerVehicle) end
```
* coords: `vector3`
* The coords to check from.
* maxDistance: `number`
* The max distance to check.
* includePlayerVehicle: `boolean`
* Whether or not to include the player's current vehicle.
Return:
* vehicle?: `number`
* vehicleCoords?: `vector3`
+9 -4
View File
@@ -3,9 +3,14 @@
Get the id, ped, and coords of all players within range of a set of coordinates.
```lua
---@param coords vector3 The coords to check from.
---@param maxDistance number The max distance to check.
---@param includePlayer boolean Whether or not to include the current player.
---@return number[]
function lib.getNearbyPlayers(coords, maxDistance, includePlayer) end
```
* coords: `vector3`
* The coords to check from.
* maxDistance: `number`
* The max distance to check.
* includePlayer: `boolean`
* Whether or not to include the current player.
Return:
* `number[]`
+9 -4
View File
@@ -3,9 +3,14 @@
Get the id and coords of all vehicles within range of a set of coordinates.
```lua
---@param coords vector3 The coords to check from.
---@param maxDistance number The max distance to check.
---@param includePlayerVehicle boolean Whether or not to include the player's current vehicle.
---@return number[]
function lib.getNearbyVehicles(coords, maxDistance, includePlayerVehicle) end
```
* coords: `vector3`
* The coords to check from.
* maxDistance: `number`
* The max distance to check.
* includePlayerVehicle: `boolean`
* Whether or not to include the player's current vehicle.
Return:
* `number[]`
+51 -10
View File
@@ -2,29 +2,51 @@
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'>
:::caution
This function is **asynchronous** requiring you to do a `.then` callback on the promise or make your function `async`.
:::
```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`.
**Example:**
<Tabs>
<TabItem value='Lua'>
```lua
local alert = lib.alertDialog({
header = 'Hello there',
@@ -35,5 +57,24 @@ local alert = lib.alertDialog({
print(alert)
```
</TabItem>
<TabItem value='JS/TS'>
![alert_dialog](https://i.imgur.com/TnUT3S1.png)
```ts
import lib from '@overextended/ox_lib/client'
const alert = await lib.alertDialog({
header: 'Hello there',
content: 'General Kenobi \n Markdown support!',
centered: true,
cancel: true
})
console.log(alert)
```
</TabItem>
</Tabs>
![alert_dialog](https://i.imgur.com/TnUT3S1.png)
+17 -1
View File
@@ -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`
+180 -88
View File
@@ -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`.
+104 -31
View File
@@ -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)
```
![Example image](https://i.imgur.com/RvFFZqv.png)
</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>
![Example image](https://i.imgur.com/RvFFZqv.png)
### 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}))
```
![Example image](https://i.imgur.com/9dBA2d2.png) ![Select example](https://i.imgur.com/ILdFeot.png)
</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>
![Example image](https://i.imgur.com/9dBA2d2.png) ![Select example](https://i.imgur.com/ILdFeot.png)
+161 -23
View File
@@ -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>
![Example](https://i.imgur.com/lmimH7e.png)
+118 -32
View File
@@ -5,35 +5,49 @@ title: Notifications
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
### lib.notify
## lib.notify
Custom notifications with a lot of styling options.
<Tabs>
<TabItem value='Lua'>
```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)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
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
</TabItem>
</Tabs>
* id?: `string`
* When set the current notification will be unique and only shown once on screen when spammed.
* title?: `string`
* Must provide if there is no description
* description?: `string`
* Must provide if there is no title
* duration?: `number`
* position?: `'top'` or `'top-right'` or `'top-left'` or `'bottom'` or `'bottom-right'` or `'bottom-left'`
* Default: `'top-right'`
* type?: `'inform'` or `'error'` or `'success'`
* Default: `'inform'`
* style?: `table` (`object`)
* React CSS styling format
* icon?: `string`
* Font Awesome 6 icon name
* iconColor: `string`
### Usage Example
### Standard
**Example:**
<Tabs>
<TabItem value='standard' label="Standard">
<TabItem value='Lua'>
```lua
lib.notify({
@@ -42,9 +56,27 @@ lib.notify({
type = 'success'
})
```
![notification](https://i.imgur.com/cRxJICO.png)
</TabItem>
<TabItem value='custom' label="Custom">
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.notify({
title: 'Notification title',
description: 'Notification description',
type: 'success'
})
```
</TabItem>
</Tabs>
![notification](https://i.imgur.com/cRxJICO.png)
### Custom
<Tabs>
<TabItem value='Lua'>
```lua
lib.notify({
@@ -60,25 +92,64 @@ lib.notify({
iconColor = '#C53030'
})
```
![custom_notification](https://i.imgur.com/0EK5APp.png)
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.notify({
id: 'some_identifier',
title: 'Notification title',
description: 'Notification description',
position: 'top',
style: {
backgroundColor: '#141517',
color: '#909296'
},
icon: 'ban',
iconColor: '#C53030'
})
```
</TabItem>
</Tabs>
### lib.defaultNotify
![custom_notification](https://i.imgur.com/0EK5APp.png)
## lib.defaultNotify
Default notifications provided by Chakra UI.
<Tabs>
<TabItem value='Lua'>
```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)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.defaultNotify(data)
```
</TabItem>
</Tabs>
**Example:**
* id?: `number`
* Same as id in `lib.notify`
* title?: `string`
* description?: `string`
* duration?: `number`
* position?: `'top'` or `'top-right'` or `'top-left'` or `'bottom'` or `'bottom-right'` or `'bottom-left'`
* status?: `'info'` or `'warning'` or `'success'` or `'error'`
### Usage Example
<Tabs>
<TabItem value='Lua'>
```lua
lib.defaultNotify({
@@ -87,4 +158,19 @@ lib.defaultNotify({
status = 'success'
})
```
![default_notification](https://i.imgur.com/EIibuY9.png)
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.defaultNotify({
title: 'Notification title',
description: 'Notification description',
status: 'success'
})
```
</TabItem>
</Tabs>
![default_notification](https://i.imgur.com/EIibuY9.png)
+230 -82
View File
@@ -2,54 +2,81 @@
title: Progress
---
### lib.progressBar
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
## lib.progressBar
Displays a running progress bar.
```lua
-- duration: number
-- label: string
-- useWhileDead: boolean (optional)
-- allowRagdoll: boolean (optional)
-- allowCuffed: boolean (optional)
-- allowFalling: 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)
-- playbackRate: number (optional - default is 0)
-- lockX: boolean (optional)
-- lockY: boolean (optional)
-- lockZ: boolean (optional)
<Tabs>
<TabItem value='Lua'>
-- scenario: string (optional - either scenario or dict)
-- playEnter: boolean (optional - default is true)
-- prop: table (optional)
-- model: hash
-- 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)
-- combat: boolean (optional)
-- mouse: boolean (optional)
```lua
lib.progressBar(data)
```
If you want to define multiple props, you can pass them
as individual tables in the `prop` table.
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.progressBar(data)
```
</TabItem>
</Tabs>
* duration: `number`
* label: `string`
* useWhileDead?: `boolean`
* allowRagdoll?: `boolean`
* allowCuffed?: `boolean`
* allowFalling?: `boolean`
* canCancel?: `boolean`
* anim?: `table` (`object`)
* dict?: `string`
* Must specify either scenario or dict
* clip: `string`
* flag?: `number`
* Default: `49`
* blendIn?: `float`
* Default: `3.0`
* blendOut?: `float`
* Default: `1.0`
* duration?: `number`
Default: `-1`
* playbackRate?: `number`
Default: `0`
* lockX?: `boolean`
* lockY?: `boolean`
* lockZ?: `boolean`
* scenario?: `string`
* Must specify either scenario or dict
* playEnter?: `boolean`
* Default: `true`
* prop?: `table` (`object` or `array`)
* [ If you want to define multiple props, you can pass them as individual tables (array of objects) ]
* model: `hash`
* bone?: `number`
* Default: `60309`
* pos: `table`
* x: `number`
* y: `number`
* z: `number`
* rot: `table` (`object`)
* x: `number`
* y: `number`
* z: `number`
* disable?: `table` (`object`)
* move?: `boolean`
* car?: `boolean`
* combat?: `boolean`
* mouse?: `boolean`
### Usage Example
<Tabs>
<TabItem value='Lua'>
**Example:**
```lua
if lib.progressBar({
duration = 2000,
@@ -70,54 +97,115 @@ if lib.progressBar({
},
}) then print('Do stuff when complete') else print('Do stuff when cancelled') end
```
</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
import lib from '@overextended/ox_lib/client'
if (await 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: {x: 0.03, y: 0.03, z: 0.02},
rot: {x: 0.0, y: 0.0, z: -1.5}
},
})) console.log('Do stuff when complete');
else console.log('Do stuff when cancelled')
```
</TabItem>
</Tabs>
![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.
## lib.progressCircle
Similar to `lib.progressBar` except it displays a circle and you can define a position.
<Tabs>
<TabItem value='Lua'>
```lua
-- duration: number
-- label: string (optional)
-- 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)
-- playbackRate: number (optional - default is 0)
-- lockX: boolean (optional)
-- lockY: boolean (optional)
-- lockZ: boolean (optional)
lib.progressCircle(data)
```
</TabItem>
<TabItem value='JS/TS'>
-- scenario: string (optional - either scenario or dict)
-- playEnter: boolean (optional - default is true)
-- prop: table (optional)
-- model: hash
-- 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)
-- combat: boolean (optional)
-- mouse: boolean (optional)
```ts
import lib from '@overextended/ox_lib/client'
lib.progressCircle(data)
```
</TabItem>
</Tabs>
* duration: `number`
* label?: `string`
* position?: `'middle'` or `'bottom'`
* Default: `'middle'`
* useWhileDead?: `boolean`
* allowRagdoll?: `boolean`
* allowCuffed?: `boolean`
* allowFalling?: `boolean`
* canCancel?: `boolean`
* anim?: `table` (`object`)
* dict?: `string`
* Must specify either scenario or dict
* clip: `string`
* flag?: `number`
* Default: `49`
* blendIn?: `float`
* Default: `3.0`
* blendOut?: `float`
* Default: `1.0`
* duration?: `number`
Default: `-1`
* playbackRate?: `number`
Default: `0`
* lockX?: `boolean`
* lockY?: `boolean`
* lockZ?: `boolean`
* scenario?: `string`
* Must specify either scenario or dict
* playEnter?: `boolean`
* Default: `true`
* prop?: `table` (`object` or `array`)
* [ If you want to define multiple props, you can pass them as individual tables (array of objects) ]
* model: `hash`
* bone?: `number`
* Default: `60309`
* pos: `table`
* x: `number`
* y: `number`
* z: `number`
* rot: `table` (`object`)
* x: `number`
* y: `number`
* z: `number`
* disable?: `table` (`object`)
* move?: `boolean`
* car?: `boolean`
* combat?: `boolean`
* mouse?: `boolean`
### Usage Example
<Tabs>
<TabItem value='Lua'>
**Example:**
```lua
if lib.progressCircle({
duration = 2000,
@@ -138,20 +226,80 @@ if lib.progressCircle({
},
}) then print('Do stuff when complete') else print('Do stuff when cancelled') end
```
</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
import lib from '@overextended/ox_lib/client'
if (await 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: {x: 0.03, y: 0.03, z: 0.02},
rot: {x: 0.0, y: 0.0, z: -1.5}
},
})) console.log('Do stuff when complete')
else console.log('Do stuff when cancelled')
```
</TabItem>
</Tabs>
![progress_circle](https://i.imgur.com/nETRm5f.png)
### lib.progressActive
## lib.progressActive
Returns true if a progress bar is currently active.
<Tabs>
<TabItem value='Lua'>
```lua
lib.progressActive()
```
</TabItem>
<TabItem value='JS/TS'>
### lib.cancelProgress
```ts
import lib from '@overextended/ox_lib/client'
lib.progressActive()
```
</TabItem>
</Tabs>
## lib.cancelProgress
If there is a progress bar active and the
progress bar can be cancelled then it cancels it.
<Tabs>
<TabItem value='Lua'>
```lua
lib.cancelProgress()
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.cancelProgress()
```
</TabItem>
</Tabs>
+73 -18
View File
@@ -5,32 +5,63 @@ title: TextUI
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
### lib.showTextUI
## lib.showTextUI
Show the TextUI window.
**DO NOT** run this every tick, it's intented to be used as a toggle.
<Tabs>
<TabItem value='Lua'>
```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)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.showTextUI(text, options)
```
</TabItem>
</Tabs>
* text: `string`
* options?: `table`
* position?: `'right-center'` or `'left-center'` or `'top-center'`
* Default: `'right-center'`
* icon?: `string` or `table` (`array`)
* iconColor?: `string`
* style?: React.CSSProperties
### Usage Example
### Basic
**Example:**
<Tabs>
<TabItem label="Basic" value="basic">
<TabItem value='Lua'>
```lua
lib.showTextUI('[E] - Fuel vehicle')
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.showTextUI('[E] - Fuel vehicle')
```
</TabItem>
</Tabs>
![](https://i.imgur.com/3ptQyAq.png)
</TabItem>
<TabItem label="Custom style" value="custom">
### Custom styling
<Tabs>
<TabItem value='Lua'>
```lua
lib.showTextUI('[E] - Pick apple', {
@@ -43,22 +74,46 @@ lib.showTextUI('[E] - Pick apple', {
}
})
```
</TabItem>
<TabItem value='JS/TS'>
![](https://i.imgur.com/gNDwPBN.png)
```ts
import lib from '@overextended/ox_lib/client'
lib.showTextUI('[E] - Pick apple', {
position: "top-center",
icon: 'hand',
style: {
borderRadius: 0,
backgroundColor: '#48BB78',
color: 'white'
}
})
```
</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.
![](https://i.imgur.com/gNDwPBN.png)
`icon = {'fab', 'apple'}`
### lib.hideTextUI
Hides the currently visible TextUI window
<Tabs>
<TabItem value='Lua'>
```lua
lib.hideTextUI()
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.hideTextUI()
```
</TabItem>
</Tabs>
+3 -2
View File
@@ -4,11 +4,12 @@ Locale files should use the [ISO Language Code](http://www.lingoes.net/en/transl
Players can use `setlocale [langcode]`, and admins can use `serverlocale [langcode]` to change the loaded file.
```lua
-- str: string
-- ...: string | number
locale(str, ...)
```
* str: `string`
* ...: `string` or `number`
Additional arguments can be sent to format the locale output.
```lua
+5 -4
View File
@@ -12,12 +12,13 @@ set datadog:site "datadoghq.com"
```
```lua
-- source: string | number
-- event: string
-- message: string
-- ...: string
lib.logger(source, event, message, ...)
```
* source: `string` or `number`
* event: `string`
* message: `string`
* ...: `string`
Source is passed to ddsource and creates a tag. Could be playerId, identifier, -1, or server.
Event is passed to ddservice and displays in the logs list.
+5 -3
View File
@@ -3,11 +3,13 @@
Simple and centralised distance checking, supporting callbacks when entering, leaving, and standing in-range of set coordinates.
```lua
-- coords: vector3
-- distance: number
-- data: table
lib.points.new(coords, distance, data)
```
* coords: `vector3`
* distance: `number`
* data: `table`
```lua
local point = lib.points.new(playerCoords, 5, {
dunak = 'nerd',
})
+11 -7
View File
@@ -3,12 +3,16 @@
Starts a shapetest originating from the camera, extending to ~10m.
```lua
---@param flags number? Defaults to 1|2|8|16 (see: https://docs.fivem.net/natives/?_0x377906D8A31E5586)
---@param p8 number? A bit mask with bits 1, 2, 4, or 7 relating to collider types. 4 and 7 are usually used.
---@return boolean hit
---@return number entityHit
---@return vector3 endCoords
---@return vector3 surfaceNormal
---@return number materialHash
function lib.raycast.cam(flags, p8) end
```
* flags?: `number`
* Defaults to 1|2|8|16 (see: https://docs.fivem.net/natives/?_0x377906D8A31E5586)
* p8?: `numbe`
* A bit mask with bits 1, 2, 4, or 7 relating to collider types. 4 and 7 are usually used.
Return:
* hit: `boolean`
* entityHit: `number`
* endCoords: `vector3`
* surfaceNormal: `vector3`
* materialHash: `number`
+98 -10
View File
@@ -1,37 +1,125 @@
Check if assets exist, such as models, and loads them into memory.
Throws errors for invalid assets and returns true if the asset is loaded.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
### lib.requestAnimDict
<Tabs>
<TabItem value='Lua'>
```lua
-- dict: string
-- timeout: number [default: 100]
lib.requestAnimDict(dict, timeout)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.requestAnimDict(dict, timeout)
```
</TabItem>
</Tabs>
* dict: `string`
* timeout: `number`
* Default: `100`
### lib.requestAnimSet
<Tabs>
<TabItem value='Lua'>
```lua
-- set: string
-- timeout: number [default: 100]
lib.requestAnimSet(set, timeout)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.requestAnimSet(set, timeout)
```
</TabItem>
</Tabs>
* set: `string`
* timeout: `number`
* Default: `100`
### lib.requestModel
<Tabs>
<TabItem value='Lua'>
```lua
-- model: string
-- timeout: number [default: 100]
lib.requestModel(model, timeout)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.requestModel(model, timeout)
```
</TabItem>
</Tabs>
* model: `string`
* timeout: `number`
* Default: `100`
### lib.requestStreamedTextureDict
<Tabs>
<TabItem value='Lua'>
```lua
-- dict: string
-- timeout: number [default: 100]
lib.requestStreamedTextureDict(dict, timeout)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.requestStreamedTextureDict(dict, timeout)
```
</TabItem>
</Tabs>
* dict: `string`
* timeout: `number`
* Default: `100`
### lib.requestNamedPtfxAsset
<Tabs>
<TabItem value='Lua'>
```lua
-- fxName: string
-- timeout: number [default: 100]
lib.requestNamedPtfxAsset(fxName, timeout)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.requestNamedPtfxAsset(fxName, timeout)
```
</TabItem>
</Tabs>
* fxName: `string`
* timeout: `number`
* Default: `100`
+47 -6
View File
@@ -1,25 +1,66 @@
Mostly follows the format used by ESX and QBCore, with extra data such as damaged/missing props.
https://github.com/overextended/ox_lib/blob/master/resource/vehicleProperties/client.lua#L5
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
### lib.getVehicleProperties
```lua
-- vehicle: entity
```ts
lib.getVehicleProperties(vehicle)
```
* vehicle: `entity`
<Tabs>
<TabItem value='Lua'>
```lua
lib.getVehicleProperties(GetVehiclePedIsUsing(PlayerPedId()))
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
lib.getVehicleProperties(GetVehiclePedIsUsing(PlayerPedId()))
```
</TabItem>
</Tabs>
### lib.setVehicleProperties
Requires the vehicle to belong to the client. _Do not use NetworkRequestControlOfEntity_.
```lua
-- vehicle: entity
-- props: table
lib.setVehicleProperties(vehicle, props)
```lua
lib.setVehicleProperties(vehicle, props)
```
* vehicle: `entity`
* props: `table` (`object`)
<Tabs>
<TabItem value='Lua'>
```lua
RegisterNetEvent('ox_lib:setVehicleProperties', function(netid, data)
lib.setVehicleProperties(NetToVeh(netid), data)
end)
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/client'
onNet('ox_lib:setVehicleProperties', (netid, data) => {
lib.setVehicleProperties(NetToVeh(netid), data)
})
```
</TabItem>
</Tabs>
#### Recommended usage
The server should tell the owner of the entity to set properties, using the following trigger.
+20 -1
View File
@@ -1,10 +1,29 @@
### lib.versionCheck
Compares the resource version to the latest published release on GitHub.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
```lua
-- repository: string
lib.versionCheck(repository)
```
* repository: `string`
<Tabs>
<TabItem value='Lua'>
```lua
lib.versionCheck('overextended/ox_lib')
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/server'
lib.versionCheck('overextended/ox_lib')
```
</TabItem>
</Tabs>
[Utilises GitHub's release API](https://docs.github.com/en/rest/reference/releases)
+26 -4
View File
@@ -1,9 +1,31 @@
### lib.checkDependency
Check if a resource is using a specified version or higher, allowing for compatibility checks or throwing errors.
```lua
-- resource: string
-- version: string
lib.checkDependency(resource, version)
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
```lua
lib.checkDependency(resource, version)
```
* resource: `string`
* version: `string`
<Tabs>
<TabItem value='Lua'>
```lua
if not lib.checkDependency('ox_lib', '1.5.0') then error() end
```
</TabItem>
<TabItem value='JS/TS'>
```ts
import lib from '@overextended/ox_lib/shared'
// import { checkDependency } from '@overextended/ox_lib/shared'
if (!lib.checkDependency('ox_lib', '1.5.0')) error()
```
</TabItem>
</Tabs>
+47 -14
View File
@@ -1,25 +1,51 @@
An alternative to PolyZone utilising [glm.polygon](https://github.com/gottfriedleibniz/lua/blob/luaglm/EXTENDED.md#polygon).
Faster alternative to PolyZone utilising [glm.polygon](https://github.com/gottfriedleibniz/lua/blob/luaglm/EXTENDED.md#polygon).
## lib.zones.poly
```lua
-- data: table
-- points: vector3[] all z values must match
-- thickness: number (optional), default 4
-- debug: bool (optional)
lib.zones.poly(data)
```
* data: `table`
* points: `vector3[]`
* All z values must match
* thickness?: `number`
* Default: `4`
* onEnter: `function`(self: `table`)
* onExit: `function`(self: `table`)
* inside: `function`(self: `table`)
* debug?: `boolean`
-- data: table
-- coords: vector3
-- size: vector3 (optional), default is vec3(4, 4, 4)
-- rotation: number (optional), angle in degrees
-- debug: bool (optional)
## lib.zones.box
```lua
lib.zones.box(data)
```
* data: `table`
* coords: `vector3`
* size?: `vector3`
* Default: `vec3(4, 4, 4)`
* rotation?: `number`
* Angle in degrees
* onEnter: `function`(self: `table`)
* onExit: `function`(self: `table`)
* inside: `function`(self: `table`)
* debug?: `boolean`
-- data: table
-- coords: vector3
-- radius: number (optional), default is 2
-- debug: bool (optional)
## lib.zones.sphere
```lua
lib.zones.sphere(data)
```
* data: `table`
* coords: `vector3`
* radius?: `number`
* Default: `2`
* onEnter: `function`(self: `table`)
* onExit: `function`(self: `table`)
* inside: `function`(self: `table`)
* debug?: `boolean`
## Usage Examples
```lua
function onEnter(self)
@@ -82,3 +108,10 @@ poly:remove()
sphere:remove()
box:remove()
```
## Zone creation script
Similarly to PolyZone, there is a zone creation script included.
To use it use the `/zone` with `poly`, `box` or `sphere` as args.
Available controls will be displayed on the right side.
+53
View File
@@ -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/server'
```
```ts
import { versionCheck } from '@overextended/ox_lib/server'
```
</TabItem>
</Tabs>
**ACE Permissions:**
```
@@ -35,6 +65,29 @@ That's it!
You can now use the library functions inside of your resource, check the rest of the
documentation to see how to utilise them.
# Using icons for interface functions
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 (`array`) with the first value being
the icon type (`fas`, `far`, `fab`) as a string, and the second being the icon name.
<Tabs>
<TabItem value='Lua'>
```lua
icon = {'fab', 'apple'}
```
</TabItem>
<TabItem value='JS/TS'>
```ts
icon: ['fab', 'apple']
```
</TabItem>
</Tabs>
# Building the UI
If you wish to edit any of the UI elements you will need to download the *source* code, edit what you need and then