HowToAddMapsServerStendhal
Of course you have already read:
Ok, and I assume that you can write or at least read Java.
Modify map TMX file
The maps files are just XML files with special tags, open your maps and make sure that you set x,y position of your map on the world. Semos village is right now (500000,500000) so use something near yours to set correctly the map position.
Now you need to create the stend map files. There are two options: - Generate it using tiled ( Save as xstend ) - Run at stendhal folder: ant convertmaps
The later is prefered as it will also update world.tmx graphics.
Modify world.tmx
Now make sure if your map is new that world.tmx shows it by adding a new tileset with your map image. This step is just for your mental wellness. Stendhal don't use world.tmx.
Create a map file
Create a new Java source file at games/stendhal/server/maps/<name>.java
Open the file and make sure that it looks like this:
package games.stendhal.server.maps;
import games.stendhal.server.StendhalRPWorld;
public class MapName implements IContent
{
public MapName(StendhalRPWorld world)
{
}
}
This is an empty map area file. This file is used just to populate the areas that has previously added to World in the file StendhalRPWorld.java inside the onInit method.
public void onInit() throws Exception
{
// Load zones. Written from left to right and from up to down.
// Please respect it!
// Ground level
addArea("0_semos_mountain_n_w4");
addArea("0_semos_mountain_n2_w2");
addArea("0_semos_mountain_n2_w");
addArea("0_semos_mountain_n2");
Find where your zone should be and just place it between that. Now once it is added, test the result by starting server.
Populating zones
Now open again the Mapname.java file and let's start adding code.
First step is to get the zone we are going to work with:
StendhalRPZone zone=(StendhalRPZone)world.getRPZone(new IRPZone.ID("map_name"));
Once we add the zone we can start adding things. Most usual things we are going to add to a zone are NPC, Portals and items.
Adding Items
Adding Portals
A portal is a door to another place. It can be used to go up and down stairs, or to teleport player to other places or simply to enter a building. Whenever you encounter something that engine challenges you about how to do ( for example cross under a brigde or pass under a castle door ) you can solve it using portals.
There are several types of portals:
- Portal
- One way portal
- Stairs portals
- House Door portals.
A portal is just the generic portal. It works for almost everything you can imagine.
A one way portal is a portal that only exists as endpoint, so none can use the portal to move back to the origin. For example you have such a portal at Semos to reenter game after dying.
For example:
Portal portal=new Portal();
zone.assignRPObjectID(portal);
portal.setx(84);
portal.sety(92);
portal.setNumber(0);
portal.setDestination("0_nalwor_forest_w",61);
zone.addPortal(portal);
portal=new OneWayPortal();
zone.assignRPObjectID(portal);
portal.setx(117);
portal.sety(91);
portal.setNumber(61);
zone.addPortal(portal);
You are responsible of assigning correctly the numbers of each portal.
The House door portal is a special type of portal that automatically creates all the portals and areas needed to add a house to that zone with its entrance on point where the portal is.
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.
Adding NPC
Usually we add NPC to make world more alive and to use them in Quests. It is because of that reason, that is so important that you add NPC on the zone they are. So use something like:
SpeakerNPC npc=npcs.add("Ilisa",new SpeakerNPC()
{
protected void createPath()
{
List<Path.Node> nodes=new LinkedList<Path.Node>();
nodes.add(new Path.Node(9,5));
nodes.add(new Path.Node(14,5));
setPath(nodes,true);
}
protected void createDialog()
{
Behaviours.addGreeting(this);
Behaviours.addJob(this, "I have healing abilities and I heal wounded players. I also sell potions and antidotes.");
Behaviours.addHelp(this, "Ask me to #heal you and I will help you or ask me #offer and I will show my shop's stuff.");
Behaviours.addSeller(this, new Behaviours.SellerBehaviour(shops.get("healing")));
Behaviours.addHealer(this, 0);
Behaviours.addGoodbye(this);
}
});
zone.assignRPObjectID(npc);
npc.put("class","welcomernpc");
npc.set(9,5);
npc.initHP(100);
zone.addNPC(npc);