NightZoom LogoNightZoom

Server Integration

This page covers server-side functionality for NZ Dialog v1. These functions handle server-initiated dialogs and response processing.

Server Exports

ExportParametersReturnsDescription
showDialogToPlayer(playerId, data, cb)playerId: number, data: table, cb: functionvoidShows a dialog to a specific player
closeDialogForPlayer(playerId)playerId: numbervoidCloses dialog for a specific player
showDialogToAll(data, cb)data: table, cb: functionvoidShows a dialog to all players

Server Events

Receiving Events

EventParametersDescription
nz_dialog:server:dialogResponsedialogId: string, response: anyPlayer responded to a dialog

Triggering Events

EventParametersDescription
nz_dialog:client:showDialogdata: tableSend dialog to client for display
nz_dialog:client:closeDialognoneClose dialog on client

Parameter Details

showDialogToPlayer / showDialogToAll

  • playerId: Target player's server ID (number)
  • data: table with the following fields:
    • id: string — Unique dialog ID
    • title: string — Dialog title
    • message: string — Dialog message/content
    • type: string — Dialog type ('confirm', 'input', 'select', etc.)
    • options: table — Array of option objects (for select dialogs)
    • placeholder: string — Input placeholder (for input dialogs)
    • timeout: number — Auto-close timeout in milliseconds (optional)
  • cb: callback function that receives the player's response

Example Usage

-- Show confirmation dialog to a player
exports['nz_dialog']:showDialogToPlayer(1, {
    id = 'admin_confirm',
    title = 'Admin Action',
    message = 'Are you sure you want to kick this player?',
    type = 'confirm'
}, function(response, playerId)
    if response then
        print('Admin confirmed action for player', playerId)
        -- Perform admin action
    end
end)

-- Show input dialog to player
exports['nz_dialog']:showDialogToPlayer(1, {
    id = 'report_reason',
    title = 'Report Player',
    message = 'Please provide a reason for the report:',
    type = 'input',
    placeholder = 'Enter reason...'
}, function(response, playerId)
    if response and response ~= '' then
        print('Report reason:', response, 'from player', playerId)
        -- Process report
    end
end)

-- Show selection dialog to all players
exports['nz_dialog']:showDialogToAll({
    id = 'server_vote',
    title = 'Server Vote',
    message = 'Vote for the next event:',
    type = 'select',
    options = {
        { label = 'Racing Event', value = 'racing' },
        { label = 'PvP Event', value = 'pvp' },
        { label = 'Roleplay Event', value = 'rp' }
    }
}, function(response, playerId)
    if response then
        print('Player', playerId, 'voted for:', response)
        -- Process vote
    end
end)

-- Listen for dialog responses
RegisterNetEvent('nz_dialog:server:dialogResponse', function(dialogId, response)
    local playerId = source
    print('Dialog response:', dialogId, response, 'from player', playerId)
end)

-- Close dialog for a player
exports['nz_dialog']:closeDialogForPlayer(1)

Always validate player permissions before showing sensitive dialogs or processing responses.