### Install Dependencies Source: https://github.com/esx-framework/overextended.github.io/blob/main/README.md Installs project dependencies using pnpm. Run this before starting the development server. ```bash pnpm i ``` -------------------------------- ### Start Development Server Source: https://github.com/esx-framework/overextended.github.io/blob/main/README.md Starts the development server. Visit localhost:3000 after running this command. ```bash pnpm dev ``` -------------------------------- ### Resource Start Order Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory.mdx Ensure resources start in the correct order to prevent dependency errors. Essential resources like oxmysql and ox_lib should start early. ```bash start oxmysql # this should be one of the first resources start ox_lib start framework # the name of your framework (i.e. ox_core, es_extended, qbx_core) start ox_target start ox_inventory ``` -------------------------------- ### Install and Build Ox Doorlock Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_doorlock.mdx Follow these steps to clone the repository, install dependencies, and build the web interface for the Ox Doorlock resource. ```bash git clone https://github.com/overextended/ox_doorlock.git cd ox_doorlock/web pnpm i pnpm build ``` -------------------------------- ### Install OxMySQL npm Package Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/oxmysql.mdx Install the OxMySQL npm package for JavaScript resources to get intellisense and a consistent API similar to Lua. ```bash # With pnpm pnpm add @overextended/oxmysql ``` ```bash # With Yarn yarn add @overextended/oxmysql ``` ```bash # With npm npm install @overextended/oxmysql ``` -------------------------------- ### Zone Event Callbacks Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Zones/Shared.mdx Provides example functions for onEnter, onExit, and inside events for zones, and demonstrates creating multiple zone types with these callbacks. ```lua function onEnter(self) print('entered zone', self.id) end function onExit(self) print('exited zone', self.id) end function inside(self) print('you are inside zone ' .. self.id) end local poly = lib.zones.poly({ points = { vec(413.8, -1026.1, 29), vec(411.6, -1023.1, 29), vec(412.2, -1018.0, 29), vec(417.2, -1016.3, 29), vec(422.3, -1020.0, 29), vec(426.8, -1015.9, 29), vec(431.8, -1013.0, 29), vec(437.3, -1018.4, 29), vec(432.4, -1027.2, 29), vec(424.7, -1023.5, 29), vec(420.0, -1030.2, 29), vec(409.8, -1028.4, 29), }, thickness = 2, debug = true, inside = inside, onEnter = onEnter, onExit = onExit }) local sphere = lib.zones.sphere({ coords = vec3(442.5363, -1017.666, 28.65637), radius = 1, debug = true, inside = inside, onEnter = onEnter, onExit = onExit }) local box = lib.zones.box({ coords = vec3(442.5363, -1017.666, 28.65637), size = vec3(1, 1, 1), rotation = 45, debug = true, inside = inside, onEnter = onEnter, onExit = onExit }) ``` -------------------------------- ### Example Usage of GetSlot Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Functions/Server.mdx Demonstrates how to use the GetSlot function and print the returned slot data. The example shows the expected structure of a slot object. ```lua local slot = exports.ox_inventory:GetSlot(source, 1) print(json.encode(slot, {indent=true})) --[[ { "weight": 2000, "name": "water", "metadata": [], "slot": 1, "label": "Water", "close": true, "stack": true, "count: 4 } ]] ``` -------------------------------- ### Install ESX Framework Dependencies Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Frameworks/esx.mdx Ensure these resources are started in your server.cfg immediately after es_extended for proper Ox Inventory functionality. ```yaml start oxmysql start ox_lib start es_extended start qtarget start ox_inventory ``` -------------------------------- ### Standard Notification Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/notify.mdx Provides an example of a standard notification with a title, description, and success type. ```lua lib.notify({ title = 'Notification title', description = 'Notification description', type = 'success' }) ``` ```typescript import lib from '@overextended/ox_lib/client'; lib.notify({ title: 'Notification title', description: 'Notification description', type: 'success', }); ``` -------------------------------- ### Example Usage of lib.logger Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Logger/Server.mdx An example demonstrating how to use the lib.logger function to log the creation of a vehicle. The vehicle data is encoded as a JSON string. ```lua local vehicle = Ox.CreateVehicle(false, `sultanrs`, vector4(-56.479122, -1116.870362, 26.432250, 0.000030517578)) lib.logger(-1, 'CreateVehicle', json.encode(vehicle)) ``` -------------------------------- ### Register Server Callback Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Callback/JavaScript/Server.mdx Example of registering a server callback named 'test:server'. It logs received arguments and returns a server-specific value. ```typescript onClientCallback('test:server', (playerId, ...args: [number, null, number, null, null, number]) => { console.log('onClientCallback', playerId, ...args); return { serverValue: 3000, }; }); ``` -------------------------------- ### pnpm Package.json Scripts Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/guides/pnpm.mdx Example of scripts defined in a package.json file. You can execute these scripts using pnpm. ```json "scripts": { "start": "vite", "watch": "vite build --watch", "build": "tsc && vite build", "preview": "vite preview", "format": "prettier --write \"./src/**/*.{ts,tsx,css}\"" } ``` -------------------------------- ### Example Usage of Alert Dialog (Lua) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/alert.mdx An example of how to use the `alertDialog` function in Lua, including setting header, content, and other options. The return value indicates player interaction. ```lua local alert = lib.alertDialog({ header = 'Hello there', content = 'General Kenobi Markdown support!', centered = true, cancel = true }) print(alert) ``` -------------------------------- ### Start UI Development Server with Hot Reloads Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib.mdx Run the development server with hot reloads for browser-based UI development. ```bash pnpm start ``` -------------------------------- ### Install Ox Core for JavaScript Resources Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core.mdx Install the Ox Core npm package for your JavaScript resources to get full TypeScript and Intellisense support. This is recommended for JavaScript development. ```bash pnpm i @overextended/ox_core ``` -------------------------------- ### JSON Data Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Require/Shared.mdx An example JSON file structure containing event mappings, intended to be loaded by lib.loadJson. ```json { "disconnect": "onPlayerDropped" } ``` -------------------------------- ### Registering a Custom Stash Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Guides/stashes.mdx Register a custom stash with specific properties. This example shows how to set a hardcoded stash configuration and register it when the ox_inventory resource starts. ```lua -- Server local stash = { id = '42wallabyway', label = '42 Wallaby Way', slots = 50, weight = 100000, owner = 'char1:license' } AddEventHandler('onServerResourceStart', function(resourceName) if resourceName == 'ox_inventory' or resourceName == GetCurrentResourceName() then exports.ox_inventory:RegisterStash(stash.id, stash.label, stash.slots, stash.weight, stash.owner) end end) -- Client exports.ox_inventory:openInventory('stash', {id='42wallabyway', owner=property.owner}) ``` -------------------------------- ### Basic TextUI Usage Example (Lua) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/textui.mdx Demonstrates the basic usage of showing a TextUI prompt with simple text content in Lua. ```lua lib.showTextUI('[E] - Fuel vehicle') ``` -------------------------------- ### Start UI Development Server for In-Game Testing Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib.mdx Run the development server that writes changes to disk for in-game testing, requiring resource restarts. ```bash pnpm start:game ``` -------------------------------- ### Install pnpm Globally Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/guides/pnpm.mdx Install pnpm globally using npm. This command should be run in your command-line terminal. ```bash npm install -g pnpm ``` -------------------------------- ### Build Ox Inventory Web Assets Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory.mdx Clone the repository, navigate to the web directory, install dependencies, and build the assets. ```bash git clone https://github.com/overextended/ox_inventory.git cd ox_inventory/web pnpm i pnpm build ``` -------------------------------- ### Trigger Client Callback Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Callback/JavaScript/Server.mdx Example of triggering a client callback named 'test:client' after a delay. It awaits a response from the client and logs it. ```typescript setTimeout(async () => { const response = await triggerClientCallback<{ clientValue: string }>('test:client', 1, [1, null, 3, null, null, 6]) if (!response) return; console.log(response.clientValue); console.log('Response from client', response); }, 100); ``` -------------------------------- ### CanCarryAmount Usage Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Functions/Server.mdx Shows how to use CanCarryAmount to find out how much of an item can be carried, and then uses AddItem to add that calculated amount. ```lua -- Checks how much you can carry amountToAdd = exports.ox_inventory:CanCarryAmount(inv, 'stone') -- Adds the amount exports.ox_inventory:AddItem(inv, 'stone', amountToAdd) ``` -------------------------------- ### SetSlotCount Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Functions/Server.mdx Sets the total number of available slots for a given inventory. This example demonstrates setting the slot count for player 1's inventory. ```lua local ox_inventory = exports.ox_inventory -- Set the slot count for player 1's inventory to 10. ox_inventory:SetSlotCount(1, 10) ``` -------------------------------- ### Locale Example Usage (Lua) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Locale/Shared.mdx Demonstrates loading the locale module and printing translated strings at intervals. Includes formatting with arguments. ```lua -- Load the locale module lib.locale() SetInterval(function() print(locale('grand_theft_auto')) print(locale('suspect_sex', locale('male'))) end, 5000) ``` -------------------------------- ### Basic TextUI Usage Example (JavaScript) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/textui.mdx Demonstrates the basic usage of showing a TextUI prompt with simple text content in JavaScript. ```typescript import lib from '@overextended/ox_lib/client'; lib.showTextUI('[E] - Fuel vehicle'); ``` -------------------------------- ### Locale Example Usage (JavaScript) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Locale/Shared.mdx Demonstrates initializing the locale module and logging translated strings at intervals. Includes formatting with arguments. ```typescript import { initLocale, locale } from '@overextended/ox_lib/shared' // Load the locale module initLocale() setInterval(() => { console.log(locale('grand_theft_auto')) console.log(locale('suspect_sex', locale('male'))) }, 5000) ``` -------------------------------- ### Example Usage of Alert Dialog (JavaScript) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/alert.mdx An example of how to use the `alertDialog` function in JavaScript, including setting header, content, and other options. The return value indicates player interaction. This function is asynchronous. ```javascript import lib from '@overextended/ox_lib/client'; const alert = await lib.alertDialog({ header: 'Hello there', content: 'General Kenobi Markdown support!', centered: true, cancel: true, }); console.log(alert); ``` -------------------------------- ### Custom Notification Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/notify.mdx Illustrates a custom notification with advanced styling, position, and icon settings. ```lua lib.notify({ id = 'some_identifier', title = 'Notification title', description = 'Notification description', showDuration = false, position = 'top', style = { backgroundColor = '#141517', color = '#C1C2C5', ['.description'] = { color = '#909296' } }, icon = 'ban', iconColor = '#C53030' }) ``` ```typescript import lib from '@overextended/ox_lib/client'; lib.notify({ id: 'some_identifier', title: 'Notification title', description: 'Notification description', showDuration: false, position: 'top', style: { backgroundColor: '#141517', color: '#C1C2C5', '.decription': { color: '#909296', }, }, icon: 'ban', iconColor: '#C53030', }); ``` -------------------------------- ### Shop Definition Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Guides/shops.mdx Defines a shop with inventory, blip, and target locations. Supports BoxZones or peds for interaction. ```lua { General = { name = 'Shop', blip = { id = 59, colour = 69, scale = 0.8 }, inventory = { { name = 'burger', price = 10 }, { name = 'water', price = 10 }, { name = 'cola', price = 10 }, }, locations = { vec3(25.7, -1347.3, 29.49), }, targets = { -- Shop using a BoxZone { loc = vec3(25.06, -1347.32, 29.5), length = 0.7, width = 0.5, heading = 0.0, minZ = 29.5, maxZ = 29.9, distance = 1.5 }, -- Shop using a ped { ped = `mp_m_shopkeep_01`, scenario = 'WORLD_HUMAN_AA_COFFEE', loc = vec3(24.407, -1347.283, 28.497), heading = 270.311, }, } } } ``` -------------------------------- ### Get License Data Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Functions/server.mdx Retrieves license data based on the license name. ```lua Ox.GetLicense(name) ``` -------------------------------- ### Progress Bar with Customization (Lua) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/progress.mdx Example of using lib.progressBar in Lua with custom duration, label, animation, props, and disabled actions. ```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 ``` -------------------------------- ### Example: Set Specific Menu Option Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/menu.mdx Demonstrates how to replace the options at a specific index within a menu. This is useful for modifying individual menu items. ```lua lib.setMenuOptions('some_menu_id', {label = 'New option', icon = 'plus'}, 3) ``` -------------------------------- ### Create Polygon Zone (Function Format) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Zones/Shared.mdx Example of creating a polygon zone using the function format, suitable for direct use in scripts. ```lua local poly = lib.zones.poly({ name = poly, points = { vec(447.9, -998.8, 25.8), vec(450.3, -998.2, 25.8), vec(449.9, -995.5, 25.8), vec(447.2, -995.6, 25.8), vec(446.3, -997.9, 25.8), }, thickness = 2, }) ``` -------------------------------- ### CanCarryItem Usage Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Functions/Server.mdx Demonstrates how to use CanCarryItem to determine if a player can carry a specific quantity of an item before attempting to add it to their inventory. ```lua -- Checks if the player calling the event can carry 3 water items if exports.ox_inventory:CanCarryItem(source, 'water', 3) then -- Do stuff if can carry else -- Do stuff if can't carry end ``` -------------------------------- ### Get All Player Licenses Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Server/OxPlayer.mdx Returns an object containing information for all licenses held by the player. ```lua player.getLicenses() ``` -------------------------------- ### Register Client Callback Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Callback/JavaScript/Client.mdx Registers a client callback named 'test:client' that logs received arguments and returns a value to the server. ```typescript onServerCallback('test:client', (...args: [number, number, string]) => { console.log(args); return { clientValue: 'Value from the client', }; }); ``` -------------------------------- ### Get All Licenses Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Functions/server.mdx Call this function to retrieve an array of all license data. The returned data is in the format of OxLicense objects. ```lua Ox.GetLicenses() ``` -------------------------------- ### Get Account Metadata Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Server/OxAccount.mdx Retrieves specific metadata values from an account. Pass a single key to get one value, or an array of keys to get multiple values. ```lua account.get(key) ``` -------------------------------- ### Registering a Server Command with Parameters Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/AddCommand/Server.mdx Example of registering a 'giveitem' command. This snippet demonstrates how to define parameters for target player, item name, count, and metadata type, along with access restrictions. ```lua lib.addCommand('giveitem', { help = 'Gives an item to a player', params = { { name = 'target', type = 'playerId', help = 'Target player\'s server id', }, { name = 'item', type = 'string', help = 'Name of the item to give', }, { name = 'count', type = 'number', help = 'Amount of the item to give, or blank to give 1', optional = true, }, { name = 'metatype', help = 'Sets the item\'s \"metadata.type\"', optional = true, }, }, restricted = 'group.admin' }, function(source, args, raw) local item = Items(args.item) if item then Inventory.AddItem(args.target, item.name, args.count or 1, args.metatype) end end) ``` -------------------------------- ### English Locale File Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Locale/Shared.mdx Example of an English locale JSON file. This file defines translations for various game-related terms. ```json { "grand_theft_auto": "grand theft auto", "male": "male", "female": "female", "suspect_sex": "suspect is %s" } ``` -------------------------------- ### lib.raycast.fromCoords Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Raycast/Client.mdx Starts a raycast originating from specified coordinates to a destination. It can be configured with flags and entities to ignore, returning detailed hit information. ```APIDOC ## lib.raycast.fromCoords ### Description Starts a shapetest originating from starting coordinates and ending at destination coordinates. ### Method ```lua lib.raycast.fromCoords(coords, destination, flags, ignore) ``` ### Parameters #### Path Parameters - **coords** (vector3) - Required - Starting coords for raycast - **destination** (vector3) - Required - Destination coords for raycast - **flags** (number) - Optional - See: https://docs.fivem.net/natives/?_0x377906D8A31E5586. Default: `511` - **ignore** (number) - Optional - A bit mask with bits 1, 2, 4, or 7 relating to collider types. 4 and 7 are usually used. Default: `4` ### Response #### Success Response - **hit** (boolean) - Whether or not an entity was hit - **entityHit** (number) - Entity handle of hit entity - **endCoords** (vector3) - Closest coords to where the raycast hit - **surfaceNormal** (vector3) - Normal to the surface that was hit - **materialHash** (number) - Material hash of the hit surface ``` -------------------------------- ### Register and Show Client Menu (Lua) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/menu.mdx Registers a client-side menu with various options and then shows it via a command. Avoid re-registering static menus. ```lua lib.registerMenu({ id = 'some_menu_id', title = 'Menu title', position = 'top-right', onSideScroll = function(selected, scrollIndex, args) print("Scroll: ", selected, scrollIndex, args) end, onSelected = function(selected, secondary, args) if not secondary then print("Normal button") else if args.isCheck then print("Check button") end if args.isScroll then print("Scroll button") end end print(selected, secondary, json.encode(args, {indent=true})) end, onCheck = function(selected, checked, args) print("Check: ", selected, checked, args) end, onClose = function(keyPressed) print('Menu closed') if keyPressed then print(('Pressed %s to close the menu'):format(keyPressed)) end end, options = { {label = 'Simple button', description = 'It has a description!'}, {label = 'Checkbox button', checked = true}, {label = 'Scroll button with icon', icon = 'arrows-up-down-left-right', values={'hello', 'there'}}, {label = 'Button with args', args = {someArg = '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'}}, } }, function(selected, scrollIndex, args) print(selected, scrollIndex, args) end) RegisterCommand('testmenu', function() lib.showMenu('some_menu_id') end) ``` -------------------------------- ### Run a Script with pnpm Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/guides/pnpm.mdx Execute a script defined in package.json using pnpm. For example, 'pnpm build' will run the 'build' script. ```bash pnpm build ``` -------------------------------- ### Trigger Server Callback Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Callback/JavaScript/Client.mdx Triggers a server callback named 'test:server' after a 100ms delay with specific arguments and logs the response from the server. ```typescript setTimeout(async () => { const args = [1, null, 3, null, null, 6]; const response = await triggerServerCallback<{ serverValue: number }>('test:server', 1, args); if (!response) return; console.log('Response from server', response); }, 100); ``` -------------------------------- ### Register and Show Client Menu (JavaScript) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/menu.mdx Registers a client-side menu with various options and then shows it via a command. Avoid re-registering static menus. ```javascript 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('Scroll: ', selected, scrollIndex, args); }, onSelected: (selected, secondary, args) => { if (!secondary) { console.log('Normal button'); } else { if (args.isCheck) { console.log('Check button'); } if (args.isScroll) { console.log('Scroll button'); } } console.log(selected, secondary, JSON.stringify(args, null, 2)); }, onCheck: (selected, checked, args) => { console.log('Check: ', selected, checked, args); }, onClose: (keyPressed) => { console.log('Menu closed'); if (keyPressed) { console.log(`Pressed ${keyPressed} to close the menu`); } }, options: [ { label: 'Simple button', description: 'It has a description!' }, { label: 'Checkbox button', checked: true }, { label: 'Scroll button with icon', icon: 'arrows-up-down-left-right', values: ['hello', 'there'] }, { label: 'Button with args', args: { someArg: '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 ); ``` -------------------------------- ### DUI Instance Usage Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Dui/Lua/Client.mdx Demonstrates the lifecycle of a DUI instance: creation with specific parameters, changing its URL, sending a message to it, and finally removing it. ```lua local dui = lib.dui:new({ url = ("nui://%s/web/index.html"):format(cache.resource), width = 1920, height = 1080, debug = true }) -- Change url dui:setUrl("https://google.com") -- Send a message dui:sendMessage({ action = "display", value = true }) -- Destroy dui:remove() ``` -------------------------------- ### Register Shop at Runtime Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Guides/shops.mdx Adds a new shop dynamically on the server using `RegisterShop`. Client-only features like blips and zones are not supported. ```lua exports.ox_inventory:RegisterShop('TestShop', { name = 'Test shop', inventory = { { name = 'burger', price = 10 }, { name = 'water', price = 10 }, { name = 'cola', price = 10 }, }, locations = { vec3(223.832962, -792.619751, 30.695190), }, groups = { police = 0 }, }) ``` -------------------------------- ### Client-Side Point Module Usage Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Points/JavaScript/Client.mdx Example of how to import and use the Point module on the client. It demonstrates setting up a point with custom arguments and defining enter, exit, and nearby callbacks. ```typescript import { Point, cache } from '@overextended/ox_lib/client' function nearby(this: Point<{dunak: string}>) { // @ts-ignore DrawMarker(2, this.coords.x, this.coords.y, this.coords.z, 0, 0, 0, 0, 180, 0, 1, 1, 1, 200, 20, 20, 50, false, true, 2, false, null, null, false) if (this.currentDistance && this.currentDistance < 1 && IsControlJustReleased(0, 38)) { console.log('Inside marker', this.id) console.log(this.args?.dunak) } } const point = new Point({ coords: GetEntityCoords(cache.ped, false), distance: 5, nearby: nearby, args: { dunak: 'nerd' } }) point.onEnter = () => { console.log('Entered range of point', point.id) } point.onExit = () => { console.log('Left range of point', point.id) } ``` -------------------------------- ### Skill Check Usage Example (Lua) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/skillcheck.mdx Demonstrates calling lib.skillCheck with a mix of preset difficulties ('easy', 'hard'), a custom difficulty object, and custom input keys. ```lua local success = lib.skillCheck({'easy', 'easy', {areaSize = 60, speedMultiplier = 2}, 'hard'}, {'w', 'a', 's', 'd'}) ``` -------------------------------- ### Create a shallow copy of a portion of an array Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Array/Shared.mdx Use `lib.array.slice(arr, start, finish)` to create a new array containing a portion of the original array from `start` to `finish`. ```lua lib.array.slice(arr, start, finish) ``` -------------------------------- ### timer:restart Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Timer/Shared.mdx Resets the timer to its initial duration and starts it again. ```APIDOC ## timer:restart ### Description Resets and starts the timer. ### Signature ```lua timer:restart() ``` ### Example ```lua -- this will create a timer that just keeps restarting itself local timer timer = lib.timer(5000, function() print("timer ended") timer:restart() end, true) ``` ``` -------------------------------- ### Clone and Build Ox Lib Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib.mdx Steps to clone the Ox Lib repository and build the web assets. ```bash git clone https://github.com/overextended/ox_lib.git cd ox_lib/web pnpm i pnpm build ``` -------------------------------- ### Get Vehicle Coordinates Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Server/OxVehicle.mdx Returns the current coordinates of the vehicle. ```lua vehicle.getCoords() ``` -------------------------------- ### OxVehicle.get Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Server/OxVehicle.mdx Get the value of a specific key from the vehicle's metadata. ```APIDOC ## OxVehicle.get ### Description Retrieves the value associated with a specific key from the vehicle's metadata. ### Method `get(key)` ### Endpoint N/A (Client-side method) ### Parameters #### Path Parameters - **key** (string) - Required - The metadata key whose value is to be retrieved. ### Request Example ```lua local metadataValue = vehicle.get('someKey') ``` ### Response #### Success Response - **Return Value** (unknown) - The value associated with the provided key. ``` -------------------------------- ### Custom TextUI Styling Example (Lua) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/textui.mdx Shows how to customize the TextUI appearance with options like position, icon, and inline styles in Lua. Note the specific style properties like borderRadius and backgroundColor. ```lua lib.showTextUI('[E] - Pick apple', { position = "top-center", icon = 'hand', style = { borderRadius = 0, backgroundColor = '#48BB78', color = 'white' } }) ``` -------------------------------- ### lib.points.getNearbyPoints Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Points/Lua/Client.mdx Gets an array of all points that are currently within the player's proximity. ```APIDOC ## lib.points.getNearbyPoints ### Description Gets an array of all points that are currently within the player's proximity. ### Returns - **nearbyPoints** (CPoint[]) - An array of CPoint objects that are near the player. ``` -------------------------------- ### Get Open Menu ID Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/menu.mdx Retrieves the identifier of the menu that is currently displayed. ```lua lib.getOpenMenu() ``` -------------------------------- ### Get Player Account Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Server/OxPlayer.mdx Returns the player's default OxAccount object. ```lua player.getAccount() ``` -------------------------------- ### Register and Add Radial Menu Items (JavaScript) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/radial.mdx Demonstrates registering a new radial menu ('police_menu') with several items and then adding global items ('police', 'business_stuff'). Includes an example of an item with a callback function. ```typescript import lib from '@overextended/ox_lib/client' exports('myMenuHandler', (menu, item) => { console.log(menu, item) if (menu === 'police_menu' and item === 1) { console.log('Handcuffs') } }) lib.registerRadial({ id: 'police_menu', items: [ { label: 'Handcuff', icon: 'handcuffs', onSelect: 'myMenuHandler' }, { label: 'Frisk', icon: 'hand' }, { label: 'Fingerprint', icon: 'fingerprint' }, { label: 'Jail', icon: 'bus' }, { label: 'Search', icon: 'magnifying-glass', onSelect: () => { console.log('Search') } } ] }) lib.addRadialItem([ { id: 'police', label: 'Police', icon: 'shield-halved', menu: 'police_menu' }, { id: 'business_stuff', label: 'Business', icon: 'briefcase', onSelect: () => { console.log('Business') } } ]) ``` -------------------------------- ### Clone and Build Ox Core Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core.mdx Follow these commands to clone the Ox Core repository and build the source code. Ensure you have Git, Node.js, and pnpm installed. ```bash git clone https://github.com/overextended/ox_core.git cd ox_core pnpm i pnpm build ``` -------------------------------- ### Get OxPlayer Coordinates Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Client/OxPlayer.mdx Retrieves the player's current 3D coordinates. ```lua player.getCoords() ``` -------------------------------- ### prepare (Callback) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/oxmysql/Functions/prepare.mdx Executes a SQL query asynchronously using a callback function. It accepts the SQL query string, an array of parameters, and a callback function that receives the query results. ```APIDOC ## prepare (Callback) ### Description Executes a SQL query asynchronously using a callback function. It accepts the SQL query string, an array of parameters, and a callback function that receives the query results. ### Method `prepare` ### Parameters - **query** (string) - Required - The SQL query to execute. - **parameters** (array) - Required - An array of values to bind to the placeholders in the query. - **callback** (function) - Required - A function to be called with the query results. ### Response - **response** (any) - The result of the SQL query, passed to the callback function. ### Example ```lua MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', { identifier }, function(response) print(json.encode(response, { indent = true, sort_keys = true })) end) ``` ``` -------------------------------- ### Clone ox_target Repository Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_target.mdx Clone the ox_target resource from its GitHub repository to install it. ```bash git clone https://github.com/overextended/ox_target.git ``` -------------------------------- ### math.interp Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Math/Shared.mdx Calculates an intermediate value between a start and finish value based on an interpolation factor. ```APIDOC ## math.interp ### Description Calculates an intermediate value between `start` and `finish` based on the interpolation `factor`. ### Parameters - **start** (T) - The starting value of the interpolation. - **finish** (T) - The ending value of the interpolation. - **factor** (number) - The interpolation factor between 0 and 1. - `T` can be `number`, `vector2`, `vector3`, or `vector4`. ### Return - result (T) - The interpolated value. ``` -------------------------------- ### Get Vehicle Metadata Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Server/OxVehicle.mdx Retrieves the value of a specific key from the vehicle's metadata. ```lua vehicle.get(key) ``` -------------------------------- ### Get Specific OxPlayer Status Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Client/OxPlayer.mdx Returns the current value of a specified player status. ```lua player.getStatus(statusName) ``` -------------------------------- ### Restart a Timer Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Timer/Shared.mdx Resets the timer to its initial state and starts it again. This is useful for creating repeating timers. ```lua timer:restart() ``` ```lua -- this will create a timer that just keeps restarting itself local timer timer = lib.timer(5000, function() print("timer ended") timer:restart() end, true) ``` -------------------------------- ### Get Vehicle Properties Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/VehicleProperties/Client.mdx Retrieves the properties of a specified vehicle. Requires the vehicle handle as input. ```typescript lib.getVehicleProperties(vehicle) ``` ```lua lib.getVehicleProperties(GetVehiclePedIsUsing(PlayerPedId())) ``` ```typescript import lib from '@overextended/ox_lib/client' lib.getVehicleProperties(GetVehiclePedIsUsing(PlayerPedId())) ``` -------------------------------- ### Handle Item Usage Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Guides/metadata.mdx Implement server-side logic to handle item usage events. This example shows how to access and print the metadata of an item when it's used. ```lua exports('pokemon_card', function(event, item, inventory, slot, data) if event == 'usingItem' then local itemSlot = exports.ox_inventory:GetSlot(inventory.id, slot) print(json.encode(itemSlot.metadata, {indent=true})) end end) ``` -------------------------------- ### Get All Created Points Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Points/Lua/Client.mdx Retrieves a table containing all points that have been created by the resource using `lib.points.new`. ```lua lib.points.getAllPoints() ``` -------------------------------- ### Get Specific Player License Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Server/OxPlayer.mdx Retrieves detailed information about a specific player license by its name. ```lua player.getLicense(licenseName: string): object ``` -------------------------------- ### Register and Add Radial Menu Items (Lua) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/radial.mdx Demonstrates registering a new radial menu ('police_menu') with several items and then adding global items ('police', 'business_stuff'). Includes an example of an item with a callback function. ```lua exports('myMenuHandler', function(menu, item) print(menu, item) if menu == 'police_menu' and item == 1 then print('Handcuffs') end end) lib.registerRadial({ id = 'police_menu', items = { { label = 'Handcuff', icon = 'handcuffs', onSelect = 'myMenuHandler' }, { label = 'Frisk', icon = 'hand' }, { label = 'Fingerprint', icon = 'fingerprint' }, { label = 'Jail', icon = 'bus' }, { label = 'Search', icon = 'magnifying-glass', onSelect = function() print('Search') end } } }) lib.addRadialItem({ { id = 'police', label = 'Police', icon = 'shield-halved', menu = 'police_menu' }, { id = 'business_stuff', label = 'Business', icon = 'briefcase', onSelect = function() print("Business") end } }) ``` -------------------------------- ### Get Vehicle from VIN Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Functions/server.mdx Retrieves an OxVehicle object using its Vehicle Identification Number (VIN). ```lua Ox.GetVehicleFromVin(vin) ``` -------------------------------- ### Define and Use Classes with Inheritance Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Class/Shared.mdx Demonstrates defining a base class 'Person' and derived classes 'Professor' and 'Student' that inherit from it. Shows constructor usage, method overriding, and accessing private fields. ```lua ---@class Person : OxClass ---@field name string local Person = lib.class('Person') function Person:constructor(name) print('calling Person constructor for', name) self.name = name end -- Professor Class (extends Person) ---@class Professor : Person ---@field teaches string local Professor = lib.class('Professor', Person) function Professor:constructor(name, teaches) print('calling Professor constructor for', name) self:super(name) self.teaches = teaches end function Professor:introduceSelf() print(("My name is %s, and I will be your %s professor."):format(self.name, self.teaches)) end function Professor:grade(paper) local grade = math.random(1, 4) print(grade) end CreateThread(function() local walter = Professor:new('Walter', 'Chemistry') walter:introduceSelf() walter:grade('my paper') end) -- Student Class (extends Person) ---@class Student : Person ---@field private private { year: number } local Student = lib.class('Student', Person) ---@param name string ---@param year number function Student:constructor(name, year) print('calling Student constructor for', name) self:super(name) self.private.year = year end function Student:introduceSelf() print(("Hi! I'm %s, and I'm in year %s."):format(self.name, self.private.year)) end ---@param year number function Student:setYear(year) self.private.year = year end CreateThread(function() local jesse = Student:new('Jesse', 2) jesse:introduceSelf() -- Hi! I'm Jesse, and I'm in year 2. jesse:setYear(3) jesse:introduceSelf() -- Hi! I'm Jesse, and I'm in year 3. print(jesse.private.year) -- nil print(getmetatable(jesse.private)) -- private jesse.private.year = 4 -- error end) ``` -------------------------------- ### Get Vehicle Properties Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Server/OxVehicle.mdx Returns the vehicle's properties object, which includes modifications and extras. ```lua vehicle.getProperties() ``` -------------------------------- ### Show Menu Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/menu.mdx Displays a menu with the specified ID. Ensure the menu is registered before attempting to show it. ```lua lib.showMenu(id) ``` -------------------------------- ### Bandage Item Usage Example Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_inventory/Functions/Client.mdx Demonstrates how to implement the 'useItem' function for a bandage, including checks for player health and applying the healing effect via a callback. ```lua exports('bandage', function(data, slot) local playerPed = PlayerPedId() local maxHealth = GetEntityMaxHealth(playerPed) local health = GetEntityHealth(playerPed) -- Does the ped need to heal? if health < maxHealth then -- Use the bandage exports.ox_inventory:useItem(data, function(data) -- The item has been used, so trigger the effects if data then SetEntityHealth(playerPed, math.min(maxHealth, math.floor(health + maxHealth / 16))) lib.notify({description = 'You feel better already'}) end end) else -- Don't use the item lib.notify({type = 'error', description = 'You don\'t need a bandage right now'}) end end) ``` -------------------------------- ### lib.getNearbyObjects Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/GetNearbyObjects/Shared.mdx Gets the object handle and coordinates of all objects within a specified range from a given set of coordinates. ```APIDOC ## lib.getNearbyObjects ### Description Retrieves the object handle and coordinates for all objects located within a specified distance from a given set of coordinates. ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Method N/A (Lua function call) ### Endpoint N/A (Lua function call) ### Parameters #### Function Parameters - **coords** (vector3) - Required - The coordinates from which to check for nearby objects. - **maxDistance** (number) - Optional - The maximum distance to search for objects. Defaults to 2.0. ### Request Example ```lua local nearbyObjects = lib.getNearbyObjects(vector3(100.0, 200.0, 30.0), 50.0) ``` ### Response #### Success Response - **objects** ( `{ object: number, coords: vector3 }[]` ) - An array of objects, where each object contains its handle and coordinates. ``` -------------------------------- ### Get Vehicle Statebag Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Server/OxVehicle.mdx Returns the interface for the vehicle's statebag, used for managing real-time state. ```lua vehicle.getState() ``` -------------------------------- ### Include Ox Lib in fxmanifest.lua (Lua) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib.mdx Include the Ox Lib initialization script in your fxmanifest.lua file as a shared_script. ```lua shared_scripts { '@ox_lib/init.lua', } ``` ```lua shared_script '@ox_lib/init.lua' ``` -------------------------------- ### Get All OxPlayer Statuses Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Client/OxPlayer.mdx Returns an object containing all of the player's statuses, with status names as keys. ```lua player.getStatuses() ``` -------------------------------- ### Get All OxPlayer Groups Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Client/OxPlayer.mdx Returns an object containing all groups the player is a member of, with group names as keys. ```lua player.getGroups() ``` -------------------------------- ### Get Closest Door Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_doorlock/Client/functions.mdx Retrieves information about the nearest door. The returned value is a number representing the door. ```lua exports.ox_doorlock:getClosestDoor() ``` -------------------------------- ### Create Account Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Functions/server.mdx Creates a new account for a character using their owner ID and a label. ```lua Ox.CreateAccount(ownerId, label) ``` -------------------------------- ### Get Points Near the Player Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Points/Lua/Client.mdx Fetches an array of all points that are currently within the player's proximity range. ```lua lib.points.getNearbyPoints() ``` -------------------------------- ### Show Context Menu Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/context.mdx Opens a registered context menu by its ID. Use this to display a specific menu to the user. ```lua lib.showContext(id) ``` -------------------------------- ### Registering Context Menu from Event Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/context.mdx Registers a context menu dynamically when a specific network event is received. This allows for menus to be created based on game state or player actions. The `args` from the event are passed to the menu options. ```lua RegisterNetEvent('test_event', function(args) lib.registerContext({ id = 'event_menu', title = 'Event menu', menu = 'some_menu', options = { { title = 'Event value: '..args.someValue, } } }) lib.showContext('event_menu') end) ``` ```typescript onNet('test_event', (args: { someValue: number }) => { lib.registerContext({ id: 'event_menu', title: 'Event menu', menu: 'some_menu', options: [ { title: `Event value: ${args.someValue}`, }, ], }); lib.showContext('event_menu'); }); ``` -------------------------------- ### Get Open Menu ID (JavaScript) Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/menu.mdx Retrieves the identifier of the menu that is currently displayed using the JavaScript API. ```ts import lib from '@overextended/ox_lib/client'; lib.getOpenMenu(); ``` -------------------------------- ### Displaying a Context Menu via Command Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Interface/Client/context.mdx Registers a command that, when executed, displays a specified context menu. This is useful for testing or triggering menus manually. ```lua RegisterCommand('testcontext', function() lib.showContext('some_menu') end) ``` ```typescript RegisterCommand('testcontext', () => { lib.showContext('some_menu'); }); ``` -------------------------------- ### Get Closest Player Function Signature Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/GetClosestPlayer/Shared.mdx This snippet shows the function signature for lib.getClosestPlayer. It outlines the parameters and their types. ```lua lib.getClosestPlayer(coords, maxDistance, includePlayer) ``` -------------------------------- ### Loading an External Module Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_lib/Modules/Require/Shared.mdx Demonstrates loading a module from an external resource ('@mylib.import'). The imported module's data is then accessed. ```lua local mylib = require '@mylib.import' print(mylib.events.disconnect) ``` -------------------------------- ### Get OxPlayer Group by Type Source: https://github.com/esx-framework/overextended.github.io/blob/main/pages/ox_core/Classes/Client/OxPlayer.mdx Returns the player's name and grade for a group that matches the specified type. ```lua player.getGroupByType(type) ```