Adding side effects to dialogue

Time to write the merchant's dialogue. In the Editor, set the merchant's personality to 2 and Cell 3 to 3. Then add the following nodes to the talk script:

// Merchant

begintalknode 3;
  nextstate = 2;
  personality = 2;
  text1 = "You see an anxious looking merchant fidgeting with the wares in her carts. She straightens as you approach.";
  text2 = "_You there! I think you might be able to help me._";
  text5 = "The merchant stops rummaging through her wares and looks at you. _Yes?_";
  action = INTRO;

begintalknode 4;
  state = 2;
  nextstate = 3;
  question = "What do you need done?";
  text1 = "_Less than an hour ago, my guard and I woke to see a pack of goblins stealing items from our cart._";
  text2 = "_We managed to scare them off, but one of them stole something very precious to me._";
  text3 = "_A necklace, valuable, in my family for generations. I want it back._";

begintalknode 5;
  state = 3;
  nextstate = -1;
  question = "Consider it done.";
  text1 = "She nods imperiously. _Continue west. You'll find them soon enough._";

But these lines of dialogue are not enough. Talking to the merchant about the necklace should give the player a new quest. Also, after the player gets the quest they should be able to leave the town. We need to add side effects to talk node 5:

begintalknode 5;
  state = 3;
  nextstate = -1;
  question = "Consider it done.";
  text1 = "She nods imperiously. _Continue west. You'll find them soon enough._";
  code =
    set_flag(0, 1, 1);
    toggle_quest(0, 1);
  break;

When talk node 5 is run, the lines of code between code = and break; are also run. SDF (0,1) keeps track of whether or not the player has received the quest from the merchant. toggle_quest sets the "Retrieve the Necklace" quest to be active. However, activating the quest is only half the work. We also need to define the quest. Open pesky.txt (the script for the entire scenario) and edit the LOAD_SCEN_STATE:

beginstate LOAD_SCEN_STATE;
  init_quest(0, "Retrieve the Necklace", "Get the merchant's necklace back from the pesky goblins.");
break;

This scenario will only have one quest, so players aren't likely to forget what they need to do next, but it's important to use the quest list a lot when making larger scenarios.

Now that we have a SDF that keeps track of whether or not the player has received the quest, we should change the dialogue nodes so that the merchant only talks about the quest once. Let's make the following change to talk node 4:

begintalknode 4;
  state = 2;
  nextstate = 3;
  condition = get_flag(0, 1) == 0;
  question = "What do you need done?";
  text1 = "_Less than an hour ago, my guard and I woke to see a pack of goblins stealing items from our cart._";
  text2 = "_We managed to scare them off, but one of them stole something very precious to me._";
  text3 = "_A necklace, valuable, in my family for generations. I want it back._";

When you use condition, a talk node will be hidden unless whatever condition is set to is true. In this case, the player will be able to ask about the merchant's quest, but once SDF (0,1) is set to 1, talk node 4 will be hidden. For good measure, let's add another talk node that can only be accessed once SDF (0,1) is set to 1:

begintalknode 6;
  state = 2;
  nextstate = -1;
  condition = get_flag(0, 1) == 1;
  question = "Sorry, still looking for that necklace.";
  text1 = "She scowls. _Get back to work then! What else are you good for?_";

Two things left to do. First, go back to z0tunnel.txt and change state 12 so that it only blocks the player if they haven't received the quest from the merchant:

beginstate 12;
  if (get_flag(0, 1) == 0) {
    message_dialog("The merchant looks like she has something to say to you.", "(Talk to the merchant before leaving.)");
    block_entry(1);
  }
break;
Second, keep your notes up to date!
0: Merchant's Tunnel
  0: Seeing the merchant (state 10)
    0: Haven't seen
    1: Have seen
  1: Necklace quest
    0: Haven't received
	1: Have received

Now let's give the merchant something to sell.