Stendhal Quest Coding: Difference between revisions
Content deleted Content added
imported>MiguelAngelBlanchLardin No edit summary |
imported>MiguelAngelBlanchLardin No edit summary |
||
Line 183:
Now let's add some options when player is in state 1 like job, offer, buy, sell, etc.
add(1, "job", null, 1, "I work as a part time example showman",null)
add(1, "offer", null, 1, "I sell best quality swords",null)
Ok, two new events: job and offer, they go from state 1 to 1, because after listening to them
the NPC can listen something like job.
Easy, isn't it?
add(1, "buy", 20, null, new ChatAction()▼
{▼
Now let's add something harder.
public void fire(Player player, String text, SpeakerNPC engine)▼
Let's make the NPC ask a question and let's expect a reply to the question.
I hope you see that this means adding a new state different of 1, because while we are waiting for the reply we are not interested in anything else.
add(1, "fun", null, 50, "Do you want me to convert you in a heady bare elf?", null)
If player says ''fun'' then NPC will ask the question. Note that new state is 50 instead of 1.
Now let's add two new states for the reply: yes and no.
<pre>
add(50, "yes", new ChatCondition()
{
public boolean fire(Player player, String text, SpeakerNPC engine)
if(item.equals("sword"))▼
{
return player.equals(HEADY_BARE_ELF);
}
1, "Sorry!, you are already a heady bare elf!", null);
</pre>
Heh! We add a condition on the yes to handle the case of the player being already a heady bare elf.
This condition is perhaps handle better on the Fire part as we really want to execute something.
<pre>
add(50, "yes", null,
▲ {
▲ public void fire(Player player, String text, SpeakerNPC engine)
{
engine.say("Sorry, I don't sell "+item);▼
▲ {
}
else
{
engine.say("Ok! But there is no return way! KAAABOOOM!");
player.setOutfit("0");
world.modify(player);
}
}
});
</pre>
See? This way is simpler and you save having to adding two states.
Let add the no state to complete it.
<pre>
</pre>
Now NPC will only accept on state 50 either yes or no.
We could add a help message in case player get blocked.
<pre>
add(50, "help", null, 50, "Do you want me to convert you in a bare elf?", null);
</pre>
Finally we want to finish the conversation, so whatever state we are we want to finish a conversation with Bye.▼
add(-1, "bye", 0, "Bye!.", null);
▲Finally we want to finish the conversation, so whatever state we are we want to finish a conversation
▲add(-1, "bye", 0, "Bye!.", null);
Let's continue with our example and I comment anything that is really important beyond this point.
▲We use -1 as a wildcard, so it text is bye the transition.happens.
<pre>
| |||