Stendhal Quest Coding: Difference between revisions
Content deleted Content added
imported>Kymara To add a new NPC, see Stendhal NPC Coding. |
imported>Ufizavipupu No edit summary |
||
Line 1:
=[http://egebyromedu.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
{{Navigation for Stendhal Top|Contributing}}
{{Navigation for Stendhal Contributors}}
Line 17 ⟶ 18:
== Creating a quest skeleton ==
This tutorial is based on the quest
Quest files are put into the package games.stendhal.server.maps.quests. (If you are new to Java: this refers to the folder stendhal/src/games/stendhal/server/maps/quests).
Line 23 ⟶ 24:
Please create a new file in that folder called BeerForHayunn.java. (Note: The upper / lower case spelling is important, even on Microsoft Windows):
package games.stendhal.server.maps.quests;
Line 34 ⟶ 35:
public class BeerForHayunn extends AbstractQuest {
public static final String QUEST_SLOT =
@Override
Line 48 ⟶ 49:
@Override
public String getName() {
return
}
}
Don't worry, if you don't understand a word of this; just copy it. We will explain the important parts and extend this skeleton in the following sections.
Line 57 ⟶ 58:
In order for the Stendhal server to pick up this file, it has to be registered in the file StendhalQuestSystem.java in the package games.stendhal.server.core.rp by adding two lines at the appropriate places:
import games.stendhal.server.maps.quests.BeerForHayunn;
Line 63 ⟶ 64:
loadQuest(new BeerForHayunn());
Of course in the case of this tutorial the two lines for BeerForHayunn are already there.
Line 69 ⟶ 70:
== Teaching the NPC to talk ==
Okay, we have now completed the preparation. Our first task is to get Hayunn to reply to the word
Therefore we add a new method called prepareQuestStep() at the end of the file BeerForHayunn, just above the last closing
public void prepareQuestStep() {
// get a reference to the Hayunn npc
SpeakerNPC npc = npcs.get(
// add a reply on the trigger phrase
npc.addReply(
}
There is one little step left before we can test it: We need to tell the server to execute our new method. There is already a method called
@Override
public void addToWorld() {
Line 93 ⟶ 94:
prepareQuestStep();
}
Okay, all done? Please start the server (depending on whether you are using an IDE or not you might have to compile or build first). Go to Hayunn and say
== Commonly used conversation phrases ==
Good, Hayunn now replies to the trigger
Let's adjust the above sample by using ''ConversationPhrases.QUEST_MESSAGES'' instead of the hard coded word
public void prepareQuestStep() {
// get a reference to the Hayunn npc
SpeakerNPC npc = npcs.get(
// add a reply on quest related trigger phrases to Hayunn
npc.addReply(ConversationPhrases.QUEST_MESSAGES,
}
Please compile and restart your server. Hayunn should now respond to
== Blue trigger words ==
As you probably know NPCs can say words in blue, words that they expect to be repeated by the player. We want to add such words for
So, how do we get the words colored blue? Simple, add a
public void prepareQuestStep() {
// get a reference to the Hayunn npc
SpeakerNPC npc = npcs.get(
// ask for a beer and explain it
npc.addReply(ConversationPhrases.QUEST_MESSAGES,
// explain blue words
npc.addReply(
npc.addReply(
// an example for escaping #
npc.addReply(
}
You know the drill: Compile, restart and try it out.
| |||