HowToAddMapsServerStendhal: Difference between revisions
Content deleted Content added
imported>Mort →Adding NPC: This was terribly outdated. I updated it, but it doesn't yet describe the new XML stuff. |
imported>Mort →Adding NPC: described how to define NPCs using XML |
||
Line 146:
Finally the stairs portals also automate the creation of stairs between two areas. It is very important that the portals ( both ends ) are exactly on the same position but on different levels. Position means absolute position. Also, due to current implementation, be careful '''not''' to place omni-directional stair portals at the same exact location between adjacent levels if they're not meant to be linked, as they might inadvertantly be linked. Directional stairs are safer and only link with the level they go toward.
== Adding
Usually we add
=== The old way ===
This is how NPCs used to be added to the world. The downside of this is that you need a lot of Java code. If you're adding new NPCs, consider using the new way of doing it, as described in the next section.
''SpeakerNPC npc = new SpeakerNPC() { ... }'' creates a new NPC. ''NPCList.get().add(npc)'' adds it to a global list so next time you need to get the NPC for participating in a quest, or if you want to teleportto it, you can call it by its ''name'' using ''NPCList.get().get(name)''.
Line 211 ⟶ 214:
Once that is done add the NPC to zone using ''zone.add()'' method.
=== The new way ===
This is the new way of adding NPCs. It requires less Java coding skills; Java code is only required for the dialog and for special behaviour, everything else is defined in XML.
First, you need to create a Java file for the dialog. You should put it in a subpackage of <code>games.stendhal.server.maps</code>; the package describes where NPC is located.
For example, here is the Java code for a simple NPC on Athor island:
package games.stendhal.server.maps.athor.holiday_area;
import games.stendhal.server.entity.npc.SpeakerNPC;
import games.stendhal.server.entity.npc.SpeakerNPCFactory;
public class SwimmerNPC extends SpeakerNPCFactory {
@Override
protected void createDialog(SpeakerNPC npc) {
npc.addGreeting("Don't disturb me, I'm trying to establish a record!");
npc.addQuest("I don't have a task for you, I'm too busy.");
npc.addJob("I am a swimmer!");
npc.addHelp("Try the diving board! It's fun!");
npc.addGoodbye("Bye!");
};
}
This will make the NPC react to typical words that players might say to him, e.g. "hi", "help", and "bye". This Java class is stored in the file <code>/src/games/stendhal/server/maps/athor/holiday_area/SwimmerNPC.java</code>. Of course this is just a simple example, and more sophisticated dialogs and behaviours are possible with more complex Java code.
Next, we need place the NPC and set the name and some other attributes. The NPC in the example lives on Athor island, so the information is stored in <code>data/conf/zones/athor.xml</code>. The map he's on is called 0_athor_island, so the information is inside the <code><zone name="0_athor_island"...> ... </zone></code> tag:
<entity x="67" y="63">
<implementation class-name="games.stendhal.server.maps.athor.holiday_area.SwimmerNPC">
<parameter name="name">Enrique</parameter>
<parameter name="class">swimmer3npc</parameter>
<parameter name="node0">67,68</parameter>
<parameter name="node1">67,63</parameter>
</implementation>
</entity>
* The first line says that the NPC should initially be placed at the point (67, 63).
* The second line tells the server where we stored our Java file with the dialog.
* The third line says that our NPC should be called Enrique.
* The fourth line defines how the NPC should look like. In this case, the graphics from the file <code>data/sprites/npc/swimmer3npc.png</code> will be used.
* The fifth and sixth lines define the path along which Enrique should walk/swim. He will first visit the point (67, 68), then return to his start position (67, 63), and continue like this infinitely. You can of course create NPCs with more than 2 nodes, but:
** keep in mind that counting starts with 0
** make sure that you don't forget a node number, e.g. if you have node6, you must also have node5, node4 etc.
If you don't want your NPC to walk around, just leave out the node parameters. Instead, you should add a parameter that defines in which direction the NPC should look on server startup (left, right, up, down), e.g.:
<parameter name="direction">down</parameter>
Other parameters you can use:
<parameter name="hp">50</parameter>
This will make the NPC look wounded (the health bar will be at the middle). Note that, as NPCs cannot be killed, this is only for decoration. If you leave this parameter out, the hitpoints will be set to 100, which means full health.
<parameter name="level">10</parameter>
This sets the NPC's level of experience. Again, this is only for decoration, as NPCs don't fight or die.
Congrats you have populated your new zone.
Line 216 ⟶ 283:
[[Stendhal
| |||