HowToAddMapsServerStendhal: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Oslsachem
imported>Chad3f
Line 20: Line 20:


= Create a map file=
= Create a map file=
If you need to do custom zone configuration that is not possible via the "zones.xml" file (such as adding NPC's), for each zone, create one or more new Java source file(s) at '''src/games/stendhal/server/maps/<area>/<location>/<level>_<entity>.java'''. The directory path after '''maps/''' would be the same as your '''.tmx''' file uses. Ideally this would be one file per independant entity created (so they can be enabled/diabled separately).
Create a new Java source file at '''games/stendhal/server/maps/<name>.java'''


Open the file and make sure that it looks like this:
Open the file and make sure that it looks like this:

<pre>
<pre>
package games.stendhal.server.maps;
package games.stendhal.server.maps.myarea.mylocation;


import games.stendhal.server.StendhalRPWorld;
import java.util.Map;
import games.stendhal.server.StendhalRPZone;
import games.stendhal.server.maps.ZoneConfigurator;


public class MapName implements IContent
public class IL0_MyZone implements ZoneConfigurator
{
{
/**
public MapName(StendhalRPWorld world)
* Configure a zone.
{
}
*
* @param zone The zone to be configured.
}
* @param attributes Configuration attributes.
*/
public void configureZone(StendhalRPZone zone, Map<String, String> attributes) {
// Add/configure entity to "zone", using optional configuration "attributes"
}
}
</pre>
</pre>


To enable a zone in the server, edit the file "data/conf/zones.xml" and add an entry (in the appropriete top-down/left-right/level order), giving it the zone name and converted map filename to use:
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.
<pre>
<pre>
<zone name="int_myarea_mylocation" file="int_myarea_mylocation.xstend"/>
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");
</pre>
</pre>


If you have custom configuration code, add appropriete "<configurator>" entries in your "<zone>" element, using the fully qualified package/class name of your java classes:
Find where your zone should be and just place it between that.


<pre>
Once that is done add a line like this on ''StendhalRPWorld.onInit()''
<zone name="int_myarea_mylocation" file="int_myarea_mylocation.xstend">

<configurator class-name="games.stendhal.server.maps.myarea.mylocation.IL0_MyZone"/>
populateZone("Mapname");
</zone>

</pre>
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.
Now once it is added, test the result by starting server.