User:Wombat/eAthena NPC Scripting Tutorial

From The Mana World

Here are some basic NPCs that can be used as templates and to learn scripting with. While they use the botcheck map, that is mainly for testing purposes.

Guy

Guy is an NPC you can use for giving information to characters when they question it.

//

botcheck.gat,13,18,0 script Guy	102,{
	mes "[Guy]";
	mes "\"I'm just talking.\"";
	next;
	menu "Good",L_Good,"Bad",L_Bad,"Go on..",L_Goon;
	
L_Good:
	mes "[Guy]";
	mes "\"You selected good.  Good for you!\"";
	close;
	
L_Bad:
	mes "[Guy]";
	mes "\"You selected bad.  You suck!\"";
	close;
	
L_Goon:
	mes "[Guy]";
	mes "\"I'm going to talk for a little bit since you wanted me to go on.\"";
	next;
	mes "[Guy]";
	mes "\"Here I am talking for a second time.  That is if I did this right :D\"";
	next;
	mes "[Guy]";
	mes "\"Here I am talking a third time.  I am running my mouth today!\"";
	close;
}

Dude

This NPC communicates with the NPC "Someone", another NPC. Changing the script can make this a basic message sent and received quest.

//

botcheck.gat,14,19,0	script	Dude	102,{
    if (Dude == 1) goto L_Dude_Notdone;
    if (Dude == 2) goto L_Dude_Done;
    if (Dude == 3) goto L_Dude_Again;
	mes "[Dude]";
    mes "\"Hey, I'm wanting to talk to Someone.\"";
    next;
    menu 
        "I'll talk to him.", L_Talk,
        "I won't talk to him.", L_Notalk;
    close;
    
L_Talk:
    set Dude, 1;
    mes "[Dude]";
    mes "\"Thanks.\"";
    close;
    
L_Notalk:
    mes "[Dude]";
    mes "\"Whatever.\"";
    close;
    
L_Dude_Notdone:
    mes "[Dude]";
    mes "\"I thought you were going to talk to Someone for me!\"";  
	next;
	mes "\"Please do.\"";
    close;
    
L_Dude_Done:
    set Dude, 3;
    mes "[Dude]";
    mes "\"Did you talk to him?\"";
	menu "I did.", -;
    mes "\"Awesome!\"";
    close;
    
L_Dude_Again:
    mes "[Dude]";
    mes "\"Good to see you again!\"";
    close;
}

Someone

//

botcheck.gat,15,20,0 script Someone 102, {
    if (Dude == 1) goto L_Talktodude;
    mes "[Someone]";
    mes "\"Hi there!\"";
    close;
    
L_Talktodude:
    set Dude, 2;
    mes "[Someone]";
    mes "\"You talked to me for Dude.\"";
    close;
}

Jake

Jake gives random equipment for 1000 gold.

//

botcheck.gat,18,15,0 script Jake	102,{
	setarray @Items$, "Bow", "CottonShorts", "Dagger", "LeatherShirt", "Boots", "MinerGloves", "MinersHat";
	set @items$, @Items$[rand(getarraysize(@Items$))];
	
	mes "[Jake]";
	mes "\"For 1000 gold, I'll give you a random item.\"";
	next;
	mes "\"Would you like something random?.\"";
	menu
		"Yes.", L_Yes,
		"No.", -;
	close;
	
L_Yes:
	mes "[Jake]";
	mes "\"Here you go.\"";
	next;
	mes "You get one " + getitemname (@items$) + "!";
	set zeny, zeny - 1000;
	getitem @items$, 1; 
	close;
}

Meelu

A wizard NPC needs a list of equipment. This quest shows you need to delitem on equipment individually.

//

botcheck.gat,17,17,0 script Meelu	102,{
	if (Meelu == 1) goto L_Meelu_Progress;
	if (Meelu == 2) goto L_Meelu_Done;
	mes "[Meelu]";
	mes "\"I'm Meelu, master of the 'Order of Ice' wizard academy.\"";
	next;
	mes "\"My apprentices need starting equipment to survive up here in Snowland.  Maybe you could help me out?\"";
	next;
	mes "\"These ice snakes are too dangerous for my apprentices to handle and have eaten many unfortunate acolytes of my order, ill prepared to take on the dangers they offer.  Despite our losses, I'd like to get some of these hats back so I can ensure my apprentices a fighting chance.  Could you collect some of these wizard hats for me?\"";
	next;
	mes "\"I'll award you with a staff from my order if you can help me out.  I just need 10 hats to raise my inventory for incoming apprentices.\"";
	next;
	mes "\"So what do you say, can you collect some hats for me?\"";
	menu
		"Sounds dangerous, but I'll give it a shot!", L_Yes,
		"No way! I'm too weak to fight these damned snakes!", L_No;
	close;
		
L_Yes:
	set Meelu, 1;
	mes "[Meelu]";
	mes "\"Awesome!  Good luck on getting 20 wizard hats for me!\"";
	close;
	
L_No:
	mes "[Meelu]";
	mes "\"That's too bad.  Hopefully you will get more powerful so you can help me out in the future.\"";
	close;
	
L_Meelu_Progress:
	if (countitem("FancyHat") < 10) goto L_Meelu_NotEnough;
	mes "[Meelu]";
	mes "\You brought me 10 wizard hats!  My apprentices will be very pleased!  Here is a wooden staff.  It is the weapon of choice for many wizards.  Enjoy and thank you very much!\"";
	delitem "FancyHat", 1;
	delitem "FancyHat", 1;
	delitem "FancyHat", 1;
	delitem "FancyHat", 1;
	delitem "FancyHat", 1;
	delitem "FancyHat", 1;
	delitem "FancyHat", 1;
	delitem "FancyHat", 1;
	delitem "FancyHat", 1;
	delitem "FancyHat", 1;
	getitem "Bow", 1;
	set Meelu, 2;
	close;

L_Meelu_NotEnough:
	mes "[Meelu]";
	mes "\"It doesn't seem you have enough wizard hats for my inventory.  Please hurry and get me 10 wizard's hats for my apprentices.\"";
	close;

L_Meelu_Done:
	mes "[Meelu]";
	mes "\"Thank you for all your help.  My apprentices are making it a little better out here in Snowland.\"";
	close;
}