Integration

Exports, events, and API reference

Integration

The Legacy Scoreboard integrates with your server through callbacks, commands, and keybinds. Here's the complete API reference.

Callbacks (Server)

The script registers several server-side callbacks using ox_lib:

`legacy-scoreboard:getInitData`

Description: Returns initial data when the scoreboard is first opened.

Parameters: None

Returns: InitData object containing:

  • server: Server metadata
  • players: Array of player objects
  • spark: Player count history array
  • uptimeSeconds: Server uptime in seconds
  • restartSeconds: Seconds until next restart
  • accent: Accent color from legacy-lib
  • logo: Server logo URL (if available)
  • logoText: Logo text from config
  • roles: Role definitions array
  • quickLinks: Footer links array
  • refreshIntervalMs: Refresh interval
  • locale: Localization strings

Example Usage:

lua
-- Client-side
local initData = lib.callback.await('legacy-scoreboard:getInitData', false)
if initData then
    print('Server:', initData.server.name)
    print('Players online:', #initData.players)
end

`legacy-scoreboard:getRefresh`

Description: Returns refreshed data for live updates.

Parameters: None

Returns: RefreshData object containing:

  • players: Updated player array
  • spark: Updated sparkline data
  • uptimeSeconds: Current uptime
  • restartSeconds: Seconds until restart

`legacy-scoreboard:toggleAnonymous`

Description: Toggles the player's anonymous status.

Parameters: None

Returns: boolean - New anonymous state

Example Usage:

lua
-- Client-side
local isAnonymous = lib.callback.await('legacy-scoreboard:toggleAnonymous', false)
print('Anonymous mode:', isAnonymous)

Commands

The script registers the following commands:

`+scoreboard`

Description: Opens the scoreboard (press action)

Default Keybind: HOME

`-scoreboard`

Description: Closes the scoreboard (release action - no functionality)

`+scoreboardFocus`

Description: Toggles interactive focus mode

Default Keybind: J

`-scoreboardFocus`

Description: Focus release action (no functionality)

NUI Callbacks

The client handles these NUI callbacks from the web interface:

`close`

Description: Triggered when the UI requests to close the scoreboard.

Data: None

Response: 'ok'

`toggleFocus`

Description: Triggered when the UI requests to toggle focus mode.

Data: None

Response: { focused: boolean }

`toggleAnonymous`

Description: Triggered when the UI requests to toggle anonymous mode.

Data: None

Response: { anonymous: boolean }

NUI Messages

The client sends these messages to the NUI:

`open`

Description: Opens the scoreboard with initial data.

Data: InitData object

`refresh`

Description: Updates the scoreboard with new data.

Data: RefreshData object

`close`

Description: Closes the scoreboard.

Data: None

`focusChange`

Description: Updates the focus state.

Data: { focused: boolean }

Web Interface (fetchNui)

The React UI uses these fetch functions:

typescript
// Close the scoreboard
await fetchNui('close');

// Toggle focus mode
const result = await fetchNui<{ focused: boolean }>('toggleFocus');

// Toggle anonymous mode
const result = await fetchNui<{ anonymous: boolean }>('toggleAnonymous');

Data Types

Player Object

lua
{
    id = number,          -- Server ID
    name = string,        -- Display name (Anonymous if hidden)
    ping = number,        -- Player ping
    role = string|nil,    -- Job role key (leo, ems, etc.)
    onDuty = boolean,     -- On-duty status
    isYou = boolean,      -- Is the requesting player
    isStaff = boolean,    -- Has admin permissions
    isDonator = boolean,  -- Has donator status
    isStreamer = boolean, -- Has streamer status
    isAnonymous = boolean -- Is in anonymous mode
}

Server Metadata

lua
{
    name = string,       -- Server name from config
    patch = string,      -- Server patch version
    maxPlayers = number, -- Max player capacity
    queue = number       -- Queue count (always 0 in current version)
}

Example Integration

lua
-- Custom command to check if scoreboard is open
RegisterCommand('scoreboardstatus', function()
    if isOpen then
        TriggerEvent('chat:addMessage', {
            args = { 'Scoreboard is currently open' }
        })
    else
        TriggerEvent('chat:addMessage', {
            args = { 'Scoreboard is currently closed' }
        })
    end
end)

-- Listen for scoreboard state changes
RegisterNetEvent('legacy-scoreboard:stateChanged')
AddEventHandler('legacy-scoreboard:stateChanged', function(state)
    print('Scoreboard state:', state) -- 'open' or 'closed'
end)

Framework Integration

The scoreboard relies on legacy-lib for framework integration:

  • Framework.GetPlayerName(src) - Get player's first and last name
  • Framework.GetPlayerJobData(src) - Get job information including onDuty status
  • Framework.GetIsFrameworkAdmin(src) - Check if player is admin
  • exports['legacy-lib']:GetAccentColor() - Get server accent color
  • exports['legacy-lib']:GetLogo() - Get server logo URL

The scoreboard automatically adapts to different frameworks through the legacy-lib abstraction layer.