This quest example covers chests and npc tags.
Logic[]
- Open a chest which gives a scroll item and also spawn monsters.
- 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:
- Create new quest. (Ctrl+Shift+P RCE:New Project)
- Add ids to the enums.
- Copy-paste the quest variable.
- Copy-paste the item.
- Copy-paste the events in EVENT_CLASS.
- Add the q1 spots in the .tmx file then "Update Spots". Once again, make sure to put the spot inbetween tiles.
- Copy-paste the npc spawning logic in the map onLoad().
- Test the quest. (Ctrl+Shift+P RCE:Test Project)