### Configure Server.cfg for Dusa Bridge Installation Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/installation.md This snippet shows how to configure your server.cfg file to ensure Dusa Bridge and its dependencies are loaded correctly. It specifies the order of operations, ensuring the framework and OX Lib are started before Dusa Bridge. ```cfg # Framework (start before bridge) ensure es_extended # or your chosen framework # Dependencies ensure ox_lib # Dusa Bridge (start after dependencies) ensure dusa_bridge # Your other resources (start after bridge) ensure your_custom_resource ``` -------------------------------- ### Dusa Bridge Installation Verification Messages Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/installation.md These console messages indicate a successful installation and configuration of Dusa Bridge. They show the detected framework, inventory, and target systems. ```log [BRIDGE] Version 0.7.8-release [BRIDGE] Framework Detected: esx (or your framework) [BRIDGE] Inventory Detected: ox_inventory (or your inventory) [BRIDGE] Target Detected: ox_target (or your target) ``` -------------------------------- ### Example Menu Structure Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Provides an example of the data structure required to display a menu using the Menu.Show function. This includes a title, description, and event for an item, helping to troubleshoot menus not opening. ```lua Menu.Show({ title = 'Test Menu', items = { { title = 'Option 1', description = 'Test option', event = 'test:event' } } }) ``` -------------------------------- ### Ensure Dusa Bridge Starts First Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Configures the server startup order to ensure the Dusa Bridge resource ('dusa_bridge') is started before your dependent resource. This prevents 'Bridge Must Be Started First' errors. ```cfg # In server.cfg - ensure proper order ensure dusa_bridge ensure your_resource ``` -------------------------------- ### Lua Dusa Bridge Callback Pattern Example Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Demonstrates the standard Lua callback pattern implemented by the Dusa Bridge for inter-resource communication. It shows how to register a server-side callback and how to trigger a callback on the client-side with arguments. ```lua Framework.RegisterCallback('name', serverFunction) Framework.TriggerCallback('name', clientCallback, args) ``` -------------------------------- ### OX Core Integration Usage Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/framework-integration.md Provides examples of using the Dusa Bridge API for player data access and server-side modifications within the OX Core framework. Demonstrates getting player names and updating player money. ```lua -- Get player data local player = Framework.Player print('Player name:', player.get('firstName')) -- Server-side operations local player = Framework.GetPlayer(source) player.set('money', player.get('money') + 1000) ``` -------------------------------- ### QBox Integration Usage Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/framework-integration.md Shows how to utilize the Dusa Bridge API for player data retrieval and server-side operations specific to the QBox framework. Examples include accessing player source and adding cash to a player. ```lua -- Get player data local PlayerData = Framework.Player print('Player source:', PlayerData.source) -- Server-side operations local player = Framework.GetPlayer(source) player.addMoney('cash', 500) ``` -------------------------------- ### Override Configuration Pattern Example in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/context7-overview.md Shows the Override Configuration Pattern in Lua, allowing developers to manually set which framework, inventory, or target systems the bridge should use. This provides flexibility for custom server setups. ```lua -- Flexible configuration system override.framework = 'esx' override.inventory = 'ox_inventory' override.target = 'ox_target' ``` -------------------------------- ### Enable Lua 5.4 in fxmanifest.lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/installation.md This snippet shows how to enable Lua 5.4 for your resource within the fxmanifest.lua file. This is often required by Dusa Bridge or other modern FiveM resources. ```lua fx_version 'cerulean' game 'gta5' -- ... other manifest settings ... lua54 'yes' -- ... rest of your manifest ... ``` -------------------------------- ### Add Dusa Bridge Dependency to fxmanifest.lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/installation.md This Lua snippet demonstrates how to add Dusa Bridge as a dependency in your resource's fxmanifest.lua file. It includes the necessary bridge and shared_scripts directives for integration. ```lua fx_version 'cerulean' game 'gta5' -- Bridge dependency dependency 'dusa_bridge' -- Bridge metadata (required) bridge 'dusa_bridge' -- Bridge integration (required) shared_scripts { '@dusa_bridge/bridge.lua' } -- Your resource files client_scripts { 'client/*.lua' } server_scripts { 'server/*.lua' } ``` -------------------------------- ### Framework Detection Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/framework-integration.md Illustrates how to check the currently detected Dusa Bridge framework at runtime. This allows for conditional logic to execute framework-specific code when needed. ```lua -- Check current framework if Bridge.Framework == 'esx' then -- ESX-specific code elseif Bridge.Framework == 'qb' then -- QBCore-specific code end ``` -------------------------------- ### Unified Target API Zone Management Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/target-systems.md Illustrates zone management using the Unified Target API, specifically how to remove a zone by its name. The example also shows how to create a temporary zone using SetTimeout to automatically remove it after a specified duration. ```lua -- Remove zone Target.RemoveZone(name) -- Example: Temporary event zone local function CreateEventZone() Target.AddCircleZone('event_zone', vector3(0.0, 0.0, 50.0), 10.0, { name = 'event_zone', debugPoly = false }, { options = { { type = 'client', event = 'event:participate', icon = 'fas fa-star', label = 'Join Event' } }, distance = 10.0 }) -- Remove after 30 minutes SetTimeout(30 * 60 * 1000, function() Target.RemoveZone('event_zone') end) end ``` -------------------------------- ### Lua Auto-Detection Algorithm for Dusa Bridge Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Illustrates the priority order for the auto-detection algorithm in the Dusa Bridge resource, starting from manual overrides down to fallback defaults. This logic is crucial for dynamically identifying the framework and systems the bridge needs to interact with. ```lua -- Detection priority order: 1. Manual override configuration 2. Resource state checking 3. Metadata extraction 4. Fallback defaults ``` -------------------------------- ### vRP Integration Usage Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/framework-integration.md Demonstrates the Dusa Bridge API usage for vRP framework, specifically for obtaining user IDs and performing money addition operations. This example is straightforward, directly using framework exports. ```lua -- Get user ID local user_id = Framework.GetUserId(source) -- Money operations Framework.AddMoney(user_id, 1000) ``` -------------------------------- ### Specify Framework and Event for Detection Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Forces the Dusa Bridge to use a specific framework (e.g., ESX) and its associated event for detection. This is useful when multiple frameworks are present or for custom setups, configured in 'override.lua'. ```lua -- In override.lua override.framework = 'esx' -- Force ESX override.frameworkname = 'es_extended' override.frameworkevent = 'esx:getSharedObject' ``` -------------------------------- ### NDCore Integration Usage Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/framework-integration.md Shows a basic example of accessing player data through the Dusa Bridge API when integrated with the NDCore framework, focusing on retrieving character-specific information. ```lua -- Get player data local player = Framework.Player print('Character ID:', player.character.id) ``` -------------------------------- ### Initialize and Manage Properties (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/examples.md Initializes the property system by fetching owned properties and creating interaction zones for each. Handles property management menus, including options for entering, accessing storage, giving keys, and selling, with cross-framework compatibility for inventory access. ```lua -- properties/client.lua local PropertySystem = {} local ownedProperties = {} -- Initialize property system CreateThread(function() Framework.TriggerCallback('properties:getOwnedProperties', function(properties) ownedProperties = properties for _, property in pairs(properties) do CreatePropertyZone(property) end end) end) -- Create property interaction zone function CreatePropertyZone(property) Target.AddBoxZone('property_' .. property.id, property.coords, 2.0, 2.0, { name = 'property_' .. property.id, heading = property.heading or 0, debugPoly = false }, { options = { { type = 'client', event = 'properties:enterProperty', icon = 'fas fa-home', label = 'Enter Property', args = {propertyId = property.id} }, { type = 'client', event = 'properties:manageProperty', icon = 'fas fa-cog', label = 'Manage Property', args = {propertyId = property.id} } }, distance = 2.0 }) end -- Property management menu RegisterNetEvent('properties:manageProperty', function(data) local property = GetPropertyById(data.propertyId) if not property then return end local menuItems = { { title = 'Enter Property', description = 'Enter your property', event = 'properties:enterProperty', args = {propertyId = property.id} }, { title = 'Property Storage', description = 'Access property storage', event = 'properties:openStorage', args = {propertyId = property.id} } } -- Add management options for owner if property.owner == Framework.Player.Identifier then table.insert(menuItems, { title = 'Give Keys', description = 'Give keys to nearby player', event = 'properties:giveKeys', args = {propertyId = property.id} }) table.insert(menuItems, { title = 'Sell Property', description = 'Sell this property', event = 'properties:sellProperty', args = {propertyId = property.id} }) end Menu.Show({ title = property.name, items = menuItems }) end) -- Property storage RegisterNetEvent('properties:openStorage', function(data) local property = GetPropertyById(data.propertyId) if not property then return end local storageId = 'property_' .. property.id if Bridge.Inventory == 'ox_inventory' then exports.ox_inventory:openInventory('stash', storageId) elseif Bridge.Inventory == 'qb-inventory' then TriggerEvent('inventory:client:SetCurrentStash', storageId) TriggerServerEvent('inventory:server:OpenInventory', 'stash', storageId, { maxweight = property.storage_weight or 50000, slots = property.storage_slots or 50 }) end end) -- Utility functions function GetPropertyById(propertyId) for _, property in pairs(ownedProperties) do if property.id == propertyId then return property end end return nil end ``` -------------------------------- ### Create Simple Shop Resource with dusa_bridge (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/examples.md This snippet demonstrates how to create a simple shop resource using Lua for a game environment, leveraging dusa_bridge for event handling and framework integration. It includes client-side scripts for creating shop zones and menus, and server-side scripts for handling purchases. Dependencies include 'dusa_bridge' and a game framework. ```lua -- fxmanifest.lua fx_version 'cerulean' game 'gta5' lua54 'yes' author 'Your Name' description 'Simple Shop' version '1.0.0' -- Bridge dependency dependency 'dusa_bridge' bridge 'dusa_bridge' client_scripts { 'client.lua' } server_scripts { 'server.lua' } ``` ```lua -- client.lua local shopItems = { {name = 'bread', price = 5, label = 'Bread'}, {name = 'water', price = 3, label = 'Water'}, {name = 'sandwich', price = 8, label = 'Sandwich'} } -- Create shop target zone CreateThread(function() Target.AddBoxZone('general_store', vector3(25.7, -1347.3, 29.49), 2.0, 2.0, { name = 'general_store', heading = 0, debugPoly = false, minZ = 28.5, maxZ = 30.5 }, { options = { { type = 'client', event = 'shop:openMenu', icon = 'fas fa-shopping-cart', label = 'Browse Shop' } }, distance = 2.5 }) end) -- Handle shop menu RegisterNetEvent('shop:openMenu', function() local menuItems = {} for _, item in pairs(shopItems) do table.insert(menuItems, { title = item.label, description = 'Price: $' .. item.price, event = 'shop:buyItem', args = {item = item.name, price = item.price} }) end Menu.Show({ title = 'General Store', items = menuItems }) end) -- Handle item purchase RegisterNetEvent('shop:buyItem', function(data) TriggerServerEvent('shop:purchaseItem', data.item, data.price) end) ``` ```lua -- server.lua -- Handle item purchase RegisterNetEvent('shop:purchaseItem', function(itemName, price) local source = source local player = Framework.GetPlayer(source) if not player then return end -- Check if player has enough money local playerMoney = Framework.GetMoney(source, 'cash') if playerMoney >= price then -- Remove money and add item Framework.RemoveMoney(source, 'cash', price) Inventory.AddItem(source, itemName, 1) Framework.Notify(source, 'You purchased ' .. itemName .. ' for $' .. price, 'success') else Framework.Notify(source, 'You don't have enough money', 'error') end end) ``` -------------------------------- ### Debug Zone Creation and Events Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Demonstrates how to create a zone using the Zone.CreateBox function and includes `onEnter` and `onExit` callbacks that print messages to the console. This aids in debugging issues with zone triggering. ```lua local zone = Zone.CreateBox(coords, size, rotation, { onEnter = function() print('Entered zone') end, onExit = function() print('Exited zone') end }) ``` -------------------------------- ### QBox Framework Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet configures the Dusa Bridge for the QBox framework. It specifies the framework type, name, and prefix, enabling the bridge to interact correctly with QBox functionalities. ```lua override.framework = 'qbox' override.frameworkname = 'qbx_core' override.frameworkprefix = 'QBCore' ``` -------------------------------- ### Auto-Detection Pattern Example in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/context7-overview.md Illustrates the Auto-Detection Pattern in Lua, showing how the system identifies and applies logic based on the detected framework. This enables dynamic adaptation to the server's environment. ```lua -- Automatic system detection with fallbacks if Bridge.Framework == 'esx' then -- ESX-specific logic elseif Bridge.Framework == 'qb' then -- QBCore-specific logic end ``` -------------------------------- ### QS-Inventory Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet sets up the Dusa Bridge to work with QS-Inventory. It defines the inventory type, name, and the path to inventory images, ensuring seamless integration. ```lua override.inventory = 'qs-inventory' override.inventoryname = 'qs-inventory' override.imagepath = "qs-inventory/html/images/" ``` -------------------------------- ### Unified Inventory API: Basic Operations (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/inventory-systems.md Provides examples of fundamental inventory management operations using the Dusa Bridge's unified API, including adding, removing, getting, checking for items, and retrieving all items for a player. ```lua -- Add item to player Inventory.AddItem(source, 'bread', 5) -- Remove item from player Inventory.RemoveItem(source, 'bread', 2) -- Get specific item local item = Inventory.GetItem(source, 'bread') if item then print('Player has', item.count, 'bread') end -- Check if player has item local hasItem = Inventory.HasItem(source, 'bread', 3) if hasItem then print('Player has at least 3 bread') end -- Get all items local items = Inventory.GetItems(source) for slot, item in pairs(items) do print('Slot', slot, ':', item.name, 'x', item.count) end ``` -------------------------------- ### Unified Interface Pattern Examples in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/context7-overview.md Demonstrates the Unified Interface Pattern for interacting with player data, inventory items, and target zones. This pattern allows for writing code that works across different supported systems without modification. ```lua -- Same code works across all supported systems local player = Framework.GetPlayer(source) Inventory.AddItem(source, 'bread', 1) Target.AddBoxZone(name, coords, size, options) ``` -------------------------------- ### ESX Framework Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet specifies the configuration parameters for using the ESX framework with the Dusa Bridge. It defines the framework type, name, event, and prefix required for integration. ```lua override.framework = 'esx' override.frameworkname = 'es_extended' override.frameworkevent = 'esx:getSharedObject' override.frameworkprefix = 'esx' ``` -------------------------------- ### Spawn and Manage Vehicles (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/examples.md Handles spawning personal vehicles based on provided data, including model loading, creation, and setting properties like plates and colors. It also manages vehicle interactions through a menu, with options for locking, engine control, and trunk access. The script integrates with multiple inventory systems (ox_inventory, qb-inventory) for trunk functionality and supports key distribution for ESX and QBCore frameworks. ```lua -- client/vehicles.lua local VehicleSystem = {} -- Spawn personal vehicle function VehicleSystem.SpawnVehicle(vehicleData) local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) local heading = GetEntityHeading(playerPed) -- Find spawn location local spawnCoords = GetSpawnLocation(coords) Framework.TriggerCallback('vehicles:spawnVehicle', function(success) ... end) end -- Vehicle interaction menu function VehicleSystem.ShowVehicleMenu(vehicle) local plate = GetVehicleNumberPlateText(vehicle) Framework.TriggerCallback('vehicles:getVehicleData', function(vehicleData) ... end) end -- Vehicle targeting CreateThread(function() Target.AddGlobalVehicle({ options = { { type = 'client', event = 'vehicles:showMenu', icon = 'fas fa-car', label = 'Vehicle Options' } }, distance = 2.0 }) end) -- Events RegisterNetEvent('vehicles:showMenu', function(data) ... end) RegisterNetEvent('vehicles:toggleLock', function(data) ... end) RegisterNetEvent('vehicles:toggleEngine', function(data) ... end) RegisterNetEvent('vehicles:openTrunk', function(data) ... end) -- Utility functions function GetSpawnLocation(coords) for i = 1, 10 do local spawnCoords = coords + vector3(math.random(-10, 10), math.random(-10, 10), 0) if IsSpawnLocationClear(spawnCoords) then return spawnCoords end end return coords end function IsSpawnLocationClear(coords) local vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 3.0, 0, 71) return vehicle == 0 end function GiveVehicleKeys(vehicle, plate) if Bridge.Framework == 'esx' then -- ESX key system TriggerEvent('esx_vehiclelock:giveKeys', plate) elseif Bridge.Framework == 'qb' or Bridge.Framework == 'qbox' then -- QBCore key system TriggerEvent('qb-vehiclekeys:client:AddKeys', plate) end end function SetVehicleProperties(vehicle, props) -- Universal vehicle property setter if props.plate then SetVehicleNumberPlateText(vehicle, props.plate) end if props.color1 then SetVehicleColours(vehicle, props.color1, props.color2 or props.color1) end ``` -------------------------------- ### QB-Target Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet configures the Dusa Bridge for QB-Target. It specifies the target system type and name, enabling the bridge to interact properly with QB-Target features. ```lua override.target = 'qb-target' override.targetname = 'qb-target' ``` -------------------------------- ### Unified Target API Zone Creation Examples (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/target-systems.md Demonstrates the creation of different types of zones using the Unified Target API: Box Zone, Circle Zone, and Poly Zone. These functions define spatial areas for interaction and require specific parameters like name, coordinates, dimensions/radius, and optional properties. ```lua -- Box Zone Target.AddBoxZone(name, coords, length, width, options) -- Circle Zone Target.AddCircleZone(name, coords, radius, options) -- Poly Zone Target.AddPolyZone(name, points, options) -- Example: Shop zone Target.AddBoxZone('general_store', vector3(25.7, -1347.3, 29.49), 2.0, 2.0, { name = 'general_store', heading = 0, debugPoly = false, minZ = 28.5, maxZ = 30.5 }, { options = { { type = 'client', event = 'shop:openMenu', icon = 'fas fa-shopping-cart', label = 'Browse Shop' } }, distance = 2.5 }) ``` -------------------------------- ### QBCore Integration Usage Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/framework-integration.md Illustrates using the Dusa Bridge API to interact with player data and perform server-side management within the QBCore framework. This includes accessing player identifiers and adding money via player functions. ```lua -- Get player data local PlayerData = Framework.Player print('Player identifier:', PlayerData.Identifier) -- Server-side player management local Player = Framework.GetPlayer(source) Player.Functions.AddMoney('bank', 1000) ``` -------------------------------- ### Lua ESX Framework Mapping for Dusa Bridge Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Defines the specific Lua variables used by the Dusa Bridge to identify and configure its interaction with the ESX framework. This includes the framework type, its internal name, the event used to get its shared object, and a prefix for its functions. ```lua Bridge.Framework = 'esx' Bridge.FrameworkName = 'es_extended' Bridge.FrameworkEvent = 'esx:getSharedObject' Bridge.FrameworkPrefix = 'esx' ``` -------------------------------- ### Specify Dusa Bridge Exports (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Ensures correct access to Dusa Bridge functions by using specific export syntax. This Lua example shows how to call `GetPlayerData` using the full export path `exports.dusa_bridge:GetPlayerData()`, preventing potential naming conflicts with other resources. ```lua exports.dusa_bridge:GetPlayerData() ``` -------------------------------- ### Lua QBCore/QBox Framework Mapping for Dusa Bridge Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Specifies the Lua variables for the Dusa Bridge to map to either QBCore or QBox frameworks. It outlines the framework type identifier, resource names, the event for obtaining the core object, and the associated API prefix. ```lua Bridge.Framework = 'qb' | 'qbox' Bridge.FrameworkName = 'qb-core' | 'qbx_core' Bridge.FrameworkEvent = 'QBCore:GetObject' | nil Bridge.FrameworkPrefix = 'QBCore' ``` -------------------------------- ### Configure Bridge in fxmanifest.lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Ensures the Dusa Bridge resource is correctly identified and loaded by adding the 'bridge' tag to your resource's fxmanifest.lua file. This is essential for the bridge to function. ```lua -- Add to fxmanifest.lua bridge 'dusa_bridge' ``` -------------------------------- ### Override Framework Configuration Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Allows manual specification of the framework and its name in Lua when the Dusa Bridge fails to auto-detect it, or when using a custom framework name. This is done within an 'override.lua' file. ```lua -- In override.lua override.framework = 'esx' override.frameworkname = 'my_custom_esx' ``` -------------------------------- ### QB-Inventory Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet configures the Dusa Bridge for QB-Inventory. It sets the inventory type, name, and the image path, allowing the bridge to correctly interface with QB-Inventory's features. ```lua override.inventory = 'qb-inventory' override.inventoryname = 'qb-inventory' override.imagepath = "qb-inventory/html/images/" ``` -------------------------------- ### Migration Example: Give Player Money (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/framework-integration.md A universal code snippet demonstrating a function to give players money using the Dusa Bridge API. This function is designed to work across any supported framework, simplifying resource migration. ```lua -- This code works on any supported framework local function GivePlayerMoney(source, amount) local player = Framework.GetPlayer(source) if player then Framework.AddMoney(source, 'cash', amount) Framework.Notify(source, 'You received $' .. amount) end end ``` -------------------------------- ### Migrate Inventory Data Structure Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/inventory-systems.md Converts inventory data from one system's structure to another, with a specific example for migrating from QB-Inventory to OX Inventory. ```lua -- Migrate inventory data structure local function MigrateInventoryData(oldData, oldSystem, newSystem) local newData = {} if oldSystem == 'qb-inventory' and newSystem == 'ox_inventory' then for slot, item in pairs(oldData) do newData[slot] = { name = item.name, count = item.amount, metadata = item.info or {} } end end return newData end ``` -------------------------------- ### Lua Dusa Bridge Framework Detection Logic Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Provides a conditional Lua code structure for the Dusa Bridge to execute framework-specific implementations based on the detected `Bridge.Framework` variable. This allows for tailored logic when interacting with different game frameworks like ESX or QBCore. ```lua if Bridge.Framework == 'esx' then -- ESX-specific implementation elseif Bridge.Framework == 'qb' then -- QBCore-specific implementation end ``` -------------------------------- ### OX Core Framework Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet sets up the Dusa Bridge to integrate with the OX Core framework. It defines the framework type, name, and prefix, ensuring proper communication and functionality. ```lua override.framework = 'ox' override.frameworkname = 'ox_core' override.frameworkprefix = 'ox' ``` -------------------------------- ### Lua Dusa Bridge Debug Configuration Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Illustrates how to enable debug mode for the Dusa Bridge resource by setting the `override.debug` variable in the `override.lua` configuration file. This is essential for troubleshooting and development. ```lua -- In override.lua override.debug = true ``` -------------------------------- ### Enable Lua 5.4 in fxmanifest.lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Enables the use of Lua 5.4 for your resource by adding the 'lua54' directive to your fxmanifest.lua file. This is often a requirement for the Dusa Bridge. ```lua -- Add to fxmanifest.lua lua54 'yes' ``` -------------------------------- ### ESX Integration Usage Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/framework-integration.md Demonstrates how to access player data and manage server-side player actions using the Dusa Bridge API for the ESX framework. It shows retrieving player job information and adding money to a player's bank. ```lua -- Get player data local xPlayer = Framework.Player print('Player job:', xPlayer.Job.Name) -- Server-side player management local xPlayer = Framework.GetPlayer(source) xPlayer.addMoney('bank', 1000) ``` -------------------------------- ### QBCore Framework Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet configures the Dusa Bridge to work with the QBCore framework. It sets the framework identifier, name, event for retrieving the core object, and the prefix for QBCore events. ```lua override.framework = 'qb' override.frameworkname = 'qb-core' override.frameworkevent = 'QBCore:GetObject' override.frameworkprefix = 'QBCore' ``` -------------------------------- ### Codem Inventory Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet configures the Dusa Bridge for Codem Inventory. It specifies the inventory type, name, and the path for item images, enabling proper inventory management. ```lua override.inventory = 'qb-inventory' override.inventoryname = 'codem-inventory' override.imagepath = "codem-inventory/html/itemimages/" ``` -------------------------------- ### Debug Adding Items to Inventory Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Includes a code snippet to add an item to a player's inventory and prints the success status to the console. This helps in debugging silent failures during inventory operations. ```lua local success = Inventory.AddItem(source, 'bread', 1) print('Add item result:', success) ``` -------------------------------- ### Custom ESX Framework Configuration (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/framework-integration.md Provides an example of how to manually configure Dusa Bridge to use the ESX framework, overriding automatic detection. This includes specifying the framework, resource name, event, and prefix. ```lua -- override.lua override.framework = 'esx' override.frameworkname = 'my_esx' override.frameworkevent = 'esx:getSharedObject' override.frameworkprefix = 'ESX' ``` -------------------------------- ### OX Inventory Configuration (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/inventory-systems.md Provides an example of how to configure Dusa Bridge to specifically use the OX Inventory system by setting the override variables for inventory type, name, and image path. ```lua -- override.lua override.inventory = 'ox_inventory' override.inventoryname = 'ox_inventory' override.imagepath = "ox_inventory/web/images/" ``` -------------------------------- ### Unified Target API Player Targeting Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/target-systems.md Demonstrates how to add targeting options for nearby players using the Unified Target API. This allows for player-specific actions to be displayed when a player is within range. The AddGlobalPlayer function takes an options table defining the available actions. ```lua -- Add player target options Target.AddGlobalPlayer({ options = { { type = 'client', event = 'police:cuff', icon = 'fas fa-handcuffs', label = 'Cuff Player', job = 'police' }, { type = 'client', event = 'ems:revive', icon = 'fas fa-heart', label = 'Revive Player', job = 'ambulance' } }, distance = 2.0 }) ``` -------------------------------- ### Custom Resource Name Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua code snippet illustrates how to configure the Dusa Bridge when using custom or renamed versions of supported resources. It allows you to specify the correct `frameworkname` and `inventoryname` to ensure proper integration. ```lua -- For a renamed ESX resource override.framework = 'esx' override.frameworkname = 'my_custom_esx' override.frameworkevent = 'esx:getSharedObject' -- For a renamed inventory override.inventory = 'ox_inventory' override.inventoryname = 'my_custom_inventory' override.imagepath = "my_custom_inventory/web/images/" ``` -------------------------------- ### Item Image Management: Automatic Path Detection (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/inventory-systems.md Demonstrates how to dynamically get the image URL for an inventory item using the automatically detected image path provided by Dusa Bridge, and how to use this in NUI messages. ```lua -- Get item image URL local function GetItemImage(itemName) local imagePath = Bridge.InventoryImagePath return ('nui://%s%s.png'):format(imagePath, itemName) end -- Usage in NUI SendNUIMessage({ type = 'showItem', item = 'bread', image = GetItemImage('bread') }) ``` -------------------------------- ### TGiann Inventory Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet configures the Dusa Bridge to utilize TGiann Inventory. It sets the inventory type, name, and the directory for inventory images, facilitating its integration. ```lua override.inventory = 'tgiann-inventory' override.inventoryname = 'tgiann-inventory' override.imagepath = "inventory_images/images/" ``` -------------------------------- ### Police Job System Integration Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/examples.md Implements a police job system with menu options for actions like checking IDs, cuffing, and managing officers. It also defines interactive zones for police stations and evidence lockers. This script relies on external Framework and Menu modules for UI and player data. ```lua -- jobs/police.lua local PoliceJob = {} -- Police menu function PoliceJob.OpenPoliceMenu() local playerData = Framework.Player if playerData.Job.Name ~= 'police' then Framework.Notify('You are not a police officer', 'error') return end local menuItems = { { title = 'Check ID', description = 'Check nearby player ID', event = 'police:checkID' }, { title = 'Cuff Player', description = 'Cuff nearby player', event = 'police:cuffPlayer' }, { title = 'Search Player', description = 'Search nearby player', event = 'police:searchPlayer' } } -- Add supervisor options if playerData.Job.Grade.Level >= 3 then table.insert(menuItems, { title = 'Manage Officers', description = 'Manage police officers', event = 'police:manageOfficers' }) end Menu.Show({ title = 'Police Menu', items = menuItems }) end -- Police station zones CreateThread(function() -- Police station Target.AddBoxZone('police_station', vector3(441.0, -975.0, 30.0), 5.0, 5.0, { name = 'police_station', heading = 0, debugPoly = false }, { options = { { type = 'client', event = 'police:clockIn', icon = 'fas fa-clock', label = 'Clock In/Out', job = 'police' }, { type = 'client', event = 'police:openArmory', icon = 'fas fa-gun', label = 'Armory', job = 'police', grade = 1 } }, distance = 2.0 }) -- Evidence locker Target.AddBoxZone('evidence_locker', vector3(475.0, -996.0, 30.0), 2.0, 2.0, { name = 'evidence_locker' }, { options = { { type = 'client', event = 'police:evidenceLocker', icon = 'fas fa-box', label = 'Evidence Locker', job = 'police' } }, distance = 1.5 }) end) -- Events RegisterNetEvent('police:checkID', function() local target = GetNearestPlayer() if target then TriggerServerEvent('police:requestID', GetPlayerServerId(target)) else Framework.Notify('No player nearby', 'error') end end) RegisterNetEvent('police:showID', function(targetData) local playerData = Framework.Player if playerData.Job.Name == 'police' then Menu.Show({ title = 'Player ID', items = { { title = 'Name', description = targetData.name }, { title = 'ID', description = targetData.Identifier or targetData.identifier }, { title = 'Job', description = targetData.job } } }) end end) -- Utility functions function GetNearestPlayer() local players = GetActivePlayers() local ped = PlayerPedId() local coords = GetEntityCoords(ped) local nearestPlayer = nil local nearestDistance = 3.0 for _, player in pairs(players) do local targetPed = GetPlayerPed(player) if targetPed ~= ped then local targetCoords = GetEntityCoords(targetPed) local distance = #(coords - targetCoords) if distance < nearestDistance then nearestDistance = distance nearestPlayer = player end end end return nearestPlayer end ``` -------------------------------- ### Unified Target API Entity Targeting Examples (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/target-systems.md Shows how to add targeting to specific entities or entity models using the Unified Target API. This enables contextual actions based on the targeted entity. Functions include AddEntityZone and AddTargetModel, each requiring entity identifiers and an options table. ```lua -- Add target to specific entity Target.AddEntityZone(name, entity, options) -- Add target to entity model Target.AddTargetModel(models, options) -- Example: Vehicle targeting Target.AddTargetModel({'adder', 'zentorno'}, { options = { { type = 'client', event = 'vehicle:tune', icon = 'fas fa-car', label = 'Tune Vehicle', job = 'mechanic' } }, distance = 3.0 }) ``` -------------------------------- ### Lua Dusa Bridge Server Hook System Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Demonstrates the server-side hook system provided by the Dusa Bridge, allowing developers to register custom event listeners and trigger events with associated data. This is used for custom bridge-specific functionality on the server. ```lua Hook.Register('eventName', callbackFunction) Hook.Trigger('eventName', data) ``` -------------------------------- ### Lua Dusa Bridge State Variables Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Lists essential Lua state variables managed by the Dusa Bridge resource, encompassing its own identifying information (resource name, version), operational context (client/server), debugging status, localization, and a table for disabled modules. ```lua Bridge.Resource - Current resource name Bridge.Name - Bridge resource name Bridge.Version - Bridge version Bridge.Context - 'client' | 'server' Bridge.DebugMode - Debug flag Bridge.Locale - Language setting Bridge.Disabled - Disabled modules table ``` -------------------------------- ### Override Configuration in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua code snippet demonstrates how to set various override configurations for the Dusa Bridge, such as debug mode, locale, and framework/inventory/target system settings. It allows for customization of the bridge's behavior. ```lua override = {} -- Enable or disable debug mode override.debug = false -- Set the locale override.locale = 'en' -- Framework Configuration override.framework = 'esx' -- 'esx', 'qb', 'qbox', 'ox', 'vrp', 'ndcore' override.frameworkname = 'es_extended' override.frameworkevent = 'esx:getSharedObject' override.frameworkprefix = 'esx' -- Inventory Configuration override.inventory = 'ox_inventory' override.inventoryname = 'ox_inventory' override.imagepath = "ox_inventory/web/images/" -- Target Configuration override.target = 'ox_target' override.targetname = 'ox_target' -- Zone Configuration override.zone = 'ox_lib' override.zonename = 'ox_lib' -- Menu Configuration override.menu = 'ox_lib' -- 'ox_lib' or 'qb-menu' ``` -------------------------------- ### Enabling Debug Mode in Lua Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This Lua snippet illustrates how to enable debug mode for the Dusa Bridge by setting `override.debug` to `true` in the `override.lua` file. Debug mode provides detailed information about the bridge's detection and loading processes. ```lua -- In override.lua override.debug = true ``` -------------------------------- ### Advanced Target Features Job Restrictions Example (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/target-systems.md Shows how to implement job-specific targeting restrictions using the Dusa Bridge API. This allows certain actions to be available only to players of a specific job, and optionally, with a minimum grade within that job. The `job` and `grade` properties are used within the options table. ```lua -- Job-specific targeting Target.AddBoxZone('police_station', vector3(441.0, -975.0, 30.0), 5.0, 5.0, { name = 'police_station' }, { options = { { type = 'client', event = 'police:clockIn', icon = 'fas fa-clock', label = 'Clock In', job = 'police' }, { type = 'client', event = 'police:armory', icon = 'fas fa-gun', label = 'Access Armory', job = 'police', grade = 2 -- Minimum grade required } }, distance = 2.0 }) ``` -------------------------------- ### Add Target Zones for ox_target and qb-target (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/target-systems.md This function allows for the creation of target zones (box or circle) that are compatible with both ox_target and qb-target systems. It abstracts the differences in API calls between the two targeting systems, providing a unified interface for adding zones. Ensure the correct Bridge.Target is set and that the respective targeting resources are started. ```lua -- Create wrapper for easy migration local TargetWrapper = {} function TargetWrapper.AddZone(zoneType, name, coords, size, options, targetOptions) if Bridge.Target == 'ox_target' then if zoneType == 'box' then exports.ox_target:addBoxZone(name, coords, size.x, size.y, options, targetOptions) elseif zoneType == 'circle' then exports.ox_target:addSphereZone(name, coords, size.radius, options, targetOptions) end elseif Bridge.Target == 'qb-target' then if zoneType == 'box' then exports['qb-target']:AddBoxZone(name, coords, size.x, size.y, options, targetOptions) elseif zoneType == 'circle' then exports['qb-target']:AddCircleZone(name, coords, size.radius, options, targetOptions) end end end ``` -------------------------------- ### Debug and Locale Configuration via Convirs Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/configuration.md This configuration snippet shows how to set Dusa Bridge's debug mode and locale using server-side convars in `server.cfg`. This method provides an alternative to editing `override.lua` for these specific settings. ```cfg # In server.cfg set bridge:debug "true" # Enable debug mode set bridge:locale "en" # Set locale ``` -------------------------------- ### Lua Dusa Bridge Module Control Configuration Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Shows how to disable specific modules of the Dusa Bridge resource within the `fxmanifest.lua` file using the `bridge_disable` directive. This allows developers to tailor the resource's functionality by excluding unnecessary components. ```lua -- In fxmanifest.lua bridge_disable 'framework' bridge_disable 'inventory' bridge_disable 'target' ``` -------------------------------- ### Custom Debug Commands for Dusa Bridge (Lua) Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/troubleshooting.md Adds custom commands to the game console for debugging various aspects of the Dusa Bridge. Includes commands to inspect player data, bridge status (framework, inventory, target), and inventory items. ```lua -- Debug player data RegisterCommand('debugplayer', function() local playerData = Framework.Player print('Player data:', json.encode(playerData, {indent = true})) end) -- Debug bridge status RegisterCommand('bridgestatus', function() print('Framework:', Bridge.Framework) print('Inventory:', Bridge.Inventory) print('Target:', Bridge.Target) end) -- Debug inventory RegisterCommand('debuginv', function(source) local items = Inventory.GetItems(source) print('Inventory:', json.encode(items, {indent = true})) end, true) ``` -------------------------------- ### Lua Dusa Bridge System Detection States Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/CONTEXT7.md Defines the Lua variables used by the Dusa Bridge to store information about detected external systems. This includes the system type, its specific resource name, the event to trigger interactions, and any applicable API prefix. ```lua Bridge.[System] - Detected system type Bridge.[System]Name - Resource name Bridge.[System]Event - Event name (if applicable) Bridge.[System]Prefix - API prefix (if applicable) ``` -------------------------------- ### Lua: Batch Create Zones for Performance Source: https://github.com/lesimov/dusa_bridge/blob/main/docs/target-systems.md Demonstrates how to efficiently create multiple zones by iterating over a table of zone definitions. It checks the zone type ('box' or 'circle') and calls the appropriate 'Target.Add' function. This approach reduces repetitive code and improves readability. ```lua -- Batch zone creation local zones = { { name = 'shop1', coords = vector3(100.0, 200.0, 30.0), type = 'box', options = { /* ... */ } }, { name = 'shop2', coords = vector3(150.0, 250.0, 30.0), type = 'circle', options = { /* ... */ } } } for _, zone in pairs(zones) do if zone.type == 'box' then Target.AddBoxZone(zone.name, zone.coords, 2.0, 2.0, {}, zone.options) elseif zone.type == 'circle' then Target.AddCircleZone(zone.name, zone.coords, 2.0, {}, zone.options) end end ```