Summary

Methods

Adds a question to the quiz.
Runs the quiz kick callback for a player who failed the quiz.
Returns whether a player has completed the current quiz.
Returns whether new players have to pass the quiz.
Returns the function that handles players who failed the quiz.
GetName()shared
Returns the title shown on the quiz panel.
Returns the quiz panel while it is open.
Returns the share of questions a player must answer correctly to pass.
Returns a quiz question.
Returns every quiz question.
Returns how many questions the quiz has.
Returns whether an answer to a quiz question is correct.
Removes a question from the quiz.
Marks a player as having completed the quiz, or clears it.
Sets whether new players have to pass the quiz.
Sets the function that handles players who failed the quiz.
Sets the title shown on the quiz panel.
Sets the share of questions a player must answer correctly to pass.

Methods

cw.quiz:AddQuestion(question, answer, ...)

shared gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:100

Adds 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:199

Runs 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

cw.quiz:GetCompleted(player)

shared gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:172

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 nil before the server has said

Defined in

Returns whether new players have to pass the quiz.

Returns

  • Boolean Whether the quiz is enabled, or nil if 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_KickReason phrase in English

Returns the title shown on the quiz panel.

Returns

  • String The quiz title; #QuizPanel_Questions when none is set

Returns the quiz panel while it is open.

Returns

  • Panel The quiz panel, or nil if 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, answer and possibleAnswers keys, or nil

Returns every quiz question.

Returns

  • Map<Map> Question tables with question, answer and possibleAnswers keys, keyed by the short CRC of the question text

cw.quiz:GetQuestionsAmount()

shared gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:42

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:70

Returns 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 true if the answer is correct, otherwise nil

cw.quiz:RemoveQuestion(question)

shared gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:113

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:156

On 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

cw.quiz:SetKickCallback(Callback)

server gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:230

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

cw.quiz:SetPercentage(percentage)

server gamemodes/catwork/gamemode/core/libraries/sh_quiz.lua:183

Sets the share of questions a player must answer correctly to pass.

Parameters

  • percentage Number Required percentage, from 0 to 100

Defined in