Skip to content

Exports & events

Public API of Cuxial Interactions: register NPCs, dialogues and shops from your own resources, read shop limits and customise the hooks.

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 ​

SideExportReturns
ClientRegister(id, def)boolean
ClientUpdate(id, patch)boolean
ClientRemove(id)boolean
ClientExists(id)boolean
ClientGetEntity(id)integer or nil
ClientInteract(id)boolean
ClientShowDialog(data)id of the closing button, or nil
ClientSwitchDialog(dialogId)boolean
ClientShowShop(data)boolean or nil
ClientClose()boolean
ClientIsOpen()boolean
ServerRegisterShop(id, items, options)boolean
ServerRemoveShop(id)boolean
ServerGetShop(id)table or nil
ServerGetShopLimits(src, shopId)table or nil
ServerResetShopLimits(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.

Declare the dependency ​

my_resource/fxmanifest.lua
lua
dependency 'cuxial_interactions'

Register the shop on the server ​

my_resource/server.lua
lua
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 ​

my_resource/client.lua
lua
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.

lua
exports.cuxial_interactions:Register(id, def)
ParameterTypeDescription
idstringUnique id of the point. Not empty.
deftableDefinition 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.

lua
-- 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.

lua
exports.cuxial_interactions:Update(id, patch)
ParameterTypeDescription
idstringId of the point.
patchtableFields 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.

lua
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.

lua
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.

lua
local registered = exports.cuxial_interactions:Exists(id)

Returns: boolean.

GetEntity ​

Returns the ped of a point.

lua
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.

lua
local ped = exports.cuxial_interactions:GetEntity('my_resource:scrap_buyer')
if ped then PlayAmbientSpeech1(ped, 'GENERIC_HI', 'SPEECH_PARAMS_FORCE') end

Interact ​

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.

lua
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.

lua
if not exports.cuxial_interactions:Interact('my_resource:scrap_buyer') then
    lib.notify({ description = 'He does not want to talk to you.', type = 'error' })
end

ShowDialog ​

Opens a dialogue that is not tied to a registered point. The call waits until the dialogue closes.

lua
local result = exports.cuxial_interactions:ShowDialog(data)
ParameterTypeDescription
data.dialogtableList of pages. Required. See Dialogue page.
data.entityintegerPed the camera focuses on. Optional.
data.shoptableShop opened by the buttons with shop = true. See Shop.
data.extraDatatableYour own data, delivered in ctx.extraData.
data.camerabooleanfalse opens without moving the camera.
data.idstringId 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.

lua
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')
end

ShowDialog 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.

lua
exports.cuxial_interactions:SwitchDialog(dialogId)
ParameterTypeDescription
dialogIdstring | numberid of a page of the open dialogue.

Returns: boolean. false when no dialogue is open or the page does not exist or is disabled.

lua
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.

lua
exports.cuxial_interactions:ShowShop(data)
ParameterTypeDescription
datatableA 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.

lua
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.

lua
exports.cuxial_interactions:Close()

Returns: boolean. false when nothing was open.

IsOpen ​

Tells whether a dialogue or a shop is open.

lua
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.

AliasEquivalent
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.

lua
exports.cuxial_interactions:RegisterShop(id, items, options)
ParameterTypeDescription
idstringId 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.
itemstableList of items. See below.
options.coordsvector3 | vector4 | tablePosition of the shop, or a list of positions.
options.netIdintegerNetwork id of a networked ped; the distance is measured to it.
options.anywherebooleantrue accepts trades from any distance.
options.distancenumberMaximum metres to coords or to the ped. Defaults to shop.maxDistance of the config.
options.accountstringAccount where sales are paid and purchases are charged. Defaults to shop.account of the config.
options.modestring'sell' (the player sells, the NPC pays) or 'buy' (the player buys). Default for items without their own mode. Defaults to 'sell'.
options.limitstableLimits of the whole shop. See Shop limit.
options.jobstring | tableJob condition, checked on the server when opening the shop and on every trade. Same format as in Point definition.
options.itemstring | tableItem condition, checked the same way.

One of coords, netId or anywhere = true is required.

Each entry of items:

FieldTypeDescription
namestringItem name. Required.
pricenumberUnit price, 0 or more. Required.
labelstringDefaults to the label of the inventory.
imagestringURL of the image.
modestring'sell' or 'buy'. Defaults to options.mode. The same item can appear once in each mode, with different prices.
limitstableLimits 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.

lua
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).

FieldTypeDescription
amountinteger1 to 1 000 000. Required.
windowintegerSeconds, from 60 up to limits.maxWindow. Required. Windows slide: what was done in the last window seconds is added up.
scopestring'player' (each character, by its identifier) or 'global' (shared by every player; works as stock). Default 'player'.
measurestring'units' or 'money' moved. Default 'units'.
modestringOnly in shop limits: '' (both modes), 'buy' or 'sell'. Default ''.

RemoveShop ​

Removes a shop you own.

lua
exports.cuxial_interactions:RemoveShop(id)

Returns: boolean. false when the shop does not exist or belongs to another resource.

GetShop ​

Returns a registered shop.

lua
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'.

lua
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
end

GetShopLimits ​

Returns, for one player, what the limits of a shop still allow.

lua
local limits = exports.cuxial_interactions:GetShopLimits(src, shopId)
ParameterTypeDescription
srcintegerServer id of the player.
shopIdstringId 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.

lua
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)) end

ResetShopLimits ​

Deletes the limit records that match the filters. Every parameter is optional.

lua
local deleted = exports.cuxial_interactions:ResetShopLimits(identifier, shopId, item)
ParameterTypeDescription
identifierstring | nilCharacter identifier. nil for every player.
shopIdstring | nilId of the shop. nil for every shop.
itemstring | nilItem name. nil for every item.

Returns: integer, the number of records deleted.

lua
-- 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.

lua
-- 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:

ActionHow your code is called
Server exportexports[resource][name](src, ...args, ...values). Returning false counts as a failure.
Server eventLocal server event: AddEventHandler('my:event', function(src, ...args, ...values) end). It is not a net event, so clients cannot trigger it.
Client exportexports[resource][name](...args, ...values) on the player's client. With context, { id, dialogId, buttonId, entity, netId } is appended at the end.
Client eventTriggerEvent(name, ...args, ...values) on the player's client, with the same optional context.
CommandExecuteCommand 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.

my_resource/server.lua
lua
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/) ​

HookWhenReturns
notify(src, key, kind, ...)Every notification to the player—
filterCatalog(src, shopId, items)On opening the shop and on every tradeList of visible items (only items of the shop are accepted)
canSell(src, shop, item, qty)Before sellingboolean, optional locale key as reason
getPrice(src, shop, item, qty)When listing (qty = 1) and on every tradeUnit price, finite number ≥ 0
takeItems(src, name, qty)Remove the items soldboolean
payout(src, account, total, reason)Pay the saleboolean
giveBack(src, name, qty)If the payment failsboolean
onSold(src, sale)Sale completed—
canBuy(src, shop, item, qty)Before buyingboolean, optional locale key as reason
canCarry(src, name, qty)Before charging a purchaseboolean
charge(src, account, total, reason)Charge the purchaseboolean, optional reason
giveItems(src, name, qty)Give what was boughtboolean
refund(src, account, total, reason)If the items cannot be givenboolean
onBought(src, sale)Purchase completed—
canRevive(src, opts)On a "Revive" actionboolean, optional reason
reviveCost(src, opts)Before charging the revivecost (integer ≥ 0), account
revive(src, opts)After charging; false returns the moneyboolean
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.

lua
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) end

Client (hooks/client/) ​

HookWhenReturns
notify(key, kind, ...)Every local notification—
canOpen(id, def)Before opening a dialogue or a shopboolean (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 interactiveOwn handle or false
detach(point, handle)The point stops being interactive—
createBlip(blip, coords)On registering a point with a blipBlip id
applySkin(entity, appearance)NPC with a player lookboolean
onPedSpawned(entity, id, def)After creating an NPC—
cameraFor(entity)On talking to an NPCposition, rotation (vector3), or false for no camera
itemImage(name)Image of an item without imageURL
lua
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) end

Keep 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.

FieldTypeDescription
coordsvector3 | vector4Position 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.
entityintegerA ped or object that already exists on this client. It is not created or deleted by the point.
netIdintegerThe same, by network id. The point attaches when the entity comes into range.

Ped. Only for points with coords that create their own ped.

FieldTypeDescription
modelstring | numberPed model. If it does not exist, npc.fallbackModel is used.
usePlayerSkinbooleantrue gives the ped the look of a random active character. Falls back to model when no look is available.
headingnumberHeading, when coords is a vector3.
scenariostringScenario the ped plays, such as 'WORLD_HUMAN_CLIPBOARD'.
animationtable{ dict, clip, speed, blendOut, duration, flag }. dict and clip are required. Defaults: 8.0, -8.0, -1, 1.
clothingtableList of { componentIndex, variation, texture }. Not applied when the ped got a player look.
behaviortable{ invincible, noTemporaryEvents, freeze }, each a boolean.
spawnDistancenumberMetres at which the ped is created. Defaults to npc.spawnDistance.

Interaction.

FieldTypeDescription
labelstringText of the target option. Defaults to "Talk".
targetIconstringFont Awesome class of the target option. Defaults to target.icon.
activeDistancenumberMetres from which the player can interact. Defaults to target.distance.
interactionstring'target', 'sprite' or 'none'. Defaults to interaction of the config.
camerabooleanfalse opens without moving the camera.
bliptable{ 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.

FieldTypeDescription
jobstring | table'police', { 'police', 'ambulance' } (any), or { police = 2 } (minimum grade).
itemstring | table'lockpick', { 'lockpick', 'phone' } (all), or { lockpick = 3 } (minimum units).
canInteractfunctionfunction(ctx). Must return true.
enabledbooleanfalse leaves the point unregistered.

Content.

FieldTypeDescription
dialogtableList of pages. The first enabled page is the one shown.
shoptableShop of the point. Without dialog the point opens the shop directly; with dialog, a button with shop = true opens it.
onInteractfunctionfunction(ctx). Runs instead of opening the dialogue or the shop.
extraDatatableYour own data, delivered in ctx.extraData.

Dialogue page ​

FieldTypeDescription
idstring | numberUnique within the dialogue. Used by nextDialog and SwitchDialog.
namestringWho speaks.
jobstringRole shown in the header. Text only, not a condition.
textstringWhat the NPC says.
textSpeednumberMilliseconds per character. Defaults to dialog.textSpeed.
iconstringIcon of the header. See Icons.
enabledbooleanfalse skips the page.
buttonstableList of buttons.

Dialogue button ​

FieldTypeDescription
idstring | numberId of the button. It is what ShowDialog returns when the button closes.
labelstringText of the button.
iconstringIcon of the button. See Icons.
enabledbooleanfalse hides the button.
job, item, canInteractConditions, as in the point. A button that fails is not sent to the interface and cannot be run.
closebooleanCloses the dialogue.
onSelectfunctionfunction(ctx).
eventstringClient event: TriggerEvent(event, args, info).
serverEventstringServer event: TriggerServerEvent(serverEvent, args, info).
argsanyValue sent as the first argument of event and serverEvent.
shopbooleanOpens the shop of the point.
nextDialogstring | numberid 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 ​

FieldTypeDescription
idstringId registered with RegisterShop. In a point it defaults to the id of the point.
namestringName of the trader. Defaults to "Seller".
jobstringRole shown in the header. Defaults to "Merchant".
iconstringIcon 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.

FieldTypeDescription
idstringId of the point. nil in a dialogue opened with ShowDialog without data.id.
entityintegerPed of the point, if any. ctx.ped holds the same value.
dialogIdstring | numberid of the current page. Only in buttons.
buttonIdstring | numberid of the button. Only in buttons.
indexintegerPosition of the button in the page. Only in buttons.
extraDatatableThe extraData of the point or of ShowDialog.

The info table ​

Second argument of event and serverEvent.

FieldTypeDescription
idstringId of the point.
dialogIdstring | numberid of the page.
buttonIdstring | numberid of the button.
entityintegerPed handle on the client that sent it.
netIdintegerNetwork 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:

  • canInteract of a point is evaluated while the player aims at it, with the result reused for dialog.conditionInterval milliseconds, 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 ctx after the call returns.
  • When an event is enough, prefer event or serverEvent: 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.

© Cuxial