# ---------------------------------------------------------------------------- ## ## Quizmaster Script ## by HungrySnake ## ## What's this? ## This script enables to user to call a Quiz whenever he wants from an event's ## action (see below). ## ## Requested by new ## ## Version History: ## ## VER : DD/MM/YYYY : UPDATE ## ## 1.0 : 21/06/2012 : Finished script ## 1.5 : 24/06/2012 : Added Randomizing Questions ## 2.0 : 26/06/2012 : Added EXP Gain, Items Gain, BGM ## 2.1 : 28/06/2012 : Fixed more commands bug ## 2.2 : 17/07/2012 : Added longer question compatibility ## 2.3 : 23/07/2012 : Added switch/var/common event control ## ## Instructions: ## ## To call the Scene from an event, follow these steps: ## > New Action ## > Script ## > Enter: start_quiz(id,questions,quit_able,music,item,weapon,armor, ## switch_id,var_id,inc_val,common_event_id) ## ----- Don't write from here on ----- ## id = The ID of your Quiz set-up below. ## questions = Amount of questions of your quiz you want to ask. ## quit_able = Can the player quit your quiz? (true/false) ## music = The music you want to play as a background music in the quiz, ## located in the BGM folder. ## If you don't want any music then don't fill in the music argument ## item = Item ID to be added when all of the questions are answered ## correctly. Set to 'nil' if you don't want an item to be added. ## weapon = Weapon ID to be added when all of the questions are answered ## correctly. Set to 'nil' if you don't want a weapon to be added. ## armor = Armor ID to be added when all of the questions are answered ## correctly. Set to 'nil' if you don't want an armor to be added. ## switch_id = The ID of the switch to activate when all of the questions are ## answered correctly. Default is set to nil. ## var_id,inc_val = The variable's id to increase with inc_val when all of ## questions are answered correctly. Default is set to nil. ## common_event_id = The common event's ID to call when all questions are ## answered correctly. Default is set to nil. ## ## Example: When I write start_quiz(0,2,true,"Battle2",nil,5,6), I'll be ## calling the Quiz with an ID of zero (see below), I'll ask 2 ## questions, the player would be able to quit the quiz, the ## "Battle2" music file, located in the BGM folder, will play, no ## Item will be added, the weapon with an ID of 5 will be added and ## the armor with an ID of 6 will be added. ## > OK ## > Finished ## ## Making a new Quiz: ## QUIZID => [ ## [["Question 1"], ["Option 1","Option 2"], correct answer], ## [["Question 2"], ["Option 1","Option 2"], correct answer] ## ] ## The question will be between the [...] symbols. To add a new line in your ## question, you'll seperate the lines by a comma. Like this: ## QUIZID => [ ## [["Question 1","Second Line!"], ["Option 1","Option 2"], ## correct answer], ## [["Question 2","Second Line!","Third Line!!"], ## ["Option 1","Option 2"], correct answer] ## ] ## The correct answer is the index of the array of options just before it, in ## example: What we want is to set the correct answer of Question 1 to Option 2 ## , in this case we'd be using 1 as the correct answer, since Option 1 has an ## index of 0 and Option 2 has an index of 1. ## ## ---------------------------------------------------------------------------- #module QMS module CONFIG DISPLAY_LEVEL_UP = true # Show the character leveled up? DEC_WRONG = false # Decrease quiz points after a wrong # answer? WRONG_TEXT = "Wrong!" # Text of the Wrong window RIGHT_TEXT = "Correct!" # Text of the Correct window JUDGE_WINDOW_DURATION = 40 # Duration of the Right/Wrong window GAINED_WINDOW_DURATION = 100 # Durarion of the Gained window at the end # of the quiz. QUIZ = { # << Don't delete 0 => [ [ ["HungrySnake is a ...","second line!!!!!"], ["***","enjoyable human being","Noob","Boss"], 3 ], [ ["New is the ..."], ["Requester","It's option 1","Really","Believe me"], 0 ], [ ["Finish the sentence: Never gonna ..."], ["Give","You","Up","Never"], 0 ], [ ["Finish the sentence: Hey I just ..."], ["You","Met","And","This"], 1 ], ], 1 => [ [["This is an example, isn't it?"] ,["Yes","No"],0], [["Are you ******ed?"],["Yes","No"],0], [["Have you ever looked in the mirror?"],["Yes","No"],1], [["Did you fall from heaven?"],["Yes","No"],1], [["ZOMG 6 OPTIONS??!!!"],["Y NO SEE?","No","3th option","Scroll down","ZOMG 5TH OPTION","ZOMG 6TH OPTION"],0], [["Just answer yes"],["Yes, click me","No, click me not ~ Joda"],1] ] } # << Don't delete endendclass Window_Question < Window_Base def initialize(quizarry,question) super(0,0,Graphics.width,24*4+32) refresh(quizarry,question) end def refresh(quizarry,question) self.contents.clear draw_question_name(quizarry,question) end def draw_question_name(quizarry,question) for i in 0..quizarry[question][0].size self.contents.draw_text(0,WLH*i,self.width,WLH,quizarry[question][0]
) end endend class Window_QuestionNumbs < Window_Base def initialize(quizid,question_id,tot_questions) super(0,WLH*4+32,Graphics.width,WLH+32) refresh(quizid,question_id,tot_questions) end def refresh(quizid,question_id,tot_questions) self.contents.clear draw_question_number(quizid,question_id,tot_questions) end def draw_question_number(quizid,question_id,tot_questions) self.contents.draw_text(220,0,150,WLH,"#{question_id+1} / #{tot_questions}") endendclass Window_Gained < Window_Base def initialize(points,item_ary,max) height = points == max ? (WLH*2+32) + item_ary.compact.size*24 : WLH*2+32 super(Graphics.width/2-90,Graphics.height/2-28,180,height) refresh(points,item_ary,max) end def refresh(points,item_ary,max) self.contents.clear draw_points(points,max) draw_gained(item_ary) if points == max Graphics.wait(QMS::CONFIG::JUDGE_WINDOW_DURATION+50) self.dispose add_gained(points,item_ary,max) end def draw_points(points,max) self.contents.draw_text(25,0,100,WLH,"Points: #{points}") self.contents.draw_text(0,WLH,150,WLH,"Gained EXP: #{points*4}") end def draw_gained(item_ary) if item_ary[0] != nil && item_ary[1] != nil && item_ary[2] != nil draw_item_name($data_items[item_ary[0]], 0, WLH*2) draw_item_name($data_weapons[item_ary[1]], 0, WLH*3) draw_item_name($data_armors [item_ary[2]], 0, WLH*4) elsif item_ary[0] != nil && item_ary[1] == nil && item_ary[2] == nil draw_item_name($data_items[item_ary[0]], 0, WLH*2) elsif item_ary[0] == nil && item_ary[1] != nil && item_ary[2] == nil draw_item_name($data_weapons[item_ary[1]], 0, WLH*2) elsif item_ary[0] == nil && item_ary[1] == nil && item_ary[2] != nil draw_item_name($data_armors [item_ary[2]], 0, WLH*2) elsif item_ary[0] != nil && item_ary[1] != nil && item_ary[2] == nil draw_item_name($data_items [item_ary[0]], 0, WLH*2) draw_item_name($data_weapons[item_ary[1]], 0, WLH*3) elsif item_ary[0] != nil && item_ary[1] == nil && item_ary[2] != nil draw_item_name($data_items [item_ary[0]], 0, WLH*2) draw_item_name($data_armors [item_ary[2]], 0, WLH*3) elsif item_ary[0] == nil && item_ary[1] != nil && item_ary[2] != nil draw_item_name($data_weapons[item_ary[1]], 0, WLH*2) draw_item_name($data_armors [item_ary[2]], 0, WLH*3) end end def add_gained(points,item_ary,max) if points == max $game_party.gain_item($data_items[item_ary[0]],1) if item_ary[0] != nil $game_party.gain_item($data_weapons[item_ary[1]],1) if item_ary[1] != nil $game_party.gain_item($data_armors[item_ary[2]],1) if item_ary[2] != nil end for actor in $game_party.members actor.gain_exp(points*4,QMS::CONFIG:
ISPLAY_LEVEL_UP) end endend class Scene_Quiz < Scene_Base include QMS::CONFIG def initialize(quiz_numb,questions,quitable,music,item,weapon,armor,switch_id,var_id,inc_val,common_event_id) @quiz_numb = quiz_numb @questions = questions @quitable = quitable @last_bgm = RPG::BGM::last @music = music @gained = [item,weapon,armor] @switch_id = switch_id @ingame_var = [var_id,inc_val] @comm_ev_id = common_event_id end def start super create_menu_background @question_numb = 0 @quiz_points = 0 @randomized_array = QUIZ[@quiz_numb].sort_by {rand} RPG::BGM.stop musicplaying = RPG::BGM.new(@music,100,100) if @music != nil musicplaying.play create_question_window create_option_window create_question_number create_wrong_window create_right_window end def create_question_number @question_number = Window_QuestionNumbs.new(@quiz_numb,@question_numb,@questions) end def create_question_window @question_window = Window_Question.new(@randomized_array,@question_numb) end def create_wrong_window @wrong_window = Window_Base.new(Graphics.width/2-75,Graphics.height/2-28,150,56) @wrong_window.contents.draw_text(25,0,100,24,WRONG_TEXT) @wrong_window.visible = false end def create_right_window @right_window = Window_Base.new(Graphics.width/2-75,Graphics.height/2-28,150,56) @right_window.contents.draw_text(25,0,100,24,RIGHT_TEXT) @right_window.visible = false end def show_judge(index) case index when 0 Sound.play_buzzer if DEC_WRONG @quiz_points -= 1 if @quiz_points > 0 end @wrong_window.visible = true Graphics.wait(JUDGE_WINDOW_DURATION) @wrong_window.visible = false when 1 Sound.play_decision @quiz_points += 1 @right_window.visible = true Graphics.wait(JUDGE_WINDOW_DURATION) @right_window.visible = false end end def refresh_windows @question_number.refresh (@quiz_numb,@question_numb,@questions) @question_window.refresh (@randomized_array,@question_numb) @option_window.dispose create_option_window end def create_option_window @option_window = Window_Command.new(Graphics.width,@randomized_array[@question_numb][1]) @option_window.y = Graphics.height - (24*4+32) @option_window.height = 24*4 + 32 for i in 0..@randomized_array[@question_numb][1].size @option_window.draw_item(i) end end def update_option_selecton if Input.trigger? (Input::C) case @option_window.index when 0...@randomized_array[@question_numb][2] show_judge(0) if @question_numb + 1 == @questions dispose_when_noq else @question_numb += 1 refresh_windows end when @randomized_array[@question_numb][2] show_judge(1) if @question_numb + 1 == @questions dispose_when_noq else @question_numb += 1 refresh_windows end when (@randomized_array[@question_numb][2]+1)..@randomized_array[@question_numb][1].size show_judge(0) if @question_numb + 1 == @questions dispose_when_noq else @question_numb += 1 refresh_windows end end elsif Input.trigger? (Input:: if @quitable $scene = Scene_Map.new RPG::BGM.stop @last_bgm.play else Sound.play_buzzer end end end def create_points @window_points = Window_Gained.new(@quiz_points,@gained,@questions) if @quiz_points == @questions $game_switches[@switch_id] = true if @switch_id != nil $game_variables[@ingame_var[0]] += @ingame_var[1] if @ingame_var[0] != nil and @ingame_var[1] != nil $game_temp.common_event_id = @comm_ev_id if @comm_ev_id != nil end end def dispose_when_noq $scene = Scene_Map.new create_points end def update super update_menu_background update_option_selecton @option_window.update @question_number.update @question_window.update end def terminate super dispose_menu_background @option_window.dispose @question_number.dispose @question_window.dispose RPG::BGM.stop @last_bgm.play endendclass Game_Interpreter def start_quiz(id,questions,quit_able,music=nil,item=nil,weapon=nil,armor=nil,switch_id=nil,var_id=nil,inc_val=nil,common_event_id=nil) $scene = Scene_Quiz.new(id,questions,quit_able,music,item,weapon,armor,switch_id,var_id,inc_val,common_event_id) endend