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 metadataplayers: Array of player objectsspark: Player count history arrayuptimeSeconds: Server uptime in secondsrestartSeconds: Seconds until next restartaccent: Accent color from legacy-liblogo: Server logo URL (if available)logoText: Logo text from configroles: Role definitions arrayquickLinks: Footer links arrayrefreshIntervalMs: Refresh intervallocale: Localization strings
Example Usage:
-- 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 arrayspark: Updated sparkline datauptimeSeconds: Current uptimerestartSeconds: Seconds until restart
`legacy-scoreboard:toggleAnonymous`
Description: Toggles the player's anonymous status.
Parameters: None
Returns: boolean - New anonymous state
Example Usage:
-- 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:
// 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
{
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
{
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
-- 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 nameFramework.GetPlayerJobData(src)- Get job information including onDuty statusFramework.GetIsFrameworkAdmin(src)- Check if player is adminexports['legacy-lib']:GetAccentColor()- Get server accent colorexports['legacy-lib']:GetLogo()- Get server logo URL
The scoreboard automatically adapts to different frameworks through the legacy-lib abstraction layer.