Read the open classes, close one, or react when a class starts, a student joins or a dance ends. Everything here runs on the server; there are no client exports.
Server exports
GetRooms
Returns every open class.
local rooms = exports.cuxial_danceclass:GetRooms()Returns: table[], sorted by id. Each entry is a room summary.
for _, room in ipairs(exports.cuxial_danceclass:GetRooms()) do
print(room.name, room.studentCount .. '/' .. room.maxStudents)
endGetPlayerRoom
Returns the class a player is in and their role.
local room, role = exports.cuxial_danceclass:GetPlayerRoom(source)| Parameter | Type | Description |
|---|---|---|
source | number | Server id of the player. |
Returns: table | nil, string | nil. The room summary and the role, 'instructor' or 'student'. nil when the player is not in a class.
local room, role = exports.cuxial_danceclass:GetPlayerRoom(source)
if role == 'instructor' then
print(('Teaching %s'):format(room.name))
endIsInClass
Tells whether a player is in a class, as instructor or student.
local inClass = exports.cuxial_danceclass:IsInClass(source)| Parameter | Type | Description |
|---|---|---|
source | number | Server id of the player. |
Returns: boolean.
if exports.cuxial_danceclass:IsInClass(source) then return endCloseRoom
Closes a class from another resource. If at least one dance was played, the class ends with its podium and the history is saved; otherwise it just closes and fees are refunded as set in rooms.refundIfNoRound.
local closed = exports.cuxial_danceclass:CloseRoom(id)| Parameter | Type | Description |
|---|---|---|
id | number | Id of the class. |
Returns: boolean. false when no class has that id.
for _, room in ipairs(exports.cuxial_danceclass:GetRooms()) do
exports.cuxial_danceclass:CloseRoom(room.id)
endRoom summary
| Field | Type | Description |
|---|---|---|
id | number | Id of the class. |
name | string | Name of the class. |
difficulty | string | Difficulty id: easy, normal or hard. |
difficultyLabel | string | Difficulty name from the config. |
fee | number | Entry fee. 0 = free. |
maxStudents | number | Capacity. |
instructor | table | { id, name, points }. |
students | table[] | { id, name, points, rounds, accuracy, bestAccuracy }, sorted by points. Accuracy goes from 0 to 1. |
studentCount | number | Students in the class. |
phase | string | lobby (not started), countdown, round or results (between dances). |
roundIndex | number | Dances played so far. |
maxRounds | number | Dances allowed per class. |
playlist | string[] | nil | Dances picked by the instructor. nil = random. |
currentDance | table | nil | { command, label } of the current or last dance. |
role | string | nil | Only with GetPlayerRoom: role of that player. |
Server events
Each event is triggered on the server with one table. Listen with AddEventHandler.
| Event | Payload | When |
|---|---|---|
cuxial_danceclass:roomCreated | { id, instructor, difficulty } | A class opens. instructor is a server id. |
cuxial_danceclass:roomClosed | { id, reason } | A class closes. reason: closed, left, ended or disconnected. |
cuxial_danceclass:studentJoined | { id, source } | A student joins. |
cuxial_danceclass:studentLeft | { id, source, reason } | A student leaves a class that stays open. reason: left, zone, kicked or disconnected. |
cuxial_danceclass:roundStarted | { id, index, dance } | A dance starts. dance is its command. |
cuxial_danceclass:roundEnded | { id, index, results } | A dance ends. |
cuxial_danceclass:classEnded | { id, rounds, ranking } | A class with at least one dance ends, right before roomClosed. |
Each entry of results has id, name, perfect, good, miss, total, accuracy, maxStreak, points and totalPoints. Each entry of ranking has id, name, points, rounds, accuracy and bestAccuracy.
studentLeft is not sent for the students still inside when a class closes. Use roomClosed for that case.
AddEventHandler('cuxial_danceclass:roundEnded', function(data)
for _, result in ipairs(data.results) do
if result.accuracy >= 0.9 then
print(('%s nailed dance %d'):format(result.name, data.index))
end
end
end)on / off
The same events as hooks, without the prefix. on returns a handle and off removes the hook.
local handle = exports.cuxial_danceclass:on(event, fn)
local removed = exports.cuxial_danceclass:off(handle)| Parameter | Type | Description |
|---|---|---|
event | string | roomCreated, roomClosed, studentJoined, studentLeft, roundStarted, roundEnded or classEnded. |
fn | function | Receives the same table as the event. |
handle | number | Value returned by on. |
Returns: on returns number, or nil when the arguments are not valid. off returns boolean.
local handle = exports.cuxial_danceclass:on('classEnded', function(data)
local winner = data.ranking[1]
if winner then print(('%s won the class'):format(winner.name)) end
end)