Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*=============================================================================
- Quiz System
- by Daniel_Cortez
- www.pro-pawn.ru
- This code is licensed under the terms of zlib/libpng license.
- Copyright (c) 2013 Daniel_Cortez
- This software is provided 'as-is', without any express or implied warranty.
- In no event will the authors be held liable for any damages arising from the
- use of this software. Permission is granted to anyone to use this software for
- any purpose, including commercial applications, and to alter it and
- redistribute it freely, subject to the following restrictions:
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software in
- a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
- =============================================================================*/
- #include <a_samp>
- #include <dc_cmd>
- const
- // time between each question (in seconds)
- // (время между вопросами в секундах)
- QUIZ_TIMEOUT = 30,
- // prize for the correct answer ($)
- // (награда за правильный ответ)
- QUIZ_PRIZE = 2000,
- // min and max quantity of arithmetical operations in question
- // (мин. и макс. кол-во арифметических операций в вопросе)
- QUIZ_MIN_ARITHMETICAL_OPS = 3,
- QUIZ_MAX_ARITHMETICAL_OPS = 5,
- // max length for question and answer respectively
- // (макс. длина под вопрос и ответа соответственно)
- QUIZ_MAX_QUESTION_LENGTH = 63,
- QUIZ_MAX_ANSWER_LENGTH = 23,
- // max amount of answer variants in multiple-choice questions
- // (макс. кол-во вариантов ответа)
- QUIZ_MAX_ANSWER_OPTIONS = 4;
- #define GivePrize(%0)\
- GivePlayerMoney(%0, QUIZ_PRIZE) // можете заменить выдачу денег на свою, например на PlayerInfo[%0][pMoney] += QUIZ_PRIZE
- enum multiple_choice_question_info{
- mcqQuestion[QUIZ_MAX_QUESTION_LENGTH+1],
- mcqAnswers,
- mcqCorrectAnswer,
- mcqAnswer[QUIZ_MAX_ANSWER_OPTIONS*(QUIZ_MAX_ANSWER_LENGTH+1)]
- };
- static const multiple_choice_questions[][multiple_choice_question_info] = {
- {
- {"Кто написал роман \"Война и мир\"?"},
- // "4, 3" означает 4 варианта ответа, 3-й правильный
- 4, 3, {"А.С.Пушкин", "М.Ю.Лермонтов", "Л.Н.Толстой", "И.С.Тургенев"}
- },
- {
- {"Кто был избран первым президентом Российской Федерации?"},
- // 3 варианта ответа
- 3, 2, {"В.В.Путин", "Б.Н.Ельцин", "Д.А.Медведев"}
- }
- };
- enum single_choice_question_info{
- scqQuestion[QUIZ_MAX_QUESTION_LENGTH],
- scqAnswer[QUIZ_MAX_ANSWER_LENGTH]
- };
- static const single_choice_questions[][single_choice_question_info] = {
- {
- {"Назовите самую длинную в мире реку."},
- {"Амазонка"}
- },
- {
- {"Какая страна имеет самую большую в мире площадь территории?"},
- {"Россия"}
- }
- };
- // Check some constant values
- // (проверить значение констант)
- // Too bad there's no way to correctly show errors in Russian. Oh well...
- #if QUIZ_MIN_ARITHMETICAL_OPS <= 1
- #error QUIZ_MIN_ARITHMETICAL_OPS must be more than 1
- #endif
- static
- cur_question_answer[QUIZ_MAX_ANSWER_LENGTH],
- cur_quiz_player_answered[MAX_PLAYERS char] = {0, ...},
- cur_quiz_answered = 0;
- CMD:quiz(playerid, params[]){
- if(cur_quiz_answered)
- return SendClientMessage(playerid, -1, "На этот вопрос уже ответили, попробуйте позже.");
- if(cur_quiz_player_answered{playerid})
- return SendClientMessage(playerid, -1, "Вы уже ответили на этот вопрос, попробуйте позже.");
- if(isnull(params))
- return SendClientMessage(playerid, -1, "Использование: /quiz [Ваш ответ]");
- if(strcmp(params, cur_question_answer, true) == 0)
- {
- static const
- fmt_str0[] = "Викторина: Поздравляем, Вы правильно ответили на вопрос и получили вознаграждение: $%d.",
- fmt_str1[] = "Викторина: Игрок %s правильно ответил на вопрос. Ответ: %s.";
- const
- size0 = sizeof(fmt_str0)-2+11,
- size1 = sizeof(fmt_str1)-2+MAX_PLAYER_NAME-2+QUIZ_MAX_ANSWER_LENGTH;
- #if size0>size1
- const size = size0;
- #else
- const size = size1;
- #endif
- new string[size];
- format(string, sizeof(string), fmt_str0, QUIZ_PRIZE);
- SendClientMessage(playerid, -1, string);
- GetPlayerName(playerid, string, sizeof(string));
- format(string, sizeof(string), fmt_str1, string, cur_question_answer);
- SendClientMessageToAll(-1, string);
- GivePrize(playerid);
- cur_quiz_answered = 1;
- }
- else
- SendClientMessage(playerid, -1, "Викторина: К сожалению, это неправильный ответ, попробуйте в следующий раз!");
- cur_quiz_player_answered{playerid} = 1;
- return 1;
- }
- // don't look at that code, it's horrible -_-
- @___dc_quiz_timer();
- @___dc_quiz_timer(){
- for(new i=0; i<sizeof(cur_quiz_player_answered)*(cellbits/charbits); ++i)
- cur_quiz_player_answered{i} = 0;
- cur_quiz_answered = 0;
- enum questionType{
- QUESTION_TYPE_ARITHMETICAL,
- QUESTION_TYPE_MULTIPLE_CHOICE,
- QUESTION_TYPE_SINGLE_CHOICE
- };
- new question_type = random(_:questionType);
- switch(question_type){
- case QUESTION_TYPE_ARITHMETICAL:{
- enum question_ops{
- // Dividing is not implemented to avoid confusion of players
- // with answer format (ex. "1024" or "1024.0").
- // Деление не реализовано, чтобы игроки не путались с форматом
- // ответа (пример: "1024" или "1024.0")
- QUESTION_OP_ADD,
- QUESTION_OP_SUB,
- QUESTION_OP_MUL
- };
- static const question_op_signs[_:question_ops] = {'+', '-', '*'};
- new op_count = QUIZ_MIN_ARITHMETICAL_OPS+random(QUIZ_MAX_ARITHMETICAL_OPS-QUIZ_MIN_ARITHMETICAL_OPS+1);
- new result = random(1000);
- new rand, op, last_operand = result;
- static const question_arithmetical_fmt_str[] = "Викторина: Сколько будет %s ?";
- new string[sizeof(question_arithmetical_fmt_str)-2+(3)+(1+1)*(QUIZ_MAX_ARITHMETICAL_OPS-1)];
- valstr(string, result);
- for(new i=1; i<op_count; ++i){
- rand = 1+random(9);
- op = random(_:question_ops);
- switch(op){
- case QUESTION_OP_ADD:{
- result += rand;
- last_operand = rand;
- }
- case QUESTION_OP_SUB:{
- result -= rand;
- last_operand = -rand;
- }
- case QUESTION_OP_MUL:{
- result -= last_operand;
- last_operand *= (rand);
- result += last_operand;
- }
- }
- format(string, sizeof(string), "%s%c%d", string, question_op_signs[op], rand);
- }
- format(string, sizeof(string), question_arithmetical_fmt_str, string);
- SendClientMessageToAll(0xF0F080FF, string);
- SendClientMessageToAll(0xF0F080FF, "Для ответа используйте {00d0f0}/quiz [ответ]");
- format(cur_question_answer, sizeof(cur_question_answer), "%d", result);
- }
- case QUESTION_TYPE_MULTIPLE_CHOICE:{
- static const multiple_choice_question_str[] = "Викторина: ";
- new string[sizeof(multiple_choice_question_str)+QUIZ_MAX_QUESTION_LENGTH];
- new rand = random(sizeof(multiple_choice_questions));
- string = multiple_choice_question_str;
- strcat(string, multiple_choice_questions[rand][mcqQuestion]);
- SendClientMessageToAll(0xF0F080FF, string);
- for(new i=0,j=0,pos; i<multiple_choice_questions[rand][mcqAnswers]; ++i){
- format(string, sizeof(string), "\t%d. ", i+1);
- pos = strlen(string);
- for(; j<(QUIZ_MAX_ANSWER_LENGTH+1)*QUIZ_MAX_ANSWER_OPTIONS; ){
- string[pos++] = multiple_choice_questions[rand][mcqAnswer][j];
- if(multiple_choice_questions[rand][mcqAnswer][j++] == '\0')
- break;
- }
- SendClientMessageToAll(0xF0F080FF, string);
- }
- SendClientMessageToAll(0xF0F080FF, "Для ответа используйте {00d0f0}/quiz [номер ответа]");
- format(cur_question_answer, sizeof(cur_question_answer), "%d", multiple_choice_questions[rand][mcqCorrectAnswer]);
- }
- case QUESTION_TYPE_SINGLE_CHOICE:{
- static const single_choice_question_str[] = "Викторина: ";
- new string[sizeof(single_choice_question_str)+QUIZ_MAX_QUESTION_LENGTH];
- new rand = random(sizeof(single_choice_questions));
- string = single_choice_question_str;
- strcat(string, single_choice_questions[rand][scqQuestion]);
- SendClientMessageToAll(0xF0F080FF, string);
- cur_question_answer[0] = '\0', strcat(cur_question_answer, single_choice_questions[rand][scqAnswer]);
- SendClientMessageToAll(0xF0F080FF, "Для ответа используйте {00d0f0}/quiz [ответ]");
- }
- }
- }
- public OnGameModeInit(){
- print(
- "#========================================#\n"\
- "# Quiz System by Daniel_Cortez loaded. #\n"\
- "# (c) 2013 Daniel_Cortez #\n"\
- "# www.pro-pawn.ru #\n"\
- "#========================================#"
- );
- SetTimer("@___dc_quiz_timer", QUIZ_TIMEOUT*1000, 1);
- #if defined quiz_sys__OnGameModeInit
- quiz_sys__OnGameModeInit();
- #endif
- return 1;
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit quiz_sys__OnGameModeInit
- #if defined quiz_sys__OnGameModeInit
- forward quiz_sys__OnGameModeInit();
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement