Quest Example 3

This quest example covers dialogues, items and teleporters. The complete quest file can be found in the RCE via "Ctrl+P: QquestExample3".

### Logic

1. Guy asks the player to get a letter from Girl.
2. Player teleports to Girl.
3. Player talks with Girl and receive the letter.
4. Player comes back and talk with Guy.

## Pseudocode

### Variable

* None. (Have letter will be tested by checking inventory.)

### Dialogues

**Guy:**

* Dialogue 1: Ask player to get letter.
	+ - Option 1: Accept

**Girl:**

* Dialogue 1: Ask player what he wants.
	+ - Option 1: I want letter. (If selected, give item)
	+ - Option 2: Nothing...

* Dialogue 2: She mentions that she gave the letter.
* Dialogue 3: Ask player to deliver it to Guy.

### Events

```
talkGuy (linked with "dialogue" trigger of NPC Guy)
 if player has item letter
 quest complete
 else
 start dialogue asking player to get letter

```

\_

```
talkGirl (linked with "dialogue" trigger of NPC Guy)
 if player has item letter
 start dialogue asking player to deliver it to Guy
 else
 start dialogue where she will give letter

```

\_

```
giveLetter (triggered within Girl dialogue)
 give letter

```

\_

```
teleportToGirl (linked with "teleport" attribute of NPC Teleport1)
 teleport player near Girl

```

\_

```
teleportToGuy (linked with "teleport" attribute of NPC Teleport2)
 teleport player near Guy

```

## Real Code

### Item

```
n.newItem(ITEM.letter, "Letter", CST.ICON.planEquip,[]);

```

### Dialogue

```
n.newDialogue("Guy",s.FACE.villagerMale0,[
 n.newDialogue_node(DIALOGUE.Guy_intro,"Please. Could you ask Girl for a letter?",[
 n.newDialogue_option("Okay"),
 ]),
]);

n.newDialogue("Girl",s.FACE.villagerFemale0,[
 n.newDialogue_node(DIALOGUE.Girl_intro,"What do you want?",[
 n.newDialogue_option("I want a letter", DIALOGUE.Girl_giveLetter, EVENT.giveLetter),
 n.newDialogue_option("Nothing..."),
 ]),
 n.newDialogue_node(DIALOGUE.Girl_giveLetter,"There you go. Now go give the letter to Guy.",[
 n.newDialogue_option("Thanks"),
 ]),
 n.newDialogue_node(DIALOGUE.Girl_after,"Go give the letter to Guy.",[
 ]),
]);

```

### Events

```
talkGuy(key:number){
 if(s.hasItem(key,ITEM.letter))
 s.completeQuest(key);
 else
 s.startDialogue(key,DIALOGUE.Guy_intro);
}
talkGirl(key:number){
 if(s.hasItem(key,ITEM.letter))
 s.startDialogue(key,DIALOGUE.Girl_after);
 else
 s.startDialogue(key,DIALOGUE.Girl_intro);
}
giveLetter(key:number){
 s.addItem(key,ITEM.letter);
}
teleportToGirl(key:number){
 s.teleport(key,SPOTS_main.t3);
}
teleportToGuy(key:number){
 s.teleport(key,SPOTS_main.t2);
}

```

### Map

```
//Tiled project has a n1, n2, t2, t3 spots on layer SPOT
m.spawnNpc(mapUid,spots.n1,NPC.npc,attrs => {
 attrs.name = 'Guy';
 attrs.onDialogue = EVENT.talkGuy;
 attrs.spriteBase = n.newNpc_spriteBase(CST.SPRITE.villagerMale0,1);
});

m.spawnNpc(mapUid,spots.n2,NPC.npc,attrs => {
 attrs.name = 'Girl';
 attrs.onDialogue = EVENT.talkGirl;
 attrs.spriteBase = n.newNpc_sprite(CST.SPRITE.villagerFemale0,1);
});

m.spawnTeleporter(mapUid,spots.t2,EVENT.teleportToGirl);
m.spawnTeleporter(mapUid,spots.t3,EVENT.teleportToGuy);

```

## Walkthrough from Quest Template

To create a new quest in the Raining Chain Editor:

1. Create new quest. (Ctrl+Shift+P RCE:New Project)
2. Add ids to the enums.
3. Copy-paste the item.
4. Copy-paste the dialogues.
5. Copy-paste the events in EVENT\_CLASS.
6. Add the n1, n2, t2, t3 spots in the .tmx file then "Update Spots".
7. Copy-paste the npc spawning logic in the map onLoad().
8. Test the quest. (Ctrl+Shift+P RCE:Test Project)