Stendhal Quest Coding: Difference between revisions
Content deleted Content added
imported>MiguelAngelBlanchLardin No edit summary |
imported>MiguelAngelBlanchLardin No edit summary |
||
Line 263:
{
return player.isQuestCompleted("ceryl_book");
</pre>
The isQuestCompleted method returns true if the quest is already complete or false in other case.
Each quest has a name (''ceryl_book'') and a state. Your quest can have as many subquests as you wants.
<pre>
}
},
Line 286 ⟶ 292:
}
});
</pre>
In this case the quest is not started because hasQuest was false. So we start the new quest.
A good initial state for a quest is ''start'' and we set it using ''setQuest'' method.
<pre>
npc.add(60,"no",null,1,"Oh! Ok :(",null);
Line 303 ⟶ 314:
npc.add(1,"jynath",null,1,"Jynath is a witch that lives at south of Or'ril castle. So will you get me the #book?",null);
}
</pre>
Here you have a example of what not to do :)
Two different states with exactly the same trigger and the same text.
Better rewrite the offending lines as:
npc.add(new int[]{1,60},"jynath",null,1,"Jynath is a witch that lives at south of Or'ril castle. So will you get me the #book?",null);
This way you have less probability of forgetting to change the other line.
It is duplicated because player may ask who is Jynath before accepting the quest and after accepting it.
This completes the first step of the quest. As you see there is only one zone and one NPC involved.
Now let's see the second step of the quest: Talk with Jynath for the book.
<pre>
private void step_2()
{
Line 310 ⟶ 338:
SpeakerNPC npc=npcs.get("Jynath");
</pre>
As previously explained we get the zone where we are going to work in and we get the NPC that is going to be the main actor of this step.
<pre>
/** If player has quest and is in the correct state, just give him the book. */
npc.add(1,"book",new SpeakerNPC.ChatCondition()
Line 316 ⟶ 349:
{
return player.hasQuest("ceryl_book") && player.getQuest("ceryl_book").equals("start");
</pre>
This condition is just more complex because we want to check that the quest is started, so we need to check if player hasQuest and that the quest state is the one we are expecting.
<pre>
}
},
Line 327 ⟶ 365:
Item book=world.getRuleManager().getEntityManager().getItem("book_black");
player.equip(book);
</pre>
If the quest is in the correct state we tell player that we give him the book and we add it to player inventory. Each item knows where it should equip itself. So just write player.equip(book) and done.
Perhaps you will be interested in handle extreme conditions like inventory full or similar ones.
<pre>
}
});
Line 339 ⟶ 384:
},
1,"Hurry up! Grab the book to #Ceryl.", null);
</pre>
Perhaps player didn't notice about the book. So tell it that book is already there and to hurry to grab the book to Ceryl.
<pre>
npc.add(1,"ceryl",null,1,"Ceryl is the book keeper at Semos's library",null);
Line 352 ⟶ 402:
1,"Shhhh!!! I am working on a new potion!.", null);
}
</pre>
Now the last step of our quest: Return the book to Ceryl
<pre>
private void step_3()
{
| |||