Export: nx_racing.getActiveRaces
The export nx_racing.getActiveRaces
retrieves a list of all active races currently in progress or awaiting participants. This is useful for scripts or resources that need to display or interact with ongoing or ready-to-start races.
Export Details
- Export Name:
nx_racing.getActiveRaces
- Description: Returns a table of all active races, including their race IDs, associated track IDs, and current statuses.
Usage
To call this export, use the following syntax:
local activeRaces = exports.nx_racing:getActiveRaces()
Parameters
This export does not take any parameters.
Return Value
A table containing information about all active races. Each entry in the table represents a race with the following structure:
raceId
(number): The unique identifier for the race.trackId
(number): The identifier of the track associated with the race.status
(number): The current status of the race, where:0
indicates the race is open for participants.1
indicates the race is in progress.
If no active races are found, the function returns an empty table.
Example Usage
Fetching Active Races
local activeRaces = exports.nx_racing:getActiveRaces()
if #activeRaces > 0 then
for _, race in ipairs(activeRaces) do
print("Race ID:", race.raceId)
print("Track ID:", race.trackId)
print("Status:", race.status)
end
else
print("No active races found.")
end
Notes
- Ensure that the database table
racing_races
is correctly populated and uses the fieldsid
,trackId
, andstatus
. - The statuses
0
and1
are integral for determining whether a race is open or in progress. Other statuses are excluded from this export.