NightZoom LogoNightZoom

Server Integration

Server-side exports and events for NZ Objective v1

This page covers server-side functionality for NZ Objective v1. These functions manage objective logic, persistence, and player data.

Server Exports

ExportParametersReturnsDescription
addObjective(data)data: tablebooleanAdds a new objective for a player
updateObjective(id, data)id: string, data: tablebooleanUpdates an existing objective by id
removeObjective(id)id: stringbooleanRemoves an objective by id
getObjectives(playerId)playerId: numbertableReturns all objectives for a player
completeObjective(id, playerId)id: string, playerId: numberbooleanMarks an objective as completed

Server Events

Receiving Events

EventParametersDescription
nz_objective:server:objectiveCompletedid: stringPlayer completed an objective client-side
nz_objective:server:requestObjectivesplayerId: numberClient requests their objectives

Triggering Events

EventParametersDescription
nz_objective:client:showObjectivedata: tableSend objective to client for display
nz_objective:client:hideObjectiveid: stringRemove objective from client display
nz_objective:client:updateProgressid: string, progress: numberUpdate objective progress on client

Parameter Details

addObjective / updateObjective

  • data: table with the following fields:
    • playerId: number — Target player ID
    • id: string — Unique objective ID (required for update)
    • title: string — Objective title
    • description: string — Objective description
    • progress: number — Current progress (optional, default: 0)
    • required: number — Amount required to complete (optional, default: 1)
    • completed: boolean — Completion status (optional, default: false)
    • reward: any — Reward data (optional)
    • meta: table — Any additional metadata (optional)

Example Usage

-- Add a new objective for a player
local success = exports['nz_objective']:addObjective({
    playerId = 1,
    id = 'collect_apples',
    title = 'Collect 5 Apples',
    description = 'Find and collect 5 apples in the forest.',
    progress = 0,
    required = 5,
    reward = { money = 100 }
})

-- Update objective progress
exports['nz_objective']:updateObjective('collect_apples', {
    playerId = 1,
    progress = 3
})

-- Complete an objective
exports['nz_objective']:completeObjective('collect_apples', 1)

-- Get all objectives for a player
local objectives = exports['nz_objective']:getObjectives(1)
for _, objective in pairs(objectives) do
    print(objective.title, objective.progress, objective.required)
end

-- Listen for client completion
RegisterNetEvent('nz_objective:server:objectiveCompleted', function(id)
    local playerId = source
    exports['nz_objective']:completeObjective(id, playerId)
end)

Always validate player permissions and objective ownership before updating or completing objectives.