Stendhal Quest Coding

From Arianne
Revision as of 18:24, 19 November 2009 by imported>Hendrik Brummermann (Teaching the NPC to talk)
Jump to navigation Jump to search


Stendhal Quests

If you have ideas for new quests or are interested in helping to refine quest ideas, please have a look at the Quest Contributor's Guide or the Stendhal Quest Ideas.


This page is currently reworked. You can find the old content on the talk page

Before you start

This page describes how to code a quest. You don't need to know a lot about Java. You should, however, already have setup an IDE and be able to compile and start a local Stendhal server.

This tutorial assumes that the new quest only uses NPCs and items that already exist in Stendhal.

Creating a quest skeleton

This tutorial is based on the quest "Beer For Hayunn". As this quest already exists, you may want to delete the java file locally in order to follow this tutorial.

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).

Please create a new file in that folder called BeerForHayunn.java. (Note: The upper / lower case spelling is important, even on Microsoft Windows):

<source lang="java"> package games.stendhal.server.maps.quests;

import games.stendhal.server.entity.npc.*; import games.stendhal.server.entity.npc.action.*; import games.stendhal.server.entity.npc.condition.*; import games.stendhal.server.entity.player.*; import java.util.*;

public class BeerForHayunn extends AbstractQuest {

public static final String QUEST_SLOT = "beer_hayunn";

@Override public void addToWorld() { super.addToWorld(); }

@Override public String getSlotName() { return QUEST_SLOT; }

@Override public String getName() { return "BeerForHayunn"; } } </source>

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.

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:

<source lang="java"> import games.stendhal.server.maps.quests.BeerForHayunn;

// [...]

loadQuest(new BeerForHayunn()); </source>

Of course in the case of this tutorial the two lines for BeerForHayunn are alrady there.

Teaching the NPC to talk

Okay, we have now completed the preparation. Our first task is to get Hayunn to reply to the word "quest".

Therefore we add a new method called prepareQuestStep() at the end of the file BeerForHayunn, just above the last closing "}". This method will

<source lang="java"> public void prepareQuestStep() {

// get a reference to the Hayunn npc SpeakerNPC npc = npcs.get("Hayunn Naratha");

// add a reply on the trigger phrase "quest" to Hayunn npc.addReply("quest", "My mouth is dry, but I can't be seen to abandon this teaching room!"); } </source>


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 "addToWorld" which will be executed on server start. So we add a call to our method in "addToWorld":

<source lang="java"> @Override public void addToWorld() { super.addToWorld(); prepareQuestStep(); } </source>

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 "quest", after starting the conversation with "hi". He should now respond with the sentence "My mouth is dry, but I can't be seen to abandon this teaching room!".


Trigger phrases

  • #beer

Please make sure this works before advancing to the next section of this tutorial:

Teaching the NPC to ask the players whether they will do the quest

  • add with states
  • very basic introduction to FSM

Teaching the NPC to remember the player

  • ChatAction
  • ChatCondition

Rewarding the player

  • MultiAction

Further Reading