Some help in creating a Quiz Battle System

Discussion in 'RPG Maker MV' started by Josip, Apr 16, 2019.

  1. Josip

    Josip Villager Member

    Messages:
    12
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    Hello everyone!
    I am currently working on a small scale game for my kids and I wanted to create a game that asks random questions during battle.

    The most I am able to figure out (new to RPG Maker MV), is under the troops section I can set the Battle Conditions and create a Loop
    > Show Text
    >Show choices
    > Choice 1 - 4
    > Show Text
    > Force Action
    This is sort of what I have been able to figure out on my own. So my questions are:

    1.Is there a way to create a a bunch of questions and randomly pick one to be asked during battle from a large pool of questions.

    2. Is there a way to force an enemy action to include a few more options. For example I can force them to do a physical attack or etc, but I wanted them to randomly chose between attack, skill, etc.

    So instead of this "Force Action > Attack" it would be "Force Action > Attack or Skill"

    3. I read about creating an event but have no idea how to implement it (some direction or helpful tutorial would be appreciated).

    If I sound unclear about anything let me know and I will do my best to describe it further or take screen shots.

    Thank you all in advance!
     
    #1
  2. Kes

    Kes Global Moderators Global Mod

    Messages:
    19,874
    Likes Received:
    10,181
    First Language:
    English
    Primarily Uses:
    RMVXA
    'Tutorials' is where people who have created a tutorial for others to use can post it. "How do I...?" questions belong in the Support forum for the engine you are using. Fortunately you mention which that is in an aside in the post, but it would be helpful if you could include that in the information under your avatar.

    I've moved this thread to RPG Maker MV. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #2
    Josip likes this.
  3. caethyril

    caethyril ^_^ Veteran

    Messages:
    796
    Likes Received:
    494
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    1 & 2) For anything random, consider using Control Variables > Set > Random. Then you can use branches to check if the variable is, for example, 1 or 2 or 3, and perform the appropriate action. So you could have a couple of random numbers: one for the question and one for the skill. And maybe a "Correct Answer" switch?

    3) From what you've said, I would suggest making one or more common event(s) for the questions (maybe one event per enemy, to make the inflexible Force Action command easier to handle). You can add a common event to a skill via the Effects list, and the event will play after the skill is performed. :kaophew:

    Put together, perhaps something vaguely like this?
    Code:
    ◆Comment:Wrong answer by default.
    ◆Control Switches:#0001 Correct Answer = OFF
    ◆Comment:Get random question!
    ◆Control Variables:#0001 random = Random 1..3
    ◆If:random = 1
      ◆Comment:Ask question 1
      ◆Text:None, Window, Bottom
      :    :What is 2 + 2?
      ◆Comment:Get answer! (Re-use this variable because why not?)
      ◆Input Number:random, 1 digit
      ◆Comment:Check answer
      ◆If:random = 4
        ◆Comment:Correct! (Wow!)
        ◆Control Switches:#0001 Correct Answer = ON
        ◆
      :End
      ◆
    :Else
      ◆If:random = 2
        ◆Comment:Question 2...
        ◆
      :Else
        ◆Comment:etc...
        ◆
      :End
      ◆
    :End
    
    ◆If:Correct Answer is ON
      ◆Comment:Correct answer ^_^
      ◆Text:None, Window, Bottom
      :    :OMG how did you get that correct? You must be cheating!
      ◆
    :Else
      ◆Comment:Incorrect v_v
      ◆Control Variables:#0001 random = Random 1..6
      ◆If:random ≤ 3
        ◆Comment:3/6 chance: Attack
        ◆Force Action:#1, Attack, Random
        ◆
      :Else
        ◆If:random ≤ 5
          ◆Comment:2/6 chance: Fire
          ◆Force Action:#1, Fire, Random
          ◆
        :Else
          ◆Comment:1/6 chance: Spark
          ◆Force Action:#1, Spark, Random
          ◆
        :End
        ◆
      :End
      ◆
    :End
    There are more sophisticated alternatives if you're willing to dive into scripting and/or action sequences (plugins)...not sure how elaborate a thing you're going for here. :kaoslp:

    For pedagogy if nothing else...troop events are a bit different from map events, here's a technical break-down:
    • Condition: all marked conditions must be met for the event to run.
      An event with no conditions will never run.
    • Span: determines how often the event can run.
      Battle = once per battle, Turn = once per turn, Moment = any time.
      Note that the event's conditions are checked on a "Moment" basis until the event conditions are met.
      Be careful with Moment span: if you're not careful it can result in an event playing on repeat and soft-locking your game.
    Also, unlike map events, there's no one "active" troop event page. The order of event pages simply determines the order in which the troop events will run if triggered in the same frame.
     
    #3
    Josip likes this.
  4. Josip

    Josip Villager Member

    Messages:
    12
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    Kes,
    I am sorry for not posting in the right forum section. I went ahead and update my profile as requested.

    Caethyril,
    Thank you for the informative reply.
    Eventually, I would love to create my own plugin. I don't know why, but I find it so fascinating and would love to dive in deeper.
     
    #4
    caethyril likes this.
  5. Josip

    Josip Villager Member

    Messages:
    12
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    Hey Caethyril,
    After studying your suggested code for a few hours I have a few questions.

    1. How would I go to apply this to activate only during battles. Right now I have running under the Troops section with the Conditions ( Actor HP (1) <= 100% , Span : Battle). To insure that it activates at the beginning of battle.

    2. Can different enemies use the same Common Event? If so how would I go about coding this.

    3. Is the switch necessary? Why or why not ( just wanting to know) I was thinking I could create a Loop and put the questions in that
    something like this:


    Thank you again!!
    P.S. Great word "pedagogy!"
     
    #5
  6. caethyril

    caethyril ^_^ Veteran

    Messages:
    796
    Likes Received:
    494
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    (It's a very useful word!)

    OK, here's some answers~
    1) Yes, that ought to work. Note you can also use Condition: Turn 0 (no difference in this case, turn 0 simply happens right at the start of battle). Depending on how you want this to integrate with the existing battle system, you might want to consider running it every turn as well? In which case you could try adding a second page with Condition: Turn 1*X (i.e. turns 1, 2, 3, etc) and Span: Turn that calls the same common event.

    2) Ah, see, now it's getting complicated, haha. One option is to dive straight into a script call:
    Code:
    // random skill ID from pool:
    var skills = [1,9,10,12,15];
    var skillId = skills[Math.randomInt(skills.length)];
    var unit = $gameTroop.movableMembers();
    var battler = unit[Math.randomInt(unit.length)];
    var targetIndex = Math.randomInt($gameParty.aliveMembers().length);
    if (battler) {
      console.log(battler.name(), 'will now use skill', skillId, 'on target', targetIndex, '!');
      battler.forceAction(skillId, targetIndex);
      BattleManager.forceAction(battler);
      $gameTroop._interpreter.setWaitMode('action');
    }
    This picks a random skill from the array defined in the first line, a random skill user from the enemy troop, and a random target from the party, then forces the action. You could replace one or more of those "random" things with a variable value if needed, e.g. to get the value of game variable #5 in a script:
    Code:
    $gameVariables.value(5)
    Totally understand if you prefer not to mess around with scripting yet, though! :kaoswt2:

    Alternatively, if you're running the event separately from the skills then you could have a variable or two to represent which enemy is questioning you, and just change the value(s) as needed between questions. If you're calling the event as a skill Effect, then you could use the damage formula to set a variable equal to the skill user's "index" (i.e. position in their unit) and/or one equal to the enemy's database ID. Something like this:
    Code:
    v[1] = a.index(); v[2] = a.enemyId(); damage_formula_goes_here
    This assumes the skill is only usable by enemies! (Actors don't have an enemyId function.) Replace 1 and/or 2 with suitable variable IDs and stick your damage formula (or 0 if you don't want it to do damage/healing) after the semi-colon. These variables can then be used to determine a) the Force Action "user" and b) the type of enemy quizzing you. More branches await! :kaoback:

    3) My idea with the switch is to avoid having to put the Force Action / random skill selection stuff in each question separately; this way, you can have one "question" block for getting/checking answers and one "force action" block for responding to the answers. I think the loop you're keen on would encompass the entire event I suggested.
    However, it sounds like you may actually be after something a bit different? You mention loops at various points, which somewhat removes the need for the battle system (it has its own, fairly complex "loop" of turns with various phases). It seems to me like you're wanting to build a turn-based quiz, which doesn't require the (somewhat restrictive) battle system: maybe consider using map events for this, with Show Picture, Show Animation, etc? :kaoswt:

    Alternatively, if you want to integrate more fully with the existing battle system (and without needing so many conditional branches!), you could look into plugins. Yanfly has a Battle Engine Core plugin that offers "action sequences", which allow you to specify more precisely how skills play out on-screen, including when common events play. I've used that plugin (along with its Action Sequence Pack 1 add-on) to create a "Quiz" skill in one of my previous projects, the outcome of which depends on whether you answer correctly:
    Skill formula:
    Code:
    v[1] === 0 ? b.addState(8) : b.gainTp(75); 0
    Notebox:
    Code:
    Requires action sequence pack 1.
    QUIZ TIME!
    See common event #7 for details.
    <whole action>
    change variable 1 = 0
    wait for movement
    if target.isActor()
      common event: 7
    else
      change variable 1 = Math.randomInt(6)
    end
    action effect: targets
    death break
    wait: 30
    </whole action>
    Common event 7 is a simple question/answer thing that sets variable 1 equal to 1 if the answer is correct, or zero otherwise. Then the skill formula checks that variable, and either makes the targets confused (wrong answer) or gives them +75 TP (correct answer). In case you're interested, you can find the full project on the Steam Workshop (assuming you have RMMV on Steam).
    I realise this might be a bit here-and-there, lots of different options being discussed and some of it possibly way over your head if you're just starting out, but hopefully it helps! xP
     
    #6
    Josip likes this.
  7. Josip

    Josip Villager Member

    Messages:
    12
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    Oooooh, I love arrays! Yes, this does look a bit complicated, but no worries I will study it!:kaopride:

    I just want to say thank you again for responding to my inquiry about the battle system I want to implement. Im starting to see that maybe I should go and study a bit more of JavaScript and maybe hash out what exactly I want to happen within RPM Maker MV.

    Also, I may be using the wrong terminology:kaoswt2:
    So let me map it out:

    [
    //In my minds eye it goes something like this;

    { Battle Starts >

    Question is asked (displayed at the bottom) >

    Then answers are displayed (at the bottom too?) >

    If player selects correct answer > will take normal action

    If player selects incorrect answer > enemy will have a chance to either attack, defend, or use a skill (we add your array here)

    Repeat the process till player defeats enemy or until ran out of questions to answer

    If enemy is knocked out > play victory sequence

    If player is knocked out or runs out of questions > play defeated sequence

    }
    ]


    I build something that works in the Troops > Condition > Battle Event
    - Which uses a Loop, but was wondering I could do the same while using the Common Events.

    I will definitely try and see what would be the best way to implement what I want: Troops Battle Event, Common Events, Map Event, or even creating a Plugin.

    I will also look into Yanfly plugin. Thank you for the suggestion!

    I would love to mess with script, and be able to use Visual Studios Code to write out all of my JavaScript.:kaoswt2:
    I wrote this in Visual Studios Code so I could understand what I am trying to accomplish in RPG Maker MV (having a frame of reference) and I am starting to see how the switch comes into play. I made i = 0 which is essentially the switch in what you previously suggested right?

    <script>
    let questions = [
    {
    prompt : "What do you do at a read light? \n (a) Stop\n (b) Go \n (c) Slow down,
    answer: "a"
    },
    {
    prompt : "What to use when you was your hands?\n (a) soda\n (b) soap\n (c) dirt,
    answer: "b"
    },
    {
    prompt: "what is the airspeed velocity of an unladen swallow?\n(a) 50mph \n(b) African or European \n(c) superfast",
    answer:"b"
    }
    ];

    for (var i=0; i < questions.length;i++){
    var response = window.prompt(questions.prompt);

    if (response == questions.answer){
    alert("Correct!");
    } else {
    alert ("Wrong!");
    }

    };

    Thank you again!
     
    #7
  8. caethyril

    caethyril ^_^ Veteran

    Messages:
    796
    Likes Received:
    494
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    Your code looks valid, and removes the need for a switch like in my example, due to the way you've grouped questions & answers together. There are issues with it, though, e.g. case-sensitivity (could convert response to lower case?), the length of the script call (minifying is possible, but it's still all going through an eval, which is generally discouraged), and, notably, the incongruous text-based interface... :kaoback:

    I would suggest working with the existing system where possible, that's what it's there for, after all! You can use the existing Show Text and Show Choices event commands for the questions and answers; scripting comes into play for stuff like Force Action, due to the limited options in the editor (no option to specify user/target/skill by variable or anything).

    Actually, if the quiz simply determines who gets to act each turn, I'm pretty sure that could be done without even resorting to Force Action! :kaojoy: Here's an idea, using troop events:
    • Have two troop event pages:
      1. Condition Turn 0; Span Battle (run once, before the first turn's input phase)
      2. Condition Turn 1*X, Turn End; Span Turn (run once at the end of every turn)
    • Have one common event per enemy type (assuming you want different enemies to ask different questions).
    • In the troop events, simply call the appropriate common event (as mentioned, you can randomise it or something if needed).
    • Make a special "stun" state in the database. This will be applied to either the enemies or the player party, to prevent them from acting next turn. Set the restriction to Cannot Move, and disable all the Remove Conditions (it will be added/removed by the event). You can also leave the icon blank to make it invisible to the player!
    • In the common event(s), try something like this:
      Code:
      ◆Comment:Remove stun from everyone~
      ◆Change State:Entire Party, - QuizStun
      ◆Change Enemy State:Entire Troop, - QuizStun
      ◆Comment:This will get switched on if the answer is correct.
      ◆Control Switches:#0001 Correct Answer = OFF
      ◆Comment:Get question number...
      ◆Control Variables:#0001 question = Random 1..3
      ◆Comment:Ask the question!
      ◆If:question = 1
        ◆Text:None, Window, Bottom
        :    :A red traffic light means...?
        ◆Show Choices:Go!, Stop!, Danger! (Window, Right, #1, #2)
        :When Go! 
          ◆
        :When Stop! 
          ◆Comment:Correct, flip the switch!
          ◆Control Switches:#0001 Correct Answer = ON
          ◆
        :When Danger! 
          ◆
        :End
        ◆
      :Else
        ◆If:question = 2
          ◆Comment:etc
          ◆
        :Else
          ◆Comment:etc
          ◆
        :End
        ◆
      :End
      ◆Comment:Check if answer was correct...
      ◆If:Correct Answer is ON
        ◆Comment:Correct! Stun enemies!
        ◆Change Enemy State:Entire Troop, + QuizStun
        ◆
      :Else
        ◆Comment:Incorrect! Stun party!
        ◆Change State:Entire Party, + QuizStun
        ◆
      :End
    I'm putting together a li'l demo project of this approach; I expect to finish it up sometime Thursday or Friday and will post it here when I do, we'll see how it goes. ^_^

    Edit @Josip: OK here's the promised demo in case you're interested~ link (6.3 MB zip). I put in a bunch of silly questions, it's just for demo purposes. :kaothx:
     
    Last edited: Apr 19, 2019
    #8
  9. Josip

    Josip Villager Member

    Messages:
    12
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    @caethyril : Whoa, this is amazing!! It everything and more!!! How did you...what did you...what?!? OK, now im super inspired to study everything you did!!

    Thank you, thank you, thank you!!

    I will spend the weekend studying your code!!

    P.S. This is awesome!!!
     
    #9
  10. caethyril

    caethyril ^_^ Veteran

    Messages:
    796
    Likes Received:
    494
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    You're welcome! Hopefully the comments I left all over the place help demystify things a little, but I'd be happy to answer any questions about it after you've taken a look~ :kaopride:
     
    #10
    Josip likes this.
  11. Josip

    Josip Villager Member

    Messages:
    12
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    Thank you!!
     
    #11
    caethyril likes this.
  12. Josip

    Josip Villager Member

    Messages:
    12
    Likes Received:
    2
    First Language:
    English
    Primarily Uses:
    RMMV
    Hey caethyril!

    Just wanted to give an update on my progress. I am still looking over all of the code and trying to break it down and figure out what goes where and how things are triggered. I do have some questions, but I want to spend a little more time with the Demo before I get back on here.

    Thank you again and have a good weekend!
     
    #12
  13. caethyril

    caethyril ^_^ Veteran

    Messages:
    796
    Likes Received:
    494
    Location:
    UK
    First Language:
    English
    Primarily Uses:
    RMMV
    All good, take your time~ :)
     
    #13

Share This Page