RainingChain Wikia
Advertisement

This quest example covers chests and npc tags.

Logic[]

  1. Open a chest which gives a scroll item and also spawn monsters.
  2. Use the item to kill all the monsters.

Pseudocode[]

Variable[]

  • haveOpenedChest = false

Item[]

  • Scroll (with event useItem)

Events[]

getChestState (linked with "getState" of chest)
    return haveOpenedChest
_
openChest (linked with "openEvent" trigger of chest)
    set haveOpenedChest = true
    add item scroll
    spawn 2 monsters with tag "monster = true"
_
useItem (linked with option of Scroll item)
    for every npc in the map with the tag "monster = true":
        kill the npc

Maps[]

Spawn a chest that gives a scroll and spawn 2 monsters.

Real Code[]

Variable[]

[VAR.haveOpenedChest]:false

Item[]

n.newItem(ITEM.scroll, "Scroll", CST.ICON.planEquip,[
    n.newItem_option(EVENT.useItem,"Use")
]);

Events[]

getChestState(key:number){
    return s.get(key,VAR.haveOpenedChest);
}
openChest(key:number){
    s.set(key,VAR.haveOpenedChest,true);
    s.addItem(key,ITEM.scroll);
    s.spawnNpcOnTop(key,MAP.main,NPC.bat,attrs => {
        attrs.tag = {[TAG.monster]:true};
    });
    s.spawnNpcOnTop(key,MAP.main,NPC.bat,attrs => {
        attrs.tag = {[TAG.monster]:true};
    });
}
useItem(key:number){
    s.forEachNpc(key,MAP.main,function(eid){
        s.killActor(eid);
    },{[TAG.monster]:true});
    s.completeQuest(key);
}

Map[]

//Tiled project has a q1 spot on layer SPOT.
m.spawnLoot(mapUid, spots.q1,EVENT.getChestState,EVENT.openChest);


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 quest variable.
  4. Copy-paste the item.
  5. Copy-paste the events in EVENT_CLASS.
  6. Add the q1 spots in the .tmx file then "Update Spots". Once again, make sure to put the spot inbetween tiles.
  7. Copy-paste the npc spawning logic in the map onLoad().
  8. Test the quest. (Ctrl+Shift+P RCE:Test Project)
Advertisement