Register your own NPCs from any resource, attach a dialogue to a ped you already created, or open a dialogue or a shop directly. NPCs are registered on the client; the items and prices of a shop are registered on the server.
What you register through the exports lives in memory and is not saved in the database. It shows in the panel under "From scripts", read only. NPCs created in the panel are stored in the database and need no code.
Quick reference
| Side | Export | Returns |
|---|---|---|
| Client | Register(id, def) | boolean |
| Client | Update(id, patch) | boolean |
| Client | Remove(id) | boolean |
| Client | Exists(id) | boolean |
| Client | GetEntity(id) | integer or nil |
| Client | Interact(id) | boolean |
| Client | ShowDialog(data) | id of the closing button, or nil |
| Client | SwitchDialog(dialogId) | boolean |
| Client | ShowShop(data) | boolean or nil |
| Client | Close() | boolean |
| Client | IsOpen() | boolean |
| Server | RegisterShop(id, items, options) | boolean |
| Server | RemoveShop(id) | boolean |
| Server | GetShop(id) | table or nil |
| Server | GetShopLimits(src, shopId) | table or nil |
| Server | ResetShopLimits(identifier, shopId, item) | integer |
Full example: an NPC with dialogue and shop
A buyer NPC registered from a resource called my_resource. The client registers the NPC; the server registers what the shop trades and at which price.
Register the shop on the server
local SHOP_ID = 'my_resource:scrap_buyer'
local function registerShop()
if GetResourceState('cuxial_interactions') ~= 'started' then return end
exports.cuxial_interactions:RegisterShop(SHOP_ID, {
{ name = 'scrapmetal', price = 12 },
{ name = 'copper', price = 20, label = 'Copper wire' },
{ name = 'lockpick', price = 150, mode = 'buy', limits = {
{ amount = 2, window = 86400 },
} },
}, {
coords = vec3(25.7, -1347.3, 29.49),
distance = 6.0,
account = 'cash',
})
end
CreateThread(registerShop)
AddEventHandler('cuxial_interactions:ready', registerShop)
RegisterNetEvent('my_resource:server:AskForWork', function(args, info)
local src = source
-- args and info come from the client: check the player, the distance and the state here.
print(('player %s asked for work at point %s'):format(src, info.id))
end)The player sells scrap metal and copper, and can buy two lockpicks per day.
Register the NPC on the client
local POINT_ID = 'my_resource:scrap_buyer'
local function registerNpc()
if GetResourceState('cuxial_interactions') ~= 'started' then return end
exports.cuxial_interactions:Register(POINT_ID, {
coords = vec4(25.7, -1347.3, 29.49, 271.0),
model = 's_m_y_dealer_01',
scenario = 'WORLD_HUMAN_STAND_IMPATIENT',
behavior = { invincible = true, noTemporaryEvents = true, freeze = true },
label = 'Talk to the buyer',
targetIcon = 'fas fa-comment-dots',
activeDistance = 2.5,
blip = { id = 52, scale = 0.6, colour = 5, name = 'Scrap buyer' },
-- shop.id defaults to the id of the point, so it matches RegisterShop.
shop = { name = 'Sam', job = 'Buyer', icon = 'store' },
dialog = {
{
id = 'start',
name = 'Sam',
job = 'Buyer',
icon = 'store',
text = 'Got anything for me?',
buttons = {
{ id = 'trade', label = 'Let us trade', icon = 'hand-coins', shop = true },
{ id = 'work', label = 'Do you have work?', icon = 'briefcase', nextDialog = 'work' },
{ id = 'bye', label = 'Not today', icon = 'x', close = true },
},
},
{
id = 'work',
name = 'Sam',
job = 'Buyer',
text = 'Maybe. Bring me a lockpick and we talk.',
buttons = {
{
id = 'accept',
label = 'I have one',
icon = 'key',
item = 'lockpick',
close = true,
serverEvent = 'my_resource:server:AskForWork',
args = { job = 'scrap' },
},
{
id = 'wave',
label = 'Say goodbye',
icon = 'hand',
close = true,
onSelect = function(ctx)
PlayAmbientSpeech1(ctx.entity, 'GENERIC_BYE', 'SPEECH_PARAMS_FORCE')
end,
},
{ id = 'back', label = 'Back', icon = 'undo-2', nextDialog = 'start' },
},
},
},
})
end
CreateThread(registerNpc)
AddEventHandler('cuxial_interactions:ready', registerNpc)Restarting cuxial_interactions wipes every NPC and shop registered by other resources. Keep the cuxial_interactions:ready handlers of the example so yours are registered again.
Ownership and cleanup
- Every NPC and shop belongs to the resource that registered it.
- Registering an id you already own replaces it. An id owned by another resource is rejected with a console warning.
- Only the owner can update or remove an NPC or a shop.
- When a resource stops, its NPCs are removed, its open dialogue is closed and its shops are deleted.
- Ids are shared by the whole server, including the NPCs of the panel. Prefix them with the name of your resource:
'my_resource:scrap_buyer'. Panel ids cannot contain:, so a prefixed id never clashes with one of them.
Client exports
Register
Registers an NPC, or a spot without a ped, that opens a dialogue or a shop.
exports.cuxial_interactions:Register(id, def)| Parameter | Type | Description |
|---|---|---|
id | string | Unique id of the point. Not empty. |
def | table | Definition of the point. See Point definition. |
Returns: boolean. false when id or def is not valid, when the id is already taken, when def.enabled == false, or when def has none of coords, entity and netId.
-- Attach a dialogue to a ped your resource already created.
exports.cuxial_interactions:Register('my_resource:doctor', {
entity = doctorPed,
label = 'Talk',
dialog = {
{
id = 'start',
name = 'Dr. Lee',
text = 'How can I help?',
buttons = { { id = 'bye', label = 'Nothing, thanks', close = true } },
},
},
})Update
Merges patch into the definition of a point you own and rebuilds it.
exports.cuxial_interactions:Update(id, patch)| Parameter | Type | Description |
|---|---|---|
id | string | Id of the point. |
patch | table | Fields to replace. Only the first level is merged: a dialog or a blip in the patch replaces the whole table. |
Returns: boolean. false when the point does not exist or belongs to another resource.
exports.cuxial_interactions:Update('my_resource:scrap_buyer', { label = 'Closed for today', dialog = closedDialog })Update cannot delete a field, because a nil value does not travel in the patch. Call Register again with the full definition instead.
Remove
Removes a point you own: its ped, its blip and its target option. If its dialogue is open, it closes.
exports.cuxial_interactions:Remove(id)Returns: boolean. false when the point does not exist or belongs to another resource.
Exists
Tells whether a point is registered, whoever owns it.
local registered = exports.cuxial_interactions:Exists(id)Returns: boolean.
GetEntity
Returns the ped of a point.
local ped = exports.cuxial_interactions:GetEntity(id)Returns: integer or nil. nil when the point does not exist, has no ped, or the player is too far and the ped is not created.
local ped = exports.cuxial_interactions:GetEntity('my_resource:scrap_buyer')
if ped then PlayAmbientSpeech1(ped, 'GENERIC_HI', 'SPEECH_PARAMS_FORCE') endInteract
Opens a point as if the player had selected it. It applies the same conditions (job, item, canInteract). Use it for points with interaction = 'none', which you open from your own marker, key or menu.
exports.cuxial_interactions:Interact(id)Returns: boolean. false when the point does not exist, a dialogue or shop is already open, the conditions fail, or the point has no dialog, shop or onInteract.
if not exports.cuxial_interactions:Interact('my_resource:scrap_buyer') then
lib.notify({ description = 'He does not want to talk to you.', type = 'error' })
endShowDialog
Opens a dialogue that is not tied to a registered point. The call waits until the dialogue closes.
local result = exports.cuxial_interactions:ShowDialog(data)| Parameter | Type | Description |
|---|---|---|
data.dialog | table | List of pages. Required. See Dialogue page. |
data.entity | integer | Ped the camera focuses on. Optional. |
data.shop | table | Shop opened by the buttons with shop = true. See Shop. |
data.extraData | table | Your own data, delivered in ctx.extraData. |
data.camera | boolean | false opens without moving the camera. |
data.id | string | Id reported in ctx.id and in the events. Optional. |
Returns: the id of the button with close = true that closed the dialogue, or its position when it has no id. nil when it was closed with Esc or by Close(), when the data is not valid, or at once when something is already open.
local answer = exports.cuxial_interactions:ShowDialog({
entity = guardPed,
dialog = {
{
id = 'ask',
name = 'Guard',
text = 'This area is closed. Do you want to pay the fee?',
buttons = {
{ id = 'yes', label = 'Pay', icon = 'dollar-sign', close = true },
{ id = 'no', label = 'Leave', icon = 'x', close = true },
},
},
},
})
if answer == 'yes' then
TriggerServerEvent('my_resource:server:PayFee')
endShowDialog blocks the thread that calls it. Call it inside CreateThread or an event handler, never in a loop that runs every frame.
SwitchDialog
Changes the page of the open dialogue.
exports.cuxial_interactions:SwitchDialog(dialogId)| Parameter | Type | Description |
|---|---|---|
dialogId | string | number | id of a page of the open dialogue. |
Returns: boolean. false when no dialogue is open or the page does not exist or is disabled.
onSelect = function()
local hasLicense = lib.callback.await('my_resource:server:HasLicense', false)
exports.cuxial_interactions:SwitchDialog(hasLicense and 'approved' or 'denied')
end,ShowShop
Opens a shop. With a dialogue open it switches to the shop and adds a button to go back. With nothing open it opens the shop directly and waits until it closes.
exports.cuxial_interactions:ShowShop(data)| Parameter | Type | Description |
|---|---|---|
data | table | A shop table, or { shop = shopTable, entity = ped, camera = boolean, id = string }. See Shop. |
Returns: boolean when it switched from an open dialogue. nil when it opened directly, once the shop is closed.
exports.cuxial_interactions:ShowShop({
entity = buyerPed,
shop = { id = 'my_resource:scrap_buyer', name = 'Sam', job = 'Buyer' },
})Opened this way, the shop needs its own id, and that id must be registered on the server with RegisterShop. Otherwise it is shown as unavailable.
Close
Closes the dialogue or the shop that is open.
exports.cuxial_interactions:Close()Returns: boolean. false when nothing was open.
IsOpen
Tells whether a dialogue or a shop is open.
local open = exports.cuxial_interactions:IsOpen()Returns: boolean.
The same value is in LocalPlayer.state.isDialogOpen. It is local to the player's client and is not sent to the server.
Compatibility aliases
Older lowercase names are kept so existing code keeps working. Use the names above in new code.
| Alias | Equivalent |
|---|---|
showDialog(data) | ShowDialog(data). Also accepts data.ped as the entity. |
switchDialog(id) | SwitchDialog(id) |
showShop(shop) | Switches to the shop from an open dialogue. |
showShopDirect({ ped, shop }) | Opens the shop directly. |
Server exports
RegisterShop
Registers what a shop trades and at which price. The server only accepts trades with registered shops, and it always uses the price registered here.
exports.cuxial_interactions:RegisterShop(id, items, options)| Parameter | Type | Description |
|---|---|---|
id | string | Id of the shop. The same as shop.id on the client; for a point registered with Register, the id of the point unless you set another. |
items | table | List of items. See below. |
options.coords | vector3 | vector4 | table | Position of the shop, or a list of positions. |
options.netId | integer | Network id of a networked ped; the distance is measured to it. |
options.anywhere | boolean | true accepts trades from any distance. |
options.distance | number | Maximum metres to coords or to the ped. Defaults to shop.maxDistance of the config. |
options.account | string | Account where sales are paid and purchases are charged. Defaults to shop.account of the config. |
options.mode | string | 'sell' (the player sells, the NPC pays) or 'buy' (the player buys). Default for items without their own mode. Defaults to 'sell'. |
options.limits | table | Limits of the whole shop. See Shop limit. |
options.job | string | table | Job condition, checked on the server when opening the shop and on every trade. Same format as in Point definition. |
options.item | string | table | Item condition, checked the same way. |
One of coords, netId or anywhere = true is required.
Each entry of items:
| Field | Type | Description |
|---|---|---|
name | string | Item name. Required. |
price | number | Unit price, 0 or more. Required. |
label | string | Defaults to the label of the inventory. |
image | string | URL of the image. |
mode | string | 'sell' or 'buy'. Defaults to options.mode. The same item can appear once in each mode, with different prices. |
limits | table | Limits of this item. See Shop limit. |
Returns: boolean. false when the id is not valid or belongs to another resource, when the list is empty or any item lacks a name or a valid price, when a mode or a limit is not valid, or when no location is given.
exports.cuxial_interactions:RegisterShop('my_resource:pharmacy', {
{ name = 'bandage', price = 15 },
{ name = 'painkillers', price = 40, limits = { { amount = 5, window = 3600 } } },
}, { coords = vec3(-1867.28, -337.84, 49.52), mode = 'buy', job = { ambulance = 0 } })What the server checks on every sale, in this order: the shop is registered and buys that item; the quantity is a whole number between 1 and shop.maxQuantity; shop.cooldown has passed; the player is within the distance; the conditions pass; the item is in the catalogue for that player (filterCatalog); the player carries the units; canSell; the price (getPrice); the limits. Then takeItems and payout; if the payment fails, giveBack. Last, onSold.
On every purchase: the shop is registered and sells that item; quantity; cooldown; distance; conditions; filterCatalog; canBuy; getPrice; the limits; canCarry. Then charge and giveItems; if the items cannot be given, refund. Last, onBought.
The total is price × quantity, rounded to a whole number. Any hook that fails or returns something invalid denies the trade.
Once the shop is registered, the player sees the list and the prices of the server, already filtered for them. On the client, shop = { name, job } is enough.
Shop limit
Used in options.limits and in the limits of each item. Up to admin.limits.limits per list (4 by default).
| Field | Type | Description |
|---|---|---|
amount | integer | 1 to 1 000 000. Required. |
window | integer | Seconds, from 60 up to limits.maxWindow. Required. Windows slide: what was done in the last window seconds is added up. |
scope | string | 'player' (each character, by its identifier) or 'global' (shared by every player; works as stock). Default 'player'. |
measure | string | 'units' or 'money' moved. Default 'units'. |
mode | string | Only in shop limits: '' (both modes), 'buy' or 'sell'. Default ''. |
RemoveShop
Removes a shop you own.
exports.cuxial_interactions:RemoveShop(id)Returns: boolean. false when the shop does not exist or belongs to another resource.
GetShop
Returns a registered shop.
local shop = exports.cuxial_interactions:GetShop(id)Returns: { id, account, mode, items } or nil. Each item has key, name, label, price, image and mode. key is mode .. ':' .. name, such as 'sell:scrapmetal'.
local shop = exports.cuxial_interactions:GetShop('my_resource:scrap_buyer')
if shop then
for _, item in ipairs(shop.items) do
print(item.mode, item.name, item.price)
end
endGetShopLimits
Returns, for one player, what the limits of a shop still allow.
local limits = exports.cuxial_interactions:GetShopLimits(src, shopId)| Parameter | Type | Description |
|---|---|---|
src | integer | Server id of the player. |
shopId | string | Id of the shop. |
Returns: a table keyed by item key, or nil when the shop does not exist or the player is not loaded. Each value is { remaining, max, resetIn, scope }: units left, the amount of the limit, seconds until one more unit fits (when remaining is 0), and 'player' or 'global'. Items without limits are not in the table.
local limits = exports.cuxial_interactions:GetShopLimits(source, 'my_resource:pharmacy')
local left = limits and limits['buy:painkillers']
if left then print(('%d of %d left'):format(left.remaining, left.max)) endResetShopLimits
Deletes the limit records that match the filters. Every parameter is optional.
local deleted = exports.cuxial_interactions:ResetShopLimits(identifier, shopId, item)| Parameter | Type | Description |
|---|---|---|
identifier | string | nil | Character identifier. nil for every player. |
shopId | string | nil | Id of the shop. nil for every shop. |
item | string | nil | Item name. nil for every item. |
Returns: integer, the number of records deleted.
-- Reset one character in one shop
exports.cuxial_interactions:ResetShopLimits(identifier, 'my_resource:pharmacy')ResetShopLimits() without arguments deletes the records of every shop and every player.
Events
cuxial_interactions:ready
Local event triggered on the client and on the server, without arguments, when cuxial_interactions starts. Register your NPCs and shops again there.
-- client
AddEventHandler('cuxial_interactions:ready', registerNpc)
-- server
AddEventHandler('cuxial_interactions:ready', registerShop)If your resource starts after it, the event has already passed: register as well when your resource loads, as the example does with CreateThread.
Events and exports called from panel buttons
The button actions of the panel call your code with the player as the source of truth:
| Action | How your code is called |
|---|---|
| Server export | exports[resource][name](src, ...args, ...values). Returning false counts as a failure. |
| Server event | Local server event: AddEventHandler('my:event', function(src, ...args, ...values) end). It is not a net event, so clients cannot trigger it. |
| Client export | exports[resource][name](...args, ...values) on the player's client. With context, { id, dialogId, buttonId, entity, netId } is appended at the end. |
| Client event | TriggerEvent(name, ...args, ...values) on the player's client, with the same optional context. |
| Command | ExecuteCommand on the player's client, with the values appended separated by spaces. |
args are the JSON arguments saved in the action; values are the fields typed by the player, already validated by the server.
AddEventHandler('my_resource:server:GiveKeys', function(src, plate)
-- src was checked by the server: distance, conditions and version of the NPC
end)Hooks
The folder hooks/ is not encrypted. Each file defines functions in CuxialInteractions.Hooks that the core calls at specific moments; the code inside is the default behaviour. Change it to connect your own inventory, economy or systems. Keep the signature and the type of what each one returns.
- On the server, a hook that fails or returns something invalid denies the action: nothing is sold, nothing is charged.
- On the client, a presentation hook that fails falls back to neutral behaviour: no camera, no blip, the image of
shop.image, the ox_lib notification. - Server hooks are always called after the checks of the core (shop registered, quantity, distance, conditions, cooldown). They apply to NPCs of the panel and to those registered by other resources.
Server (hooks/server/)
| Hook | When | Returns |
|---|---|---|
notify(src, key, kind, ...) | Every notification to the player | — |
filterCatalog(src, shopId, items) | On opening the shop and on every trade | List of visible items (only items of the shop are accepted) |
canSell(src, shop, item, qty) | Before selling | boolean, optional locale key as reason |
getPrice(src, shop, item, qty) | When listing (qty = 1) and on every trade | Unit price, finite number ≥ 0 |
takeItems(src, name, qty) | Remove the items sold | boolean |
payout(src, account, total, reason) | Pay the sale | boolean |
giveBack(src, name, qty) | If the payment fails | boolean |
onSold(src, sale) | Sale completed | — |
canBuy(src, shop, item, qty) | Before buying | boolean, optional locale key as reason |
canCarry(src, name, qty) | Before charging a purchase | boolean |
charge(src, account, total, reason) | Charge the purchase | boolean, optional reason |
giveItems(src, name, qty) | Give what was bought | boolean |
refund(src, account, total, reason) | If the items cannot be given | boolean |
onBought(src, sale) | Purchase completed | — |
canRevive(src, opts) | On a "Revive" action | boolean, optional reason |
reviveCost(src, opts) | Before charging the revive | cost (integer ≥ 0), account |
revive(src, opts) | After charging; false returns the money | boolean |
onRevived(src, cost, opts) | Revive completed | — |
fetchSkins(limit, days) | First time a player look is needed | { model, skin }[] (skin as JSON) |
sale is { shop, item, label, mode, quantity, price, total, account }. opts of the revive hooks is { interaction, coords, cost, account, ignoreEms }: the NPC that attends and the options of its action.
function Hooks.getPrice(src, shop, item, qty) return item.price * 1.10 end
function Hooks.canSell(src, shop, item, qty) return qty <= 50, 'shop_not_allowed' end
function Hooks.payout(src, account, total, reason) return Bridge.AddMoney(src, 'bank', total, reason) and true or false end
function Hooks.reviveCost(src, opts) return opts.cost or 2500, opts.account or 'cash' end
function Hooks.onSold(src, sale) TriggerEvent('my_logs:sale', src, sale) endClient (hooks/client/)
| Hook | When | Returns |
|---|---|---|
notify(key, kind, ...) | Every local notification | — |
canOpen(id, def) | Before opening a dialogue or a shop | boolean (by default: not dead, not cuffed, not in a vehicle) |
onOpen(session) / onClose(session, result) | On opening and closing | — |
attach(point, options) | The point becomes interactive | Own handle or false |
detach(point, handle) | The point stops being interactive | — |
createBlip(blip, coords) | On registering a point with a blip | Blip id |
applySkin(entity, appearance) | NPC with a player look | boolean |
onPedSpawned(entity, id, def) | After creating an NPC | — |
cameraFor(entity) | On talking to an NPC | position, rotation (vector3), or false for no camera |
itemImage(name) | Image of an item without image | URL |
function Hooks.canOpen(id, def) return not LocalPlayer.state.invBusy end
function Hooks.itemImage(name) return ('nui://qb-inventory/html/images/%s.png'):format(name) end
function Hooks.onPedSpawned(entity, id, def) SetPedCanRagdoll(entity, false) endKeep a copy of your edited hooks/ folder. When you update the resource, put your changes back into the new files.
Data reference
Point definition
The table passed to Register.
Where. One of the three is required.
| Field | Type | Description |
|---|---|---|
coords | vector3 | vector4 | Position of the point. With model or usePlayerSkin a ped is created there; without them it is a spot without a ped. The w of a vector4 is the heading. |
entity | integer | A ped or object that already exists on this client. It is not created or deleted by the point. |
netId | integer | The same, by network id. The point attaches when the entity comes into range. |
Ped. Only for points with coords that create their own ped.
| Field | Type | Description |
|---|---|---|
model | string | number | Ped model. If it does not exist, npc.fallbackModel is used. |
usePlayerSkin | boolean | true gives the ped the look of a random active character. Falls back to model when no look is available. |
heading | number | Heading, when coords is a vector3. |
scenario | string | Scenario the ped plays, such as 'WORLD_HUMAN_CLIPBOARD'. |
animation | table | { dict, clip, speed, blendOut, duration, flag }. dict and clip are required. Defaults: 8.0, -8.0, -1, 1. |
clothing | table | List of { componentIndex, variation, texture }. Not applied when the ped got a player look. |
behavior | table | { invincible, noTemporaryEvents, freeze }, each a boolean. |
spawnDistance | number | Metres at which the ped is created. Defaults to npc.spawnDistance. |
Interaction.
| Field | Type | Description |
|---|---|---|
label | string | Text of the target option. Defaults to "Talk". |
targetIcon | string | Font Awesome class of the target option. Defaults to target.icon. |
activeDistance | number | Metres from which the player can interact. Defaults to target.distance. |
interaction | string | 'target', 'sprite' or 'none'. Defaults to interaction of the config. |
camera | boolean | false opens without moving the camera. |
blip | table | { id, scale, colour, name }. id is the blip sprite. Defaults: scale 0.6, colour 0. Needs coords. The blip is created when the point is registered, whatever the distance to the player. |
Conditions. All of them must pass for the option to appear.
| Field | Type | Description |
|---|---|---|
job | string | table | 'police', { 'police', 'ambulance' } (any), or { police = 2 } (minimum grade). |
item | string | table | 'lockpick', { 'lockpick', 'phone' } (all), or { lockpick = 3 } (minimum units). |
canInteract | function | function(ctx). Must return true. |
enabled | boolean | false leaves the point unregistered. |
Content.
| Field | Type | Description |
|---|---|---|
dialog | table | List of pages. The first enabled page is the one shown. |
shop | table | Shop of the point. Without dialog the point opens the shop directly; with dialog, a button with shop = true opens it. |
onInteract | function | function(ctx). Runs instead of opening the dialogue or the shop. |
extraData | table | Your own data, delivered in ctx.extraData. |
Dialogue page
| Field | Type | Description |
|---|---|---|
id | string | number | Unique within the dialogue. Used by nextDialog and SwitchDialog. |
name | string | Who speaks. |
job | string | Role shown in the header. Text only, not a condition. |
text | string | What the NPC says. |
textSpeed | number | Milliseconds per character. Defaults to dialog.textSpeed. |
icon | string | Icon of the header. See Icons. |
enabled | boolean | false skips the page. |
buttons | table | List of buttons. |
Dialogue button
| Field | Type | Description |
|---|---|---|
id | string | number | Id of the button. It is what ShowDialog returns when the button closes. |
label | string | Text of the button. |
icon | string | Icon of the button. See Icons. |
enabled | boolean | false hides the button. |
job, item, canInteract | Conditions, as in the point. A button that fails is not sent to the interface and cannot be run. | |
close | boolean | Closes the dialogue. |
onSelect | function | function(ctx). |
event | string | Client event: TriggerEvent(event, args, info). |
serverEvent | string | Server event: TriggerServerEvent(serverEvent, args, info). |
args | any | Value sent as the first argument of event and serverEvent. |
shop | boolean | Opens the shop of the point. |
nextDialog | string | number | id of the page to show next. |
A button runs its actions in this order: close, onSelect, event, serverEvent, and then shop or nextDialog. With close = true the last step is skipped. shop wins over nextDialog.
Shop
| Field | Type | Description |
|---|---|---|
id | string | Id registered with RegisterShop. In a point it defaults to the id of the point. |
name | string | Name of the trader. Defaults to "Seller". |
job | string | Role shown in the header. Defaults to "Merchant". |
icon | string | Icon of the header. See Icons. |
The items, prices and modes come from RegisterShop on the server.
The ctx table
Received by onSelect, canInteract and onInteract.
| Field | Type | Description |
|---|---|---|
id | string | Id of the point. nil in a dialogue opened with ShowDialog without data.id. |
entity | integer | Ped of the point, if any. ctx.ped holds the same value. |
dialogId | string | number | id of the current page. Only in buttons. |
buttonId | string | number | id of the button. Only in buttons. |
index | integer | Position of the button in the page. Only in buttons. |
extraData | table | The extraData of the point or of ShowDialog. |
The info table
Second argument of event and serverEvent.
| Field | Type | Description |
|---|---|---|
id | string | Id of the point. |
dialogId | string | number | id of the page. |
buttonId | string | number | id of the button. |
entity | integer | Ped handle on the client that sent it. |
netId | integer | Network id of the ped. Only when the ped is networked; the peds created by a point are local and have none. |
A net event registered with RegisterNetEvent can be triggered by any client at any time. In the handler of a serverEvent, check the player (source), the distance to the NPC and whatever the action requires. Never trust args or info.
Functions sent through exports
onSelect, canInteract and onInteract are functions of your resource called from Cuxial Interactions. Keep in mind:
canInteractof a point is evaluated while the player aims at it, with the result reused fordialog.conditionIntervalmilliseconds, and once more on selection. Keep it cheap.- An error inside any of them does not break the dialogue. It leaves a warning in the client console.
- Do not keep
ctxafter the call returns. - When an event is enough, prefer
eventorserverEvent: they do not depend on function references.
Icons
targetIcon takes a Font Awesome class, because it is drawn by your target resource.
The icon of pages, buttons and shops takes one of these names:
arrow-left, arrow-right, bed, book, book-open, briefcase, car, check, circle-alert, circle-check, circle-play, circle-question-mark, circle-x, clipboard, clipboard-plus, dollar-sign, door-open, fish, folder-open, gamepad-2, hand, hand-coins, hand-heart, heart, hospital, house, id-card, info, key, log-out, message-circle, message-circle-more, messages-square, package, phone, pill, shield, shopping-cart, skull, stethoscope, store, thumbs-up, undo-2, user, user-pen, venetian-mask, wrench, x.
Any other name shows a speech bubble. In the header of a shop it shows a store.
