Stendhal NPC Coding: Difference between revisions
Content deleted Content added
imported>Kymara No edit summary |
imported>Madmetzger |
||
| (47 intermediate revisions by 2 users not shown) | |||
Line 3:
{{Stendhal NPCs}}
Usually we add NPCs (non-player characters) to make world more alive and to use them in Quests
This is how NPCs are added to the world.
Line 60:
*/
public void configureZone(final StendhalRPZone zone, final Map<String, String> attributes) {
buildNPC(zone
}
Line 68:
<source lang="java">
private void buildNPC(final StendhalRPZone zone
final SpeakerNPC npc = new SpeakerNPC("Mr Healer") {
protected void createPath() {
Line 78:
protected void createDialog() {
// Lets the NPC reply with "Hallo" when a player greets him. But we could have set
addGreeting();
// Lets the NPC reply when a player says "job"
Line 89:
addHealer(0);
// respond about a special trigger word
addReply("potions","Please ask for my #offer.")
// use standard goodbye, but you can also set one inside the ()
addGoodbye();
Line 95:
});
// This determines how the NPC will look like. welcomernpc.png is a picture in data/sprites/npc/
npc.setEntityClass("welcomernpc");
// set a description for when a player does 'Look'
npc.setDescription("You see Mr Healer, he looks a a bit busy at the moment but perhaps he can help you anyway.");
// Set the initial position to be the first node on the Path you defined above.
npc.setPosition(9, 5);
Line 133 ⟶ 134:
We set its outfit either by:
* setting its class to a [[StendhalRefactoringGraphics#NPCs|PNG image]] that exists at ''data/sprites/npc'', e.g. <code>npc.setEntityClass("welcomernpc");</code>
* setting its outfit with setOutfit method e.g. <code>npc.setOutfit(new Outfit(0, 05, 01, 06, 01));</code>
It is nice to set a description for when the player does ''Look''. If you don't set one, it will just say: ''You see [NPC Name].''
Finally set its initial position and its HP. Don't worry for your NPC. It can't be attacked nor killed.
| |||