cw.quiz class
Summary
Methods
Methods
cw.quiz:AddQuestion(question, answer, ...)
shared gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:100Adds a question to the quiz.
The question's index is the short CRC of its text.
cw.quiz:AddQuestion('#Quiz_RP2_Question', 2,
'#Quiz_RP2_Answer1',
'#Quiz_RP2_Answer2',
'#Quiz_RP2_Answer3',
'#Quiz_RP2_Answer4')
Parameters
- question String The question text, can be a language phrase
- answer Number Position of the correct answer among the possible answers, or a List of accepted answers
- ... String The possible answers, in the order they are shown
cw.quiz:CallKickCallback(player, correctAnswers)
server gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:199Runs the quiz kick callback for a player who failed the quiz.
Parameters
- player Player The player who failed
- correctAnswers Number How many questions they answered correctly
See also
On the server
Returns whether a player has completed the current quiz.
Bots always count as having completed it.
Parameters
- player Player The player to check
Returns
- Boolean Whether the player has completed the quiz
On the client
Returns whether the local player has completed the quiz.
Parameters
- player
Returns
- Boolean Whether the quiz is completed, or
nilbefore the server has said
Defined in
Returns whether new players have to pass the quiz.
Returns
- Boolean Whether the quiz is enabled, or
nilif it was never set
Returns the function that handles players who failed the quiz.
Returns
- Function The callback set with
cw.quiz:SetKickCallback, or a default that kicks the player with the#QuizPanel_KickReasonphrase in English
Returns the title shown on the quiz panel.
Returns
- String The quiz title;
#QuizPanel_Questionswhen none is set
Returns the quiz panel while it is open.
Returns
- Panel The quiz panel, or
nilif it is not valid
Returns the share of questions a player must answer correctly to pass.
Returns
- Number Required percentage; 100 when none is set
Returns a quiz question.
Parameters
- index Number The question's index, the short CRC of its text
Returns
- Map The question table with
question,answerandpossibleAnswerskeys, ornil
Returns every quiz question.
Returns
- Map<Map> Question tables with
question,answerandpossibleAnswerskeys, keyed by the short CRC of the question text
Returns how many questions the quiz has.
Returns
- Number The number of questions
cw.quiz:IsAnswerCorrect(index, answer)
shared gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:70Returns whether an answer to a quiz question is correct.
The answer is correct when it is one of the question's correct answers (if answer is a list),
the text of the correct possible answer, or equal to the stored answer itself.
Parameters
- index Number The question's index
- answer Any The player's answer: the answer text or its position
Returns
- Boolean
trueif the answer is correct, otherwisenil
Removes a question from the quiz.
Parameters
- question Any The question's index or its text
cw.quiz:SetCompleted(player, completed)
shared gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:156On the server
Marks a player as having completed the quiz, or clears it.
Stores the current number of questions in the player's Quiz data, so adding or removing
questions makes players take the quiz again. Tells the player's client.
Parameters
- player Player The player to mark
- completed Boolean Whether the player has completed the quiz
On the client
Sets whether the local player has completed the quiz.
Parameters
- completed Boolean Whether the quiz is completed
Defined in
Sets whether new players have to pass the quiz.
Parameters
- enabled Boolean Whether the quiz is enabled
Sets the function that handles players who failed the quiz.
cw.quiz:SetKickCallback(function(player, correctAnswers)
player:Kick('You failed the quiz.')
end)
Parameters
- Callback Function Called as
Callback(player, correctAnswers)
Sets the title shown on the quiz panel.
Parameters
- name String The quiz title, can be a language phrase
Sets the share of questions a player must answer correctly to pass.
Parameters
- percentage Number Required percentage, from 0 to 100