Skip to content

Exports

Dependencies, database, server.cfg order, and a quick test.

Exports#

All exports below are server-side.

Use them from another resource like this:

lua
local data = exports['0r-soccer']:GetLeaderboard(10, 'goals')

Make sure 0r-soccer is started before your script calls these exports.


Stats and leaderboard#

GetLeaderboard(limit?, orderBy?)#

Returns raw leaderboard rows from the database.

ArgumentTypeDefaultDescription
limitnumberconfig defaultMax rows
orderBystring"goals""goals", "assists", or "matches"
lua
local rows = exports['0r-soccer']:GetLeaderboard(10, 'goals')
-- each row: identifier, name, goals, assists, matches

GetLeaderboardTable(limit?, orderBy?)#

Same data, but formatted as a table for UIs:

lua
local tableData = exports['0r-soccer']:GetLeaderboardTable(10, 'assists')
-- tableData.columns, tableData.rows, tableData.rowCount

GetPlayerStats(identifierOrSource)#

Get one player’s total stats.

You can pass:

  • a player server id (source), or
  • a full identifier string (example: license:...)
lua
local stats = exports['0r-soccer']:GetPlayerStats(source)
-- or
local stats = exports['0r-soccer']:GetPlayerStats('license:abcd...')

Returns nil if not found.

GetPlayerMatchHistory(identifierOrSource, limit?, offset?)#

Formatted match history for one player (wins/losses, goals in match, etc.).

lua
local history = exports['0r-soccer']:GetPlayerMatchHistory(source, 15, 0)

GetPlayerMatchHistoryRaw(identifierOrSource, limit?, offset?)#

Same query, raw SQL-style fields.

GetPlayerMatchHistoryTable(identifierOrSource, limit?, offset?)#

History packed as { columns, rows, rowCount } for tablets / NUI tables.

GetRecentTopScorers(days?, limit?)#

Top scorers in the last X days (from match history).

lua
local top = exports['0r-soccer']:GetRecentTopScorers(7, 10)

GetMatchById(matchId)#

Returns one finished match + participants.

lua
local match = exports['0r-soccer']:GetMatchById(42)

Live pitches and lobbies#

GetPitchOverview()#

List of configured pitches and whether they are busy.

lua
local pitches = exports['0r-soccer']:GetPitchOverview()
-- pitchId, pitchName, isBusy, state, playerCount, lobby, coords, ...

GetPitchOverviewTable()#

Same overview in table format (columns + rows).

GetActiveLobbies()#

All active lobbies (waiting, warmup, playing, paused, …).

lua
local lobbies = exports['0r-soccer']:GetActiveLobbies()

GetActiveLobbiesTable()#

Active lobbies in table format.

GetServerSummary()#

Quick server snapshot:

lua
local summary = exports['0r-soccer']:GetServerSummary()
--[[
  activeLobbyCount
  activeMatchCount
  waitingLobbyCount
  playersInSoccer
  pitchCount
  busyPitchCount
  generatedAt
]]

GetTabletBridgeSnapshot()#

One call for tablets / dashboards:

lua
local snap = exports['0r-soccer']:GetTabletBridgeSnapshot()
-- snap.pitchOverview
-- snap.activeLobbies
-- snap.serverSummary

Player match state#

IsPlayerInMatch(source)#

Returns true if the player is currently in a soccer lobby/match.

lua
if exports['0r-soccer']:IsPlayerInMatch(source) then
    -- block other activities, etc.
end

GetPlayerLobbyId(source)#

Returns the lobby id, or nil.

lua
local lobbyId = exports['0r-soccer']:GetPlayerLobbyId(source)

Stadium scoreboard (DUI)#

These control the in-world scoreboard display.

With the default driver (ScoreboardDriver = "soccer"), lobbies already update the board. Use these exports mainly for custom / external integrations.

StartFootballMatch(payload)#

Start / show a match on the stadium board.

lua
exports['0r-soccer']:StartFootballMatch({
    homeName = 'Red Team',
    awayName = 'Blue Team',
    homeScore = 0,
    awayScore = 0,
    minutes = 20,      -- or totalSeconds / elapsedSeconds
    state = 'playing',
    status = 'LIVE',
})

UpdateFootballScore(payload)#

lua
exports['0r-soccer']:UpdateFootballScore({
    homeScore = 2,
    awayScore = 1,
    homeName = 'Red Team',
    awayName = 'Blue Team',
})

UpdateFootballTime(payload)#

lua
exports['0r-soccer']:UpdateFootballTime({
    elapsedSeconds = 600,
    totalSeconds = 1200,
    -- or timeLeft = 600
})

GoalScored(payload)#

Shows a goal overlay and can bump the score.

lua
exports['0r-soccer']:GoalScored({
    scoringTeam = 1,       -- 1 = home, 2 = away
    scorerName = 'Alex',
    isOwnGoal = false,
    -- optional: homeScore / awayScore to set exact score
})

GetFootballMatchState()#

Returns the current stadium board snapshot.

lua
local state = exports['0r-soccer']:GetFootballMatchState()

Optional server events#

If Config.API.EnableServerEvents is enabled, you can also use event-style queries:

lua
local requestId = 'my-request-1'

TriggerEvent('0r-soccer:server:ApiQuery', 'leaderboard', { limit = 10 }, requestId)

AddEventHandler('0r-soccer:server:ApiQueryResult', function(rid, ok, payload)
    if rid ~= requestId then return end
    if not ok then return end
    print(json.encode(payload))
end)

When a match is saved to the database, this event is fired:

lua
AddEventHandler('0r-soccer:matchSaved', function(matchId, lobbyId, endReason, info)
    -- info.pitchId, info.score1, info.score2, info.winnerTeam, ...
end)

Example: tablet leaderboard#

lua
RegisterCommand('soccer_top', function(source)
    local tableData = exports['0r-soccer']:GetLeaderboardTable(10, 'goals')
    for _, row in ipairs(tableData.rows or {}) do
        print(('#%s %s — %s goals'):format(row.rank, row.name, row.goals))
    end
end, true)