Quest Example 1

This quest covers the basics and death event. The complete quest file can be found in the RCE via "Ctrl+P: QquestExample1".

IMPORTANT: This page assumes you have installed the Raining Chain Editor and you have read the basics of Quest Creation.

### Logic

1. Talk with NPC who asks to kill Dragon.
2. Kill Dragon
3. Talk with NPC to complete quest

## Pseudocode

### Events

```
talkRingo (linked with "onDialogue" trigger of NPC Ringo)
 if haveKilledDragon == false
 ask player to kill dragon
 if haveKilledDragon == true
 quest complete

```

\_

```
killDragon (linked with "onDeath" trigger of NPC Dragon)
 set haveKilledDragon = true

```

## Real Code

### Variable

```
[VAR.haveKilledDragon]:false

```

### Events

```
talkRingo(key:number){
 if(s.get(key,VAR.haveKilledDragon) === false)
 s.message(key,"Go kill the dragon.");
 else
 s.completeQuest(key);
}

```

```
killDragon(key:number){
 s.set(key,VAR.haveKilledDragon,true);
}

```

### Map

```
//Tiled project has a n1 and e1 spots on layer SPOT
m.spawnNpc(mapUid, spots.n1, NPC.npc, attrs => {
 attrs.onDialogue = EVENT.talkRingo;
});

m.spawnNpc(mapUid, spots.e1, NPC.dragon, attrs => {
 attrs.onDeath = EVENT.killDragon;
});

```

## Walkthrough from Quest Template

### Create Template

To create a new quest in the Raining Chain Editor:

1. Open the command list with Ctrl+Shift+P.
2. Select "RCE: New Project".
3. Enter "Qexample1" as the new quest id.

### Enums

First, we need to declare all constant ids before being able to use them.
On the Raining Chain Editor, press Ctrl+Shift+A while having your mouse over a undeclared id to automatically add it to the enum.

```
enum VAR {haveKilledDragon} //The list of quest variable ids
enum MAP {main} //The list of map ids

```

We also need to declare the list of built-in npcs we are planning to use.
In this quest, we are using two: npc and dragon.

```
enum NPC {npc,dragon}

```

### Variables

Copy-paste the variable from the previous section.

```
n.newVariable({
 [VAR.haveKilledDragon]:false,
});

```

### Events

Copy-paste the events talkRingo and killDragon of the previous section.

```
class EVENT_CLASS extends API.CORE_EVENTS<LABEL> {
 talkRingo(key:number){
 if(s.get(key,VAR.haveKilledDragon) === false)
 s.message(key,"Go kill the dragon.");
 else
 s.completeQuest(key);
 }

 killDragon(key:number){
 s.set(key,VAR.haveKilledDragon,true);
 }
}

```

### Maps

The quest template already has the map main created. We need to edit it to add the two spots where the npc and the dragon will spawn.

Click "Open Map File" to open map editor Tiled.
Go on the Tileset #9 and add n1 and e1 spots on the SPOT layer.
Once new spots are added, you need to refresh the list of spots by clicking "Update Spots".

Note: If "Update Spots" doesn't work, make sure that you indeed added the n1 and e1 tiles on the SPOT layer.

Copy-paste the npc spawning logic from the previous step in the onLoad map function.

```
const SPOTS_main = {n1:S,e1:S};
n.newMapAddon(MAP.main,{
 spots:SPOTS_main,
 onLoad: function(mapUid:number,spots:typeof SPOTS_main){
 m.spawnNpc(mapUid, spots.n1, NPC.npc, attrs => {
 attrs.onDialogue = EVENT.talkRingo;
 });

 m.spawnNpc(mapUid, spots.e1, NPC.dragon, attrs => {
 attrs.onDeath = EVENT.killDragon;
 });
 }
});

```

### Testing

To test your new quest, you will need to start the game server.

1. Run the command "RCE: Test Project" in the Raining Chain Editor (with Ctrl+Shift+P).
2. Open Google Chrome and go to localhost:3000/game
3. Sign in (or sign up) in the game.

Errors will appear in the Visual Studio code terminal. You will automatically be teleported in the first spot of the first quest map. Note: You can add m.setAsStartPoint() to spawn elsewhere.