HowToAddMapsServerStendhal: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Kymara add how to set configurator class and dont use ilisa as example. shes mixed java xml now. make it fictitious |
imported>Hendrik Brummermann No edit summary |
||
| Line 1: | Line 1: | ||
{{Navigation for Stendhal Top}} |
{{Navigation for Stendhal Top|Extending}} |
||
{{Navigation for Stendhal |
{{Navigation for Stendhal Extenders}} |
||
Of course you have already read: |
Of course you have already read: |
||
* [[HowToUseTiledToCreateStendhalMaps]] |
* [[HowToUseTiledToCreateStendhalMaps]] |
||
| Line 36: | Line 36: | ||
To enable a zone in the server, edit the file '''data/conf/zones/<area>.xml''' and add an entry (in the appropriate level/top-down/left-right order), giving it the zone name and map tmx file to use: |
To enable a zone in the server, edit the file '''data/conf/zones/<area>.xml''' and add an entry (in the appropriate level/top-down/left-right order), giving it the zone name and map tmx file to use: |
||
<source lang="xml"> |
|||
<pre> |
|||
<zone name="int_myarea_mylocation" file="interiors/myarea/mylocation.tmx"/> |
<zone name="int_myarea_mylocation" file="interiors/myarea/mylocation.tmx"/> |
||
<zone name="0_myarea_mylocation" level="0" x="100000" y="200000" file="Level 0/myarea/mylocation.tmx"> |
<zone name="0_myarea_mylocation" level="0" x="100000" y="200000" file="Level 0/myarea/mylocation.tmx"> |
||
</ |
</source> |
||
In the case of non-interior zones, the level and x/y coordinate should also be included in the <zone> element (setting them in the tmx file has been deprecated). For interior zones, the level xml attribute should '''not''' be set (for now). The coordinate starts at the top-left corner, and should align against (but never overlap) other zones in the same level. |
In the case of non-interior zones, the level and x/y coordinate should also be included in the <zone> element (setting them in the tmx file has been deprecated). For interior zones, the level xml attribute should '''not''' be set (for now). The coordinate starts at the top-left corner, and should align against (but never overlap) other zones in the same level. |
||
| Line 59: | Line 59: | ||
Open the file and make sure that it looks like this: |
Open the file and make sure that it looks like this: |
||
<source lang="java"> |
|||
<pre> |
|||
package games.stendhal.server.maps.myarea.mylocation; |
package games.stendhal.server.maps.myarea.mylocation; |
||
| Line 66: | Line 66: | ||
import games.stendhal.server.config.ZoneConfigurator; |
import games.stendhal.server.config.ZoneConfigurator; |
||
public class MyEntity implements ZoneConfigurator |
public class MyEntity implements ZoneConfigurator { |
||
| ⚫ | |||
{ |
|||
* Configure a zone. |
|||
* |
|||
* @param zone The zone to be configured. |
|||
| ⚫ | |||
* @param attributes Configuration attributes. |
|||
| ⚫ | |||
* @param attributes Configuration attributes. |
|||
| ⚫ | |||
*/ |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
} |
} |
||
</ |
</source> |
||
For each custom configuration code class, add appropriate "<configurator>" entries in your "<zone>" element, using the fully qualified package/class name of your java classes: |
For each custom configuration code class, add appropriate "<configurator>" entries in your "<zone>" element, using the fully qualified package/class name of your java classes: |
||
<source lang="xml"> |
|||
<pre> |
|||
<zone name="int_myarea_mylocation" file="interiors/myarea/mylocation.tmx"> |
<zone name="int_myarea_mylocation" file="interiors/myarea/mylocation.tmx"> |
||
<configurator class-name="games.stendhal.server.maps.myarea.mylocation.MyEntity"/> |
<configurator class-name="games.stendhal.server.maps.myarea.mylocation.MyEntity"/> |
||
</zone> |
</zone> |
||
</ |
</source> |
||
Now once it is added, test the result by starting server. |
Now once it is added, test the result by starting server. |
||
| Line 146: | Line 145: | ||
''SpeakerNPC npc = new SpeakerNPC() { ... }'' creates a new NPC. When added to a zone, NPCs are added 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)''. |
''SpeakerNPC npc = new SpeakerNPC() { ... }'' creates a new NPC. When added to a zone, NPCs are added 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)''. |
||
<source lang="java"> |
|||
<pre> |
|||
SpeakerNPC npc = new SpeakerNPC("name") { |
SpeakerNPC npc = new SpeakerNPC("name") { |
||
/... |
/... |
||
}); |
}); |
||
</ |
</source> |
||
An example is: |
An example is: |
||
<source lang="java"> |
|||
<pre> |
|||
SpeakerNPC npc = new SpeakerNPC("Mr Healer") { |
SpeakerNPC npc = new SpeakerNPC("Mr Healer") { |
||
protected void createPath() { |
protected void createPath() { |
||
| Line 186: | Line 185: | ||
zone.add(npc); |
zone.add(npc); |
||
</ |
</source> |
||
The NPC is added to a list of NPC from where you can later obtain it for adding more dialogues for quests. So, it is very important to make sure the name you give to your NPC is unique. |
The NPC is added to a list of NPC from where you can later obtain it for adding more dialogues for quests. So, it is very important to make sure the name you give to your NPC is unique. |
||
| Line 192: | Line 191: | ||
It is a good idea to create a path that the NPC will follow on that area. Just used your tiled map or walk around in game and check coordinates to choose your nodes. You can also make the NPC stand still by using this instead: |
It is a good idea to create a path that the NPC will follow on that area. Just used your tiled map or walk around in game and check coordinates to choose your nodes. You can also make the NPC stand still by using this instead: |
||
<source lang="java"> |
|||
protected void createPath() { |
|||
// NPC does not move |
|||
// NPC does not move |
|||
setPath(null); |
|||
} |
|||
</pre> |
|||
</source> |
|||
Your NPC will stand still at whatever point you set as the initial position with <code>npc.setPosition(x, y);</code>. |
Your NPC will stand still at whatever point you set as the initial position with <code>npc.setPosition(x, y);</code>. |
||
| Line 213: | Line 213: | ||
We need to tell the zone to load this configuration class file. The NPC in the example lives in the ados area, so the information is stored in data/conf/zones/ados.xml. The map she's on is called int_ados_magician_house, so the information is inside the <zone name="int_ados_magician_house" file="interiors/ados/magician_house.tmx"> </zone> section. |
We need to tell the zone to load this configuration class file. The NPC in the example lives in the ados area, so the information is stored in data/conf/zones/ados.xml. The map she's on is called int_ados_magician_house, so the information is inside the <zone name="int_ados_magician_house" file="interiors/ados/magician_house.tmx"> </zone> section. |
||
To load the java class file you created just add the line |
To load the java class file you created just add the line |
||
<source lang="xml"> |
|||
<configurator class-name="games.stendhal.server.maps.ados.magician_house.WizardNPC" /> |
<configurator class-name="games.stendhal.server.maps.ados.magician_house.WizardNPC" /> |
||
</source> |
|||
right after the <zone ... tmx"> |
right after the <zone ... tmx"> |
||
Check the location of the file matches the path set in the class name! |
Check the location of the file matches the path set in the class name! |
||
| Line 225: | Line 227: | ||
For example, here is the Java code for a simple NPC on Athor island: |
For example, here is the Java code for a simple NPC on Athor island: |
||
<source lang="java"> |
|||
package games.stendhal.server.maps.athor.holiday_area; |
|||
| ⚫ | |||
import games.stendhal.server.entity.npc.SpeakerNPC; |
|||
| ⚫ | |||
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.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!"); |
|||
| ⚫ | |||
}; |
|||
} |
|||
</source> |
|||
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. |
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. |
||
| Line 247: | Line 251: | ||
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: |
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: |
||
<source lang="xml"> |
|||
<entity x="67" y="63"> |
|||
<implementation class-name="games.stendhal.server.maps.athor.holiday_area.SwimmerNPC"> |
|||
<parameter name="name">Enrique</parameter> |
|||
<parameter name=" |
<parameter name="name">Enrique</parameter> |
||
<parameter name=" |
<parameter name="node0">67,68</parameter> |
||
</ |
<parameter name="node1">67,63</parameter> |
||
</implementation> |
|||
<attribute name="class">swimmer3npc</attribute> |
|||
</entity> |
|||
</source> |
|||
* The first line says that the NPC should initially be placed at the point (67, 63). |
* The first line says that the NPC should initially be placed at the point (67, 63). |
||
| Line 268: | Line 274: | ||
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.: |
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.: |
||
<source lang="xml"> |
|||
<parameter name="direction">down</parameter> |
<parameter name="direction">down</parameter> |
||
</source> |
|||
Other attributes you can use: |
Other attributes you can use: |
||
<source lang="xml"> |
|||
<attribute name="hp">50</attribute> |
<attribute name="hp">50</attribute> |
||
</source> |
|||
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. |
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. |
||
<source lang="xml"> |
|||
<attribute name="level">10</attribute> |
<attribute name="level">10</attribute> |
||
</source> |
|||
This sets the NPC's level of experience. Again, this is only for decoration, as NPCs don't fight or die. |
This sets the NPC's level of experience. Again, this is only for decoration, as NPCs don't fight or die. |
||