HowToAddMapsServerStendhal: Difference between revisions
imported>MiguelAngelBlanchLardin |
imported>Oslsachem No edit summary |
||
| Line 110: | Line 110: | ||
== Adding NPC == |
== 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. |
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. |
||
First, you should decide if you're going to use your NPC later in a quest. |
|||
''new SpeakerNPC()'' simply creates a new NPC that has dialogs but will not participate later on any particular quest. |
|||
<pre> |
|||
npc=new SpeakerNPC() |
|||
{ |
|||
}; |
|||
npc.setName("name"); |
|||
</pre> |
|||
Notice that in this case, you have to specify the name later in ''npc.setName()'' |
|||
''npcs.add("name",new SpeakerNPC()...)'' creates also a new NPC '''and besides''' adds it to a global list so next time you need to get the NPC for participating in a quest you can call it by its ''name'' using ''npcs.get(name)'' |
|||
<pre> |
|||
NPC npc=npcs.add("name",new SpeakerNPC() |
|||
{ |
|||
}); |
|||
</pre> |
|||
Notice that in this case, the name is especified first in ''NPC npc=npcs.add("name",...'' |
|||
In other words, ''new SpeakerNPC()'' creates just a new NPC of the class SpeakerNPC but with ''npcs.add("name",new SpeakerNPC()...)'' you are in fact extending SpeakerNPC to add new functionality. |
|||
In this case, let's suppose you plan on using our NPC later in a quest, so use something like: |
|||
<pre> |
<pre> |
||
| Line 146: | Line 175: | ||
And then create a dialog. Dialogs and such are explained in Quest sections. |
And then create a dialog. Dialogs and such are explained in Quest sections. |
||
Now simply assign an id to the npc, set |
Now simply assign an id to the npc, set its outfit either by: |
||
* setting its class to a PNG image that exists at ''data/sprites/npc'' |
* setting its class to a PNG image that exists at ''data/sprites/npc'' |
||
* setting |
* setting its outfit with setOutfit method. |
||
Finally set its initial position and its HP. Don't worry for your NPC. It can't be attacked nor killed. |
Finally set its initial position and its HP. Don't worry for your NPC. It can't be attacked nor killed. |
||
Revision as of 20:42, 14 March 2006
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.
Once that is done add a line like this on StendhalRPWorld.onInit()
populateZone("Mapname");
This line will call your Mapname java class to populate the zone. It is empty right now but you are going to populate it right now.
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.
First, you should decide if you're going to use your NPC later in a quest.
new SpeakerNPC() simply creates a new NPC that has dialogs but will not participate later on any particular quest.
npc=new SpeakerNPC()
{
};
npc.setName("name");
Notice that in this case, you have to specify the name later in npc.setName()
npcs.add("name",new SpeakerNPC()...) creates also a new NPC and besides adds it to a global list so next time you need to get the NPC for participating in a quest you can call it by its name using npcs.get(name)
NPC npc=npcs.add("name",new SpeakerNPC()
{
});
Notice that in this case, the name is especified first in NPC npc=npcs.add("name",...
In other words, new SpeakerNPC() creates just a new NPC of the class SpeakerNPC but with npcs.add("name",new SpeakerNPC()...) you are in fact extending SpeakerNPC to add new functionality.
In this case, let's suppose you plan on using our NPC later in a quest, 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);
Use npcs.add() as this way the NPC is added to a list of NPC from where you can later obtain it for adding more dialogues for quests. Make sure the name you give to your NPC is unique.
Just after that it is a good idea to create a path that the NPC will follow on that area. And then create a dialog. Dialogs and such are explained in Quest sections.
Now simply assign an id to the npc, set its outfit either by:
- setting its class to a PNG image that exists at data/sprites/npc
- setting its outfit with setOutfit method.
Finally set its initial position and its HP. Don't worry for your NPC. It can't be attacked nor killed.
Once that is done add the NPC to zone using zone.addNPC() method.
Congrats you have populated your new zone.