### Client-side Script Example (`client.lua`) Source: https://docs.esx-framework.org/en/tutorial/developing Example of a client-side Lua script for an ESX framework in FiveM. It demonstrates registering a command using FiveM's native `RegisterCommand`, printing a configuration value, and checking if the player is loaded using `ESX.IsPlayerLoaded()`. ```lua -- Using the native from fivem since ESX.RegisterCommand doesn't exist on the clientside -- This command won't exist on the serverside, so you won't be able to use it in the console. RegisterCommand('clientTest', function () print(Config.cool) if ESX.IsPlayerLoaded() then print("Player has already loaded") else print("Player is not loaded") end end, false) ``` -------------------------------- ### ESX Impound Configuration Example Source: https://docs.esx-framework.org/en/esx_addons/esx_garage Illustrates the configuration for impound lots in esx_garage. It specifies points for getting out of impounded vehicles, spawn points, visual properties, and the cost to retrieve a vehicle. ```lua Config.Impounds = { ImpoundName = { GetOutPoint = {x = 0.0, y = 0.0, z = 0.0}, SpawnPoint = {x = 0.0, y = 0.0, z = 0.0, heading = 0.0}, Sprite = 357, Scale = 0.8, Colour = 3, Cost = 3000, } } ``` -------------------------------- ### Server-side Script Example (`server.lua`) Source: https://docs.esx-framework.org/en/tutorial/developing Example of a server-side Lua script for an ESX framework in FiveM. It showcases `ESX.RegisterCommand` for registering commands, accessing player information like name and job, printing configuration values, and defining command help text. ```lua -- Command introduced by ESX to register commands more easily -- For more information see the accoring docs for ESX.RegisterCommand ESX.RegisterCommand('test', 'user', function(xPlayer, args, showError) print(xPlayer.getName() .. " has the job " .. xPlayer.job.label) print(Config.cool) end, true, {help = 'My cool test command!'}) ``` -------------------------------- ### Set Starting Inventory Items Source: https://docs.esx-framework.org/en/esx_core/es_extended/config/main Specifies the items and quantities players receive at the start of the game. Can be set to 'false' to provide no items, or a table listing items and their counts. ```lua StartingInventoryItems = { bread = 2, -- Give the player 2 bread buns water = 4 -- Give the player 4 water bottles } ``` -------------------------------- ### Example: Interact and Show/Hide Text UI (ESX) Source: https://docs.esx-framework.org/en/esx_core/esx_textui An example demonstrating how to show a Text UI message when a player is near an interaction point and hide it when they move away or interact. Uses ESX.TextUI and ESX.HideUI. ```lua local interactCoords = vector3(0, 0, 0) CreateThread(function() local TextUI while true do local coords = GetEntityCoords(PlayerPedId()) local inDist = #(coords - interactCoords) < 2.0 if inDist and not TextUI then ESX.TextUI('Press [E] to interact') elseif inDist and TextUI then ESX.HideUI() end Wait(500) end end) ``` -------------------------------- ### Lua Infinite Loop Example (Avoid) Source: https://docs.esx-framework.org/en/tutorial/coding_practices Provides an example of an infinite `while true` loop in Lua that should be avoided. Such loops can lead to server crashes or lag if not properly managed with conditions or Wait times. ```lua CreateThread(function() while true do Wait(0) if ESX.PlayerData.job.name == 'police' then if IsControlJustPressed(0, 38) then -- Do something end end end end) ``` -------------------------------- ### ESX Menu onSelect Callback Example Source: https://docs.esx-framework.org/en/esx_core/esx_menu_default An example of the onSelect callback function for ESX menus. This function is executed when a menu element is selected. It receives the selected data and the menu object, allowing actions based on the element's name or value, and provides methods to close the menu. ```lua function(data, menu) --- for a simple element if data.current.name == "element1" then print("Element 1 Selected") menu.close() end -- for slider elements if data.current.name == "bread" then print(data.current.value) end end ``` -------------------------------- ### Example: Interact and Show/Hide Text UI (Export) Source: https://docs.esx-framework.org/en/esx_core/esx_textui An example demonstrating interaction-based Text UI control using the export functions. It shows a message when the player is close to a point and hides it when they move away. Uses exports['esx_textui']:TextUI and exports['esx_textui']:HideUI. ```lua local interactCoords = vector3(0, 0, 0) CreateThread(function() local TextUI while true do local coords = GetEntityCoords(PlayerPedId()) local inDist = #(coords - interactCoords) < 2.0 if inDist and not TextUI then exports['esx_textui']:TextUI('Press [E] to interact') elseif inDist and TextUI then exports['esx_textui']:HideUI() end Wait(500) end end) ``` -------------------------------- ### Get All Usable Items Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/functions Returns a table listing all items that are registered as usable. The table keys are item names, and the values are booleans indicating usability. ```lua local usableItems = ESX.GetUsableItems() for item, usable in pairs(usableItems) do if usable then print("Item " .. item .. " is usable") else print("Item " .. item .. " is not usable") end end ``` -------------------------------- ### Get Weapon Tint (Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/xplayer Retrieves the current tint index for a specified weapon. If a third-party inventory is installed, their metadata system should be consulted. ```Lua local xPlayer = ESX.GetPlayerFromId(playerId) print("Player's 50. Caliber has tint index " .. xPlayer.getWeaponTint("weapon_pistol50")) ``` -------------------------------- ### Accessing Player Ped Handle (Server & Client) Source: https://docs.esx-framework.org/en/esx_core/es_extended/playerdata Shows how to get the player's ped handle, which is used for interacting with the player entity in the game world. Examples are provided for both server and client-side access. ```lua -- Server Example local xPlayer = ESX.GetPlayerFromId(source) local playerHealth = GetEntityHealth(xPlayer.ped) print("player has " .. playerHealth .. " hp") -- Client Example local playerHealth = GetEntityHealth(ESX.PlayerData.ped) print("player has " .. playerHealth .. " hp") ``` -------------------------------- ### ESX Garage Configuration Example Source: https://docs.esx-framework.org/en/esx_addons/esx_garage Defines the structure for configuring garages within the esx_garage resource. This includes setting entry and spawn points, sprite, scale, color, and the name for impounded vehicles. ```lua Config.Garages = { GarageName = { EntryPoint = {x = 0.0, y = 0.0, z = 0.0}, SpawnPoint = {x = 0.0, y = 0.0, z = 0.0, heading = 0.0}, Sprite = 357, Scale = 0.8, Colour = 3, ImpoundedName = "impoundName" } } ``` -------------------------------- ### Retrieve Shared Account (Event) Source: https://docs.esx-framework.org/en/esx_addons/esx_addonaccount This example shows how to get a shared account by triggering the 'esx_addonaccount:getSharedAccount' event. It requires the account name and a callback function to process the account. ```lua TriggerEvent('esx_addonaccount:getSharedAccount', name, cb) ``` -------------------------------- ### Configuration File Example (`config.lua`) Source: https://docs.esx-framework.org/en/tutorial/developing A simple Lua configuration file for an ESX script. It defines a global `Config` table containing various settings, such as a 'cool' property used for demonstration purposes in client and server scripts. ```lua Config = { cool = "This is very cool" } ``` -------------------------------- ### Get Player List Source: https://docs.esx-framework.org/en/esx_core/es_extended/commands Retrieves a list of all players with their ID, RP Name, Group, and Identifier. ```APIDOC ## GET /players ### Description Prints the `ID`, `RP Name`, `Group` and `Identifier` of all players. ### Method GET ### Endpoint /players ### Response #### Success Response (200) - **players** (array) - An array of player objects. - **ID** (number) - The unique identifier for the player. - **RP Name** (string) - The role-playing name of the player. - **Group** (string) - The group the player belongs to. - **Identifier** (string) - The player's identifier. #### Response Example ```json { "players": [ { "ID": 1, "RP Name": "JohnDoe", "Group": "Admin", "Identifier": "steam:12345" }, { "ID": 2, "RP Name": "JaneSmith", "Group": "Member", "Identifier": "license:abcde" } ] } ``` ``` -------------------------------- ### ESX Function Notification Example Source: https://docs.esx-framework.org/en/esx_core/esx_notify Demonstrates how to display a notification using the ESX.ShowNotification function. This function takes the message, type, length, optional title, and optional position as arguments. ```lua ESX.ShowNotification("message here", "success", 3000, "title here", "top-left") ``` -------------------------------- ### Get Licenses List Event (Callback) - Lua Source: https://docs.esx-framework.org/en/esx_addons/esx_license Triggers an event to fetch a list of all available license types. It requires a callback function that receives a table containing the license names. ```lua TriggerEvent('esx_license:getLicensesList', function(licenses) end) ``` -------------------------------- ### Get All Registered Items Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/functions Retrieves a table containing all items registered in the ESX framework. Each item entry includes its data, such as weight. ```lua local items = ESX.GetItems() for item, data in pairs(items) do print("Item " .. item .. " has a weight of " .. data.weight) end ``` -------------------------------- ### ESX Notify Export Notification Example Source: https://docs.esx-framework.org/en/esx_core/esx_notify Shows how to trigger notifications using the esx_notify export. This method requires the notification type, message, length, optional title, and optional position. ```lua exports['esx_notify']:Notify('error', 'This is my new test.', 1500, "Test Notification", "top-left") ``` -------------------------------- ### Get All Licenses Event (Callback) - Lua Source: https://docs.esx-framework.org/en/esx_addons/esx_license Triggers an event to retrieve all licenses associated with a target player. It requires the target player's identifier and a callback function that receives a table of licenses. ```lua TriggerEvent('esx_license:getLicenses', source, function(licenses) end) ``` -------------------------------- ### Get Metadata (Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/xplayer Retrieves a meta value for the player using an index and optionally a sub-index. If no index is provided, it returns all metadata. ```Lua local xPlayer = ESX.GetPlayerFromId(playerId) print("Player has the " .. xPlayer.getMeta("title") .. " title!") ``` -------------------------------- ### ESX Trace Function Example Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/functions Prints a message to the server console if Debug is enabled in the ESX configuration. It takes a string message as input and is useful for debugging server-side logic. ```lua local xPlayer = ESX.GetPlayerFromId(playerId) if xPlayer.admin then ESX.Trace(xPlayer.name .. " is an Admin.") -- "[TRACE] John Doe is an Admin." when Debug is enabled. end ``` -------------------------------- ### Get Item Label by Item Name Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/functions Retrieves the display label for a given item name. It takes the item name as input and returns its corresponding label string. ```lua local jetonLabel = ESX.GetItemLabel("jeton") print("The play chips of the casino are called "..jetonLabel) ``` -------------------------------- ### Register Server Callback Example Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/functions Registers a server-side callback function that can be invoked by a client. This is used for sending data from the server to the client after processing client requests. ```lua local myMemeServer = 'Meme data string' -- The first argument of the handler function is the player source (NetID), -- cb is the callback function we call when we want to return data to client -- subsequent parameters were the arguments called from the client. ESX.RegisterServerCallback('myScript:getMeme', function(src, cb, param1, param2) -- Logic needed to derive whatever data you would like to send back -- using the passed params on the handler (src, param1, param2, etc) -- Send back our meme data to client handler cb(myMemeServer) end) ``` -------------------------------- ### Await Client Callback Example Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/functions Triggers a client callback and pauses script execution until a response is received from the client. This function should be used cautiously due to the untrusted nature of client-provided data. ```lua local vehicleType = ESX.AwaitClientCallback(player, "esx:getVehicleType", "bati") print(("The bati is a %s"):format(vehicleType)) ``` -------------------------------- ### Get All Registered Jobs Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/functions Returns a table containing all registered jobs within the ESX framework. Each job entry includes its name, label, and a table of grades with their respective details. ```lua local jobs = ESX.GetJobs() for jobName, jobData in pairs(jobs) do print(jobName .. " found with grade 0 called: " .. jobData.grades["0"].label) end ``` -------------------------------- ### Get Available Skin Components (ESX Skinchanger) Source: https://docs.esx-framework.org/en/esx_core/skinchanger Retrieves a list of available clothing components and their maximum values for the skinchanger. It uses a callback function to return the data. ```lua TriggerEvent('skinchanger:getData', function(components, maxVals) print(('Components => %s'):format(json.encode(components))) print(('MaxVals => %s'):format(json.encode(maxVals))) end) ``` -------------------------------- ### Get Player Playtime in Lua Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/xplayer This function retrieves the total playtime of a player in seconds and provides an example of how to format this into days, hours, and minutes. ```lua local xPlayer = ESX.GetPlayerFromId(playerId) local playtime = xPlayer.getPlayTime() local days = math.floor(playtime / 86400) local hours = math.floor((playtime % 86400) / 3600) local minutes = math.floor((playtime % 3600) / 60) print(("Playtime: ^5%s^0 Days | ^5%s^0 Hours | ^5%s^0 Minutes"):format(days, hours, minutes)) ``` -------------------------------- ### Show Notification (Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/xplayer Triggers a display notification to the player. Arguments include message, type, length, and optional title and position. Example shows a basic info notification. ```Lua local xPlayer = ESX.GetPlayerFromId(playerId) xPlayer.showNotification("You have been invited to a round of DnD", "info", 3000, "Test title", "top-left") ``` -------------------------------- ### Add Money to Shared Account (Export) Source: https://docs.esx-framework.org/en/esx_addons/esx_addonaccount This example retrieves a shared account using the exported function 'GetSharedAccount' and adds money to it. It only requires the name of the shared account. ```lua local account = exports['esx_addonaccount']:GetSharedAccount('society_realestateagent') account.addMoney(500) ``` -------------------------------- ### Access Player Last Name (Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/playerdata Retrieves and prints the player's last name. This example demonstrates accessing player data from both server and client contexts. ```lua local xPlayer = ESX.GetPlayerFromId(source) print("The character is called: " .. xPlayer.firstName .. " " .. xPlayer.lastName) ``` ```lua print("The character is called: " .. ESX.PlayerData.firstName .. " " .. xPlayer.lastName) ``` -------------------------------- ### Trigger Client Callback Example Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/functions Triggers a specific callback event on a designated client and provides a function to handle the response. Use with caution as client data should not be trusted for sensitive operations. ```lua ESX.TriggerClientCallback(player, "esx:GetVehicleType", function(vehicleType) print("The bati is a " .. vehicleType) -- "The bati is a bike" end, "bati") ``` -------------------------------- ### Shop Zone Configuration Example (Lua) Source: https://docs.esx-framework.org/en/esx_addons/esx_shops This snippet demonstrates the structure for defining a shop zone in the esx_shops configuration. It specifies shop items, their prices, location, and visual properties like blip and marker settings. Configuration is done within the Config.lua file. ```lua shopName: string = { Items = { { name: string = "bread", label: string = "Bread", price: number = 5 } }, Pos: vector3[] = { vector3(0.0, 0.0, 0.0) }, Size: number = 0.8 -- Blip Size Type: number = 59 -- Blip Type Color: number = 25 -- Blip Color ShowBlip: boolean = true -- Show Blip on Map ShowMarker: boolean = true -- Show Marker } ``` -------------------------------- ### ESX Server Trigger Notification Example Source: https://docs.esx-framework.org/en/esx_core/esx_notify Illustrates how to send a notification to a specific client from the server using TriggerClientEvent. This method requires the player ID, message, type, length, optional title, and optional position. ```lua TriggerClientEvent("esx:showNotification", playerId, "This is my new test.", "error", 1500, "Test Notification", "top-left") ``` -------------------------------- ### Get ESX Configuration (Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/shared Retrieves the entire ESX configuration table or a specific configuration value using a key. Useful for accessing framework settings. The 'key' argument is an optional string. ```lua -- Getting whole config: local config = ESX.GetConfig() -- Checking if EnableDebug is enabled local debugEnabled = ESX.GetConfig("EnableDebug") ``` -------------------------------- ### Check if Vehicle is Empty using ESX.Game Source: https://docs.esx-framework.org/en/esx_core/es_extended/client/modules/game Determines if a given vehicle is empty, returning a boolean value. It takes a vehicle handle as input. The example shows how to get the player's current vehicle and check if it's empty. ```lua local vehicle = GetVehiclePedIsIn(PlayerPedId(), true) local isEmpty = ESX.Game.IsVehicleEmpty(vehicle) if isEmpty then print('Vehicle is empty!') end ``` -------------------------------- ### FiveM Script Manifest (`fxmanifest.lua`) Source: https://docs.esx-framework.org/en/tutorial/developing Example of an `fxmanifest.lua` file for a FiveM script using the ESX framework. It specifies the FX manifest version, game, script metadata, Lua version, and lists shared, client, server scripts, and dependencies like `es_extended`. ```lua -- This file is always required for a fivem script fx_version 'cerulean' game 'gta5' description 'My really cool script' author 'My name' lua54 'yes' -- Not always needed, needed for functions that require Lua 5.4 -- Files that should be loaded on both server and client. -- DO NOT LOAD CONFIGS/FILES CONTAINING SENSITIVE DATA LIKE API KEYS AND WEBHOOKS HERE. shared_scripts { 'config.lua' -- Not needed but suggested to not hardcode everything. } client_scripts { 'client.lua', } server_scripts { 'server.lua', } shared_scripts { '@es_extended/imports.lua', -- Import ESX functions and PlayerData '@es_extended/locale.lua', -- Import the Locale system } dependencies { 'es_extended' -- Ensure the script starts after es_extended so that the functions work. } ``` -------------------------------- ### Registering and Using Player Interactions in ESX Source: https://docs.esx-framework.org/en/esx_core/es_extended/client/modules/interactions This example demonstrates how to register a new player interaction in the ESX framework. It includes setting up a point of interaction, defining conditions for interaction, and registering the interaction with a callback function. This is useful for creating interactive elements in the game world. ```lua local canInteract = false local point = ESX.Point:new({ coords = vec3(0, 0, 0), hidden = false, enter = function() canInteract = true ESX.TextUI(("Press [%s] to interact"):format(ESX.GetInteractKey())) end, leave = function() canInteract = false ESX.HideUI() end }) ESX.RegisterInteraction('my_interaction', function() print('Interaction pressed') end, function() return canInteract end) ``` -------------------------------- ### Get Player Name (Server-side Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/playerdata Retrieves and prints the player's name on the server-side. It uses ESX.GetPlayerFromId(source) to get the player object and then accesses its 'name' property. ```lua local xPlayer = ESX.GetPlayerFromId(source) print("The player is called: " .. xPlayer.name) ``` -------------------------------- ### Enable Service (Lua) Source: https://docs.esx-framework.org/en/esx_addons/esx_service Enables a player to go on duty for a specified service. It uses a server callback to check service capacity and provides feedback via notifications. Dependencies include the ESX framework. ```lua ESX.TriggerServerCallback('esx_service:enableService', function(canTakeService, maxInService, inServiceCount) if canTakeService then ESX.ShowNotification('You enabled service') else ESX.ShowNotification('Service is full: ' .. inServiceCount .. '/' .. maxInService) end end, 'taxi') ``` -------------------------------- ### Accessing Player Coordinates (Server & Client) Source: https://docs.esx-framework.org/en/esx_core/es_extended/playerdata Illustrates how to access a player's current coordinates (x, y, z) and heading. The server example uses ESX.GetPlayerFromId, while the client example uses ESX.PlayerData. This is useful for proximity checks or location-based logic. ```lua -- Server Example local xPlayer = ESX.GetPlayerFromId(source) local pos = vector3(xPlayer.coords.x, xPlayer.coords.y, xPlayer.coords.z) if #(pos - vector3(124, 152, 26)) < 5 then print("Player is in the range of 5 meters!") end -- Client Example local pos = vector3(ESX.PlayerData.coords.x, ESX.PlayerData.coords.y, ESX.PlayerData.coords.z) if #(pos - vector3(124, 152, 26)) < 5 then print("Player is in the range of 5 meters!") end ``` -------------------------------- ### VSCode Lua Settings Source: https://docs.esx-framework.org/en/tutorial/developing Recommended settings for the sumneko.lua VSCode extension to improve Lua development experience within FiveM projects. These settings disable specific diagnostics that may not be relevant or can cause false positives in the ESX environment. ```json { "Lua.diagnostics.disable": [ "undefined-global", "err-nonstandard-symbol", "unknown-symbol" ] } ``` -------------------------------- ### ESX Menu Cancel Callback Example Source: https://docs.esx-framework.org/en/esx_core/esx_menu_default An example of the cancel callback function for ESX menus. This function is triggered when the menu is closed, either by selection or explicit cancellation. It receives the data and menu object, allowing for cleanup or notification actions before the menu is fully closed. ```lua function(data, menu) print("Closing Menu - " .. menu.title) menu.close() -- close menu end ``` -------------------------------- ### Defining Zones for Accessory Shops in ESX Source: https://docs.esx-framework.org/en/esx_addons/esx_accessories This Lua configuration sets up the zones for accessory shops. It defines the name of the accessory and its position in the game world, which is crucial for triggering shop interactions when a player enters the zone. ```lua Config.Zones = { AccessoryName = { Pos = { vector3(-1338.1, -1278.2, 3.8) } } } ``` -------------------------------- ### Getting the Global Interact Key in ESX Source: https://docs.esx-framework.org/en/esx_core/es_extended/client/modules/interactions This code snippet shows how to retrieve the global interact key used in the ESX framework. The default key is 'E', but this function allows you to dynamically get the currently configured key. This is useful for displaying interaction prompts to the player. ```lua local key = ESX.GetInteractKey() print("Interact key: " .. key) ``` -------------------------------- ### Lua Loop with Condition and Wait (Recommended) Source: https://docs.esx-framework.org/en/tutorial/coding_practices Shows a recommended pattern for Lua loops using a conditional `while` statement and `Wait(0)` to prevent server crashes. This structure ensures the loop only runs when the condition is met and yields execution appropriately. ```lua AddEventHandler('esx:setJob', function(job) if job.name == 'police' then startPoliceThread() end end) local function startPoliceThread() CreateThread(function() while ESX.PlayerData.job.name == 'police' do Wait(0) if IsControlJustPressed(0, 38) then -- Do something end end end) end if ESX.PlayerData.job.name == 'police' then startPoliceThread() end ``` -------------------------------- ### Custom AI License Plate Pattern Example (Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/config/adjustments Defines the pattern for license plates generated for non-player (NPC) vehicles within the ESX framework. This Lua example demonstrates how to use special characters for random numbers, letters, or literal characters to create unique plate formats. ```lua CustomAIPlates = "ESX-^11EA" -- Example outcome: ESX-15EG ``` -------------------------------- ### Exports Source: https://docs.esx-framework.org/en/esx_addons/esx_garage Exported functions available from the esx_garage resource. ```APIDOC ## Exports ### `getGarages` * **Description:** Returns the `Config.Garages` table. * **Usage:** ```lua local garages = exports['esx_garage']:getGarages() ``` ### `getImpounds` * **Description:** Returns the `Config.Impounds` table. * **Usage:** ```lua local impounds = exports['esx_garage']:getImpounds() ``` ``` -------------------------------- ### OpenContext API Source: https://docs.esx-framework.org/en/esx_core/esx_context Opens a context menu and enables mouse focus. This function allows for customizable menus with different element types, positions, and callbacks for selection and closing. ```APIDOC ## OpenContext API ### Description Opens a context menu and enables mouse focus. This function allows for customizable menus with different element types, positions, and callbacks for selection and closing. ### Method `ESX.OpenContext(position, elements, canClose?, onSelect, onClose)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **position** (string) - Required - The position the context should be displayed at. Accepted values: 'left', 'center', 'right'. - **elements** (table) - Required - Table with the elements that should be displayed in the menu. Each element is an object with properties like `unselectable`, `icon`, `title`, `description`, `input`, `inputType`, `inputPlaceholder`, `inputValue`, `inputMin`, `inputMax`, and `name`. - **canClose** (boolean) - Optional (Default: `true`) - Should the menu be able to be closed? - **onSelect** (function) - Required - Function that gets ran when the client selects an element. - **onClose** (function) - Required - Function that gets ran when the client closes the menu. ### Request Example ```lua ESX.OpenContext('right', { { unselectable = true, icon = 'fas fa-info-circle', title = 'Unselectable Item (Header/Label?)', }, { icon = '', title = 'Input Text', input = true, inputType = 'text', inputPlaceholder = 'Placeholder...', name = 'firstname', }, { icon = 'fas fa-check', title = 'Submit', name = 'submit' } }, function(menu, element) -- Handle selection end, function() -- Handle close end) ``` ### Response #### Success Response (N/A) This function does not return a value but modifies the client's UI. #### Response Example N/A ``` -------------------------------- ### Get Shared Inventory Source: https://docs.esx-framework.org/en/esx_addons/esx_addoninventory Retrieves a shared inventory by its name. This is used for inventories that are not tied to a specific player. ```APIDOC ## esx_addoninventory:getSharedInventory ### Description Retrieves a shared inventory by its name. Shared inventories are accessible by multiple entities and are not tied to a single player. ### Method Server Event (Client-side Trigger) ### Event Name `esx_addoninventory:getSharedInventory` ### Usage `TriggerEvent('esx_addoninventory:getSharedInventory', name, function(inventory)) ### Parameters - **name** (string) - Required - The name of the shared inventory to retrieve. - **function** (function) - Required - A callback function that receives the inventory object. ### Request Example ```lua TriggerEvent('esx_addoninventory:getSharedInventory', 'society_police', function(inventory) inventory.addItem('bread', 1) end) ``` ### Response - **inventory** (object) - An object with methods to interact with the shared inventory (e.g., `addItem`, `removeItem`). ### Response Example (The `inventory` object provided to the callback function) ```lua -- Example of inventory object methods: -- inventory.addItem('item_name', amount) -- inventory.removeItem('item_name', amount) -- inventory.findItems('item_name') ``` ``` -------------------------------- ### Create an ESX Point (Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/client/imports/point Demonstrates how to instantiate a new ESX Point object. This involves defining coordinates, proximity distance, and callback functions for player entry, exit, and continuous presence within the point's radius. Requires the ESX framework. ```lua local point = ESX.Point:new({ coords = vector3(0.0, 0.0, 0.0), distance = 15.0, enter = function() print("Entered point") end, leave = function() print("Left point") end, inside = function(point) local distance = point.currDistance print("Inside point, distance: " .. distance) end }) ``` -------------------------------- ### Get Datastore Data Source: https://docs.esx-framework.org/en/esx_addons/esx_datastore Retrieves data from a specific datastore. This can be a shared datastore or one associated with a specific player. ```APIDOC ## esx_datastore:getDataStore ### Description Retrieves data from a specific user-associated datastore. If the datastore does not exist for the user, it will be created. ### Method Client Event Trigger ### Endpoint `esx_datastore:getDataStore` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua TriggerEvent('esx_datastore:getDataStore', 'property', 'steam:0123456789', function(store) local dressing = store.get('dressing') or {} end) ``` ### Response #### Success Response (200) A datastore object with methods to get and set data. #### Response Example ```lua -- The 'store' object passed to the callback function has methods like: -- store.get(key) -- store.set(key, value) -- store.increment(key, amount) -- store.remove(key) ``` ``` ```APIDOC ## esx_datastore:getSharedDataStore ### Description Retrieves data from a shared datastore, which is not associated with any specific user. ### Method Client Event Trigger ### Endpoint `esx_datastore:getSharedDataStore` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua TriggerEvent('esx_datastore:getSharedDataStore', 'police', function(store) local weapons = store.get('weapons') or {} table.insert(weapons, {name = 'WEAPON_PUMPSHOTGUN', ammo = 50}) store.set('weapons', weapons) end) ``` ### Response #### Success Response (200) A datastore object with methods to get and set data. #### Response Example ```lua -- The 'store' object passed to the callback function has methods like: -- store.get(key) -- store.set(key, value) -- store.increment(key, amount) -- store.remove(key) ``` ``` -------------------------------- ### Configure ESX Barber Shop Prices and Markers Source: https://docs.esx-framework.org/en/esx_addons/esx_barbershop This snippet shows configuration options for the ESX Barber Shop script. It includes settings for the price of services, drawing distance for markers, marker size, and marker color. These settings allow administrators to customize the user experience. ```lua Config.Price = 100 Config.DrawDistance = 10.0 Config.MarkerSize = vector3(1.5, 1.5, 1.0) Config.MarkerColor = { r = 102, g = 102, b = 204 } Config.MarkerType = 1 ``` -------------------------------- ### Get Inventory Source: https://docs.esx-framework.org/en/esx_addons/esx_addoninventory Retrieves a specific inventory, which can be either shared or user-specific. It provides access to inventory manipulation functions. ```APIDOC ## esx_addoninventory:getInventory ### Description Retrieves an inventory by its name and owner. This allows for manipulation of items within that specific inventory. ### Method Server Event (Client-side Trigger) ### Event Name `esx_addoninventory:getInventory` ### Usage `TriggerEvent('esx_addoninventory:getInventory', name, owner, function(inventory)) ### Parameters - **name** (string) - Required - The name of the inventory to retrieve. - **owner** (string) - Required - The identifier of the owner (e.g., player's license, society ID). - **function** (function) - Required - A callback function that receives the inventory object. ### Request Example ```lua TriggerEvent('esx_addoninventory:getInventory', 'property', 'steam:0123456789', function(inventory) inventory.removeItem('water', 1) end) ``` ### Response - **inventory** (object) - An object with methods to interact with the inventory (e.g., `addItem`, `removeItem`). ### Response Example (The `inventory` object provided to the callback function) ```lua -- Example of inventory object methods: -- inventory.addItem('item_name', amount) -- inventory.removeItem('item_name', amount) -- inventory.findItems('item_name') ``` ``` -------------------------------- ### Set Starting Account Money Source: https://docs.esx-framework.org/en/esx_core/es_extended/config/main Determines the initial amount of money each player receives in various accounts upon character creation. This includes standard accounts like 'bank' and 'money', as well as custom accounts like 'bitcoin'. ```lua StartingAccountMoney = { bank = 50000, -- Give the player 50 Thousand on his bank account money = 1500, -- Give the player 1500 cash. black_money = 500, -- Give the player 500 Black money, -- This can also be done with custom accounts: bitcoin = 3.5 -- Give the player 3.5 bitcoins } ``` -------------------------------- ### Get Player Identifier in Lua Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/xplayer This function retrieves the player's unique identifier, typically their Rockstar license. ```lua local xPlayer = ESX.GetPlayerFromId(playerId) local identifier = xPlayer.getIdentifier() ``` -------------------------------- ### Configure Animations in esx_animations Source: https://docs.esx-framework.org/en/esx_addons/esx_animations This Lua code snippet defines the configuration table for animations in the esx_animations script. It allows for categorizing animations and specifying their names, types (scenario, attitude, or anim), and associated animation libraries and names. This configuration is essential for defining the available animations players can perform. ```lua Config.Animations = { { name: string = 'category', label: string = 'Category', items = { { label: string = "Animation Name", type: string = "scenario", -- attitude, scenario, anim data = { anim: string = "anim_lib", lib: string = "lib_name" -- Only for types "anim" and "attitude" } } }, } } ``` -------------------------------- ### Get Account Source: https://docs.esx-framework.org/en/esx_addons/esx_addonaccount Retrieves a specific addon account, which can be either shared or non-shared. This function can be called via client/server event or export. ```APIDOC ## Get Account ### Description Retrieves a specific addon account. This can be a shared account (not belonging to a specific user) or a non-shared account (created for every user). ### Method Client/Server Event or Export ### Endpoint N/A (Event/Export based) ### Parameters #### Event Parameters (`esx_addonaccount:getAccount`) - **name** (string) - Required - The name of the account to retrieve. - **owner** (string) - Optional - The identifier of the account owner (e.g., player identifier). Required for non-shared accounts. - **cb** (function) - Required - A callback function that receives the account object. #### Export Parameters (`exports['esx_addonaccount']:GetAccount`) - **name** (string) - Required - The name of the account to retrieve. - **owner** (string) - Optional - The identifier of the account owner (e.g., player identifier). Required for non-shared accounts. ### Request Example (Event) ```lua TriggerEvent('esx_addonaccount:getAccount', 'society_realestateagent', function(account) account.addMoney(500) end) ``` ### Request Example (Export) ```lua local account = exports['esx_addonaccount']:GetAccount('property_black_money', 'steam:0123456789') account.addMoney(500) ``` ### Response #### Success Response (Callback/Return Value) - **account** (object) - An object representing the account with methods like `addMoney`, `removeMoney`, etc. #### Response Example (Callback) ```lua function(account) -- account object with methods account.addMoney(500) end ``` #### Response Example (Export Return) ```lua -- account object with methods local account = exports['esx_addonaccount']:GetAccount('society_bank') account.removeMoney(100) ``` ``` -------------------------------- ### Get and Set Configuration in esx_animations Source: https://docs.esx-framework.org/en/esx_addons/esx_animations These Lua code snippets demonstrate how to interact with the esx_animations script's exported functions. 'GetConfig' retrieves the current animation configuration table, while 'SetConfig' allows you to update it. These exports are crucial for dynamically managing animations within the framework. ```lua local animations = exports['esx_animations']:GetConfig() ``` ```lua exports['esx_animations']:SetConfig(animations) ``` -------------------------------- ### Get Player SSN in Lua Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/xplayer This function returns the player's Social Security Number (SSN) in the format XXX-XX-XXXX. ```lua local xPlayer = ESX.GetPlayerFromId(playerId) print(xPlayer.getSSN()) -- e.g., "123-45-6789" ``` -------------------------------- ### Configuration for Accessory Shops in ESX Source: https://docs.esx-framework.org/en/esx_addons/esx_accessories This Lua configuration defines settings for accessory shops, including blips for each shop location. It specifies the position and blip properties (sprite and color) for each accessory type available in the game world. ```lua Config.ShopsBlips = { Mask = { Pos = { vector3(-1338.1, -1278.2, 3.8) }, Blip = {sprite = 362, color = 2} } } ``` -------------------------------- ### Get Shared Account Source: https://docs.esx-framework.org/en/esx_addons/esx_addonaccount Retrieves a shared addon account, which does not belong to a specific user. This function can be called via client/server event or export. ```APIDOC ## Get Shared Account ### Description Retrieves a shared addon account. These accounts do not belong to a specific user and are typically used for group or society funds. ### Method Client/Server Event or Export ### Endpoint N/A (Event/Export based) ### Parameters #### Event Parameters (`esx_addonaccount:getSharedAccount`) - **name** (string) - Required - The name of the shared account to retrieve. - **cb** (function) - Required - A callback function that receives the account object. #### Export Parameters (`exports['esx_addonaccount']:GetSharedAccount`) - **name** (string) - Required - The name of the shared account to retrieve. ### Request Example (Event) ```lua TriggerEvent('esx_addonaccount:getSharedAccount', 'society_realestateagent', function(account) account.addMoney(500) end) ``` ### Request Example (Export) ```lua local account = exports['esx_addonaccount']:GetSharedAccount('society_realestateagent') account.addMoney(500) ``` ### Response #### Success Response (Callback/Return Value) - **account** (object) - An object representing the shared account with methods like `addMoney`, `removeMoney`, etc. #### Response Example (Callback) ```lua function(account) -- account object with methods account.removeMoney(200) end ``` #### Response Example (Export Return) ```lua -- account object with methods local account = exports['esx_addonaccount']:GetSharedAccount('society_mechanic') account.addMoney(1000) ``` ``` -------------------------------- ### Configure LSCustom Zones (Lua) Source: https://docs.esx-framework.org/en/esx_addons/esx_lscustom Defines the locations where LSCustoms can be accessed within the game world. Each zone has a position, a blip name, and a hint displayed to the player. This configuration is essential for setting up interactive customization points. ```lua Config.Zones = { ls1 = { Pos = vector3(-337.38, -136.92, 38.57), Name = TranslateCap('blip_name'), Hint = TranslateCap('press_custom') }, } ``` -------------------------------- ### Retrieve Shared Account (Export) Source: https://docs.esx-framework.org/en/esx_addons/esx_addonaccount This example shows how to retrieve a shared account using the exported 'GetSharedAccount' function. It takes the account name as an argument. ```lua exports['esx_addonaccount']:GetSharedAccount(name) ``` -------------------------------- ### Open ESX Menu Client-Side Source: https://docs.esx-framework.org/en/esx_core/esx_menu_default Opens a list-type menu on the client-side using ESX.UI.Menu.Open. Requires menu type, namespace, name, data for elements, and callback functions for selection and cancellation. The data table defines the menu's title, alignment, and selectable elements. ```lua ESX.UI.Menu.Open(type, namespace, name, data, onSelect, cancel ) ``` -------------------------------- ### Get Vehicle in Direction - Lua Source: https://docs.esx-framework.org/en/esx_core/es_extended/client/modules/game Finds a vehicle located directly in front of the player. It does not require any arguments. Returns the handle of the vehicle and its coordinates if found. ```Lua local vehicle, coords = ESX.Game.GetVehicleInDirection() if vehicle then print('Vehicle found!') print('It has ' .. GetEntityHealth(vehicle) .. ' health!') end ``` -------------------------------- ### Get Character Height (Server-side Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/playerdata Retrieves and prints the character's height on the server-side. This value is part of the player's character data. ```lua local xPlayer = ESX.GetPlayerFromId(source) print("The character's height is: " .. xPlayer.height) ``` -------------------------------- ### Show Help Notification - ESX Source: https://docs.esx-framework.org/en/esx_core/es_extended/client/functions Displays a help notification in the top-left corner of the screen. This function can be configured to display only for the current frame or for a specified duration, with an optional beep sound. It's commonly used for in-game instructions or prompts. ```lua RegisterCommand('help', function (source, args, raw) ESX.ShowHelpNotification("We won't give you help, we are truly not sorry.", false, true, 3500) end) ``` -------------------------------- ### Configuration Source: https://docs.esx-framework.org/en/esx_addons/esx_garage Configuration options for the ESX Garage resource, including draw distance, marker settings, garage definitions, and impound definitions. ```APIDOC ## Configuration ### `Config.DrawDistance` * **Type:** float * **Default:** `10.0` * **Description:** The distance in which the garage marker will be drawn. ### `Config.Markers` * **Type:** table * **Description:** The markers that will be drawn on the map. * **Parameters:** * `type` (integer) - The type of the marker. * `size` (table) - The size of the marker. * `x` (float) * `y` (float) * `z` (float) * `color` (rgba) - The color of the marker. ### `Config.Garages` * **Type:** table * **Description:** The garages that will be drawn on the map. * **Layout:** ```lua Config.Garages = { GarageName = { EntryPoint = {x = 0.0, y = 0.0, z = 0.0}, SpawnPoint = {x = 0.0, y = 0.0, z = 0.0, heading = 0.0}, Sprite = 357, Scale = 0.8, Colour = 3, ImpoundedName = "impoundName" } } ``` ### `Config.Impounds` * **Type:** table * **Description:** The impounds that will be drawn on the map. * **Layout:** ```lua Config.Impounds = { ImpoundName = { GetOutPoint = {x = 0.0, y = 0.0, z = 0.0}, SpawnPoint = {x = 0.0, y = 0.0, z = 0.0, heading = 0.0}, Sprite = 357, Scale = 0.8, Colour = 3, Cost = 3000 } } ``` ``` -------------------------------- ### Get Current Player Skin (ESX Skinchanger) Source: https://docs.esx-framework.org/en/esx_core/skinchanger Fetches the current skin data of the local player. A callback function is provided to receive the skin table. ```lua TriggerEvent('skinchanger:getSkin', function(skin) print(('%s'):format(json.encode(skin))) end) ``` -------------------------------- ### Create Pickup in ESX Source: https://docs.esx-framework.org/en/esx_core/es_extended/server/functions Creates a pickup in the game world for a specific item, money, account, or weapon. This function is not available when a third-party inventory system is installed. It requires item type, name, count, label, and player ID, with optional parameters for weapon components and tint index. ```lua ESX.CreatePickup("item_standard", "bread", 5, "Bread", 10) -- Created item pickup with 5 bread at the position of player 10 ``` -------------------------------- ### Get Weapon Label (Lua) Source: https://docs.esx-framework.org/en/esx_core/es_extended/shared Fetches the display label for a given weapon name. Useful for user-facing information. Requires 'weaponName' (string) and returns a string. ```lua local label = ESX.GetWeaponLabel("weapon_pistol") print("Weapon is a: " .. weaponLabel) ``` -------------------------------- ### Get Boat Garages - ESX Lua Source: https://docs.esx-framework.org/en/esx_addons/esx_boat Retrieves the list of available boat garages from the esx_boat resource. This function is part of the exported functions provided by the resource. ```lua local garages = exports['esx_boat']:getGarages() ```