Framework Integration
This section guides you through the steps to integrate the Advanced Ped Dialog script with your framework, utilizing built-in functions for seamless integration.
Most of the setup should be understandable, but I'll highlight a few things you might need additional help with. By default, the script is set up for ESX + ox_inventory.
Client Functions
Client functions file can be found at configurations/client/CFunctions.lua
.
Inventory
This is designed for convenience, automatically taking item labels from your inventory and using them in buying and selling menus.
fetchItems
- toggler to use this feature.labelVar
- variable name in your inventory system.getAllItems
- function that should return all the registered items in your inventory system.
Items table has to be returned as follows:
This function is called only ONCE when a player first time triggers the menu, all the items are saved in cache. Therefore, retrieving your items from the database or server will not cause any issues, as this function is not repeatedly called.
type GetAllItems = () => ReturnType;
interface ReturnType {
[item_name: string]: {
// This will be your label var, it could also be named differently.
label: string;
// Other item variables. They will not be used, but everything is fine if you don't remove them.
[key: string]: unknown;
}
}
Notifications
Display notifications sent by the script. If you prefer to not show any notifications, you can just leave this function empty.
type Notification = (
message: string,
duration: number, // This will always be 3000
type: 'error' | 'success' // Notification type.
) => void;
Text Display
Configure how text is displayed when players approach peds. The functions used depend on your Config.UseEveryTickText
setting.
When Config.UseEveryTickText = true
:
The script will use this function to display text when player is close to a ped or when player can interact with ped.
DrawTextEveryTick = function (text, coords)
BeginTextCommandDisplayHelp("STRING")
AddTextComponentSubstringPlayerName(text)
EndTextCommandDisplayHelp(2, false, false, 0)
SetFloatingHelpTextStyle(1, 1, 2, 191, 3, 0)
SetFloatingHelpTextWorldPosition(1, coords.x, coords.y, coords.z + 1.0)
end,
When Config.UseEveryTickText = false
:
The script will use these functions for the same purpose - showing text when player approaches peds and hiding it when they move away. You will need to implement these functions yourself, but this can be done in your own way.
ShowText = function (text, coords)
exports['ox_lib']:showTextUI(text)
end,
HideText = function ()
exports['ox_lib']:hideTextUI()
end,
Example Configuration
CFunctions = {
inventory = {
fetchItems = true,
labelVar = 'label',
getAllItems = function ()
return exports['ox_inventory']:Items()
end
},
TriggerServerCallback = function(name, cb, ...)
ESX.TriggerServerCallback(name, cb, ...)
end,
Notification = function (message, duration, type)
ESX.ShowNotification(message)
end,
DrawTextEveryTick = function (text, coords)
BeginTextCommandDisplayHelp("STRING")
AddTextComponentSubstringPlayerName(text)
EndTextCommandDisplayHelp(2, false, false, 0)
SetFloatingHelpTextStyle(1, 1, 2, 191, 3, 0)
SetFloatingHelpTextWorldPosition(1, coords.x, coords.y, coords.z + 1.0)
end,
ShowText = function (text, coords)
-- Add your TextUI logic here
end,
HideText = function ()
-- Add your TextUI hide logic here
end,
}
Server Functions
Server functions file can be found at configurations/server/SFunctions.lua
.
Everything here should be understandable.
Example Configuration
SFunctions = {
RegisterServerCallback = function(name, cb, ...)
ESX.RegisterServerCallback(name, cb, ...)
end,
HasMoney = function(source, amount, moneyType)
local money = 0;
if not moneyType or moneyType == 'cash' then
money = exports['ox_inventory']:GetItem(source, 'money', false, true)
elseif moneyType == 'black' then
money = exports['ox_inventory']:GetItem(source, 'black_money', false, true)
end
return money >= amount
end,
AddMoney = function(source, amount, moneyType)
if not moneyType or moneyType == 'cash' then
exports['ox_inventory']:AddItem(source, 'money', amount)
elseif moneyType == 'black' then
exports['ox_inventory']:AddItem(source, 'black_money', amount)
end
end,
RemoveMoney = function(source, amount, moneyType)
if not moneyType or moneyType == 'cash' then
exports['ox_inventory']:RemoveItem(source, 'money', amount)
elseif moneyType == 'black' then
exports['ox_inventory']:RemoveItem(source, 'black_money', amount)
end
end,
HasItem = function(source, itemName, amount)
return exports['ox_inventory']:GetItem(source, itemName, false, true) >= amount
end,
CanCarryItem = function (source, itemName, amount)
return exports['ox_inventory']:CanCarryItem(source, itemName, amount)
end,
AddItem = function (source, itemName, amount)
exports['ox_inventory']:AddItem(source, itemName, amount)
end,
RemoveItem = function (source, itemName, amount)
exports['ox_inventory']:RemoveItem(source, itemName, amount)
end
}
Last updated