nox
01-19-2006, 11:31 AM
Why do i say this is a basic guide?
This should be what you are expecting of a basic scriptor. This are the basic fundlementals of scripting and is the minimum any person should know before calling themselves a scriptor. Generally, it is a complete guide to get you to have a basic foundation level of scripting.
Introduction:
Basically, scripts here are very similar to the printf function in c programming. Basically, scripting is very easy and very straight forward. Every emulator have a somewhat different method of scripting, but they all have basically the same structure. For example, aegis uses 'dialog' while Athena uses 'mes'. Athena has a ; at the end of every script line while aegis doesn't. but all the scripts do the same thing. They create npc.
What are npcs?
NPCS stands for non-playing characters. I assume when you are reading this, you would know what are npcs. Basically, you must have a basic understanding of the game before venturing fourth into this part of the server.
What does npcs do?
NPCS are non-playing character that are used in instances whereby a player needs top interact with another. For example, you need npcs to make the game more challenging and even add more spice into your server.
Scripting? What's that?
Scripting is 'programming' a npc. When i say 'programming', you might wonder what i mean, scripts itself are not programming. The real codes are C++ which Athena is codded on. Scripting and coding is different. codding is referred as programming.
Is scripting hard?
Yes & no. Scripting depends on your creativity and your will to create a script. Scripting can and can not be easy. Scripting is what you can do to make your server a different place. Something, special for the players and for the public.
Now, enough of the intros, time for your first script:
++++++++++++
-0.1: Locations-
++++++++++++
Only the registered members can see the link.
basically that is the definition of the script. mapname.gat can be found by typing /where on your server. you will also get your Y co-ords and you will get your X co-ords. the directions depends.
[1][8][7]
[2][0][6]
[3][4][5]
8 being north, 4 being south. the word script and the comers must be there. with out it, the script will not work or will produce errors. the } is also important. The npc sprite number can be defined by going to Only the registered members can see the link.
+++++++++++++++
-0.2 Basic Talking-
+++++++++++++++
Only the registered members can see the link.
That is a basic talking script command. mes is a possible abbreviation of message. the "[]" is compulsory for the header because that identifies the name of the npc whom you are scripting. As said earlier, ; is very important. Without the ';' you will get script errors.
the next; command is when you want the player to click next.
finally the '}' is important because it will mark the ending of the script. finally the 'close;'. It marks the close button on your client. Isn't it easy?
++++++++++++++++
0.3 Colouring time...
++++++++++++++++
Only the registered members can see the link.
Ok, now to introduce you to colors. "[^333333NPC Name^000000]". the colors are as follows ^<Color Hex No.>. It's simple as that. If you wish to change the color back, just do ^000000. Simple as that. For a color chart, refer to this:
Refer to:
Only the registered members can see the link.
++++++++++++++++++
0.4 choices...choices....
++++++++++++++++++
Next on the agenda is menu and labels. These two have to go together. you will need at least 1 label if you intend to use 'menu'. let's look at an example.
Only the registered members can see the link.
menu "bleh",bleh; This simply means, 'menu' "<Choice A>",<Label>,"<Choice B>",<Label>;
treat label as a second layer. The choices are straight forward.
<Label>: This means, the label name or the goto point. Once it hits here, the rest of the script follows as you script it. That's it. Easy ain't it?
++++++++++++++++++
0.5 goto where?
++++++++++++++++++
The next script command you gonna learn is goto;. Look below:
Only the registered members can see the link.
yes. Basically you understand. 'goto' works the same way. goto works the same as menu. At this moment you are probably asking....."why is there such a thing. We don't need it.". On contrair my friend, you need it. It is in my next guide. Intermidiete Scripting.
++++++++++++++++++
0.6 Basic Variables
++++++++++++++++++
Similar to menu and labels, variables must go with the if command.let's look below.
Only the registered members can see the link.
As you can see, the variables are blah, yes & no.Variables yes and no will set the variable to 1 and 2 respectively. The if command will then check if the blah variable is bigger or smaller. Since my example script states that if it is bigger than 0, it will go to blah. That means, talking to the first time will ask the question, 'are you stupid'. Talking the second time will say blah. Simple?....ok, let me explain setting vars abit further.
set <var name>,<number>;
Basically, variables can change to any number but you must remember to not use 0. 0 is default and should remain as default. Simple? now to understand 'if's.
the if statement is a very powerful thing. With it, you can check what items you are holding, what levels, what job, practically everything you want to check the player uses this. Without it, you'll just die. For now, as you can see, it checks the variable. Nothing else. I'll touch item checking later.
+++++++++++++++++
0.7 Items??? Where?
+++++++++++++++++
Basically that's what you will think. heh. ok, let's talk of a scenario. You are a player named A. You want to buy a balmung. but the npc is set that only base lvl 200 can buy it. but you have no idea how to do any of this in the first place. Let me enlighten you.
Only the registered members can see the link.
as you can see above, this is an example script. It is most likely what you will find in many quests and talking shop npcs. Firstly, i must point out, the item ids, used here is 512, can be found in item_db.txt in your db folder. Ok, other than that, let's look at the script.
f (readparam(55) == 200) goto YourLevel200;
This checks if your level is 200 or not. the == sign shows that you must be level 200 and not above nor lower. it checks the player's parameter of 55, which is his base level.
if (Zeny < 1000000) goto no;
This checks if the amount of zeny the player is holding is more than or less then 1000000 or not. yes, this is where the goto statement comes in handy.
if(countitem(512)<1) goto no;
This here checks if the player is holding an apple or not. As state above, you can get the item code you want from the item db.
getitem 1161,1;
delitem 512,1;
set Zeny, Zeny-1000000;
This should be straight forward. the 'getitem' means to receive 1161(balmung) and 'delitem' which is to get rid of item. The set zeny comes in when you want to delete zeny. If you realize, the 'set zeny' looks very similar to a variable.
=====================
0.1 Variable Defined
=====================
Ok, so, you have a variable,yahoo wahha. No. Wrong. that is sometimes what you not need. Let me give you a scenario of this script.Yes, that's right, it's the ice cream script. notice the variable is @something and "+@something+" correct?
Only the registered members can see the link.
ok this comes into the first topic of the guide. let's cover variable defination.firstly,
blah
is a permenent character variable which will survive restart.
@blah
is a temporary character variable which would be destroyed at the end of the
script.
$blah
global permenent variable that won't be lost after restart.
$@blah
is a global temporary variable that will be lost after a server restart.
#blah
is a permenent character variable
#@blah
is a temporary character variable
_blah$
can save txt and numbers. It can be used with settings of any above variable.
"+blah+"
will display the variable in the messege box.
the above is the defination of the variable. if you realise, putting a @# would change a variable. so ensure you do not make the name of your variable contain that. also, the npc displayed:
mes "Here you go" +@input+ "Ice Cream for you.";
the "+___+" would make the npc display that variable. In some cases whereby you want it to do that, you can by doing that. Other than that, that's it for variables. or isit?
++++++++++++++++++++++
0.2 Variables + math!
++++++++++++++++++++++
yes, that's right. So you better love mathemathic. You can add, divide, times, multiply and subtract variables which you have set. How can this be done you ask? Let's look at this.
*
to multiply.
-
to subtract.
/
to divide.
+
to add.
!=
not equal to.
==
equal to
>=
bigger than or equal.
<=
smaller than or equal.
So, now you know that, how do i use that and where should i use it? The answer to your question is this. For example, you want to create a bank or create a limit on how many timews your npc can be used. Let's look at an example.
Only the registered members can see the link.
as you can see, the 'set Zeny,Zeny-100*@input;' makes your z= zeny - (100 x input). This is basically how scripts can be optimised to peak performance and be short and sweet. Tell me which person doesn't want to look through a short script for errors then a long one?.next, did you know variables can also be defined in that manner? for example if you want your script to set +1 everytime to your variable, you can simply do;
set limit,limit+1;
easy and facinating isn't it? IT works the same way for defining variables and the if statement tag.
+++++++++++++++++++++
NPC Duplication
+++++++++++++++++++++
user posted image
as you can see above, there are many of the diffrent locations mentioned at the bottom of the script. The word "Kriemhild" is the name in the game (under the sprite). 'p1-1' is the auxiliary name. It helps you to make several NPC with different IDs and the same title. and lastly, Kriemhild_t which is the internal (real) name of your template NPC scripts.The bottom, you should be able to identify it yourself. It's basically similar to the 'script' header.
++++++++++++++++++++++
Ontouch!
++++++++++++++++++++++
Ok, so it's time to get irritating. Ontouch was a feature added and founded by valaris. It's originally created by jathena. Valaris wondered if eAthena had it and he tried and he found out it had it already. So, enough of background stories, time for some teaching.
Only the registered members can see the link.
Ok, basically, the '<X par>' means the radius on the X axis and the '<Y par>' is the radius on the y axis. For example, i set the header to '5,5', it would make my script be activated everytime the person walks or bypasses there.
++++++++++++++++++++++
End. & Break
++++++++++++++++++++++
When you realise instances where close has no more effect for you, it's time to use either end or break. The commands are 'end;' or 'break;'. Remeber that this use of end and break should only be used in proper places and not in places everywhere in the script. LEt's look at an example.
Only the registered members can see the link.
For now, we'll ignore the loginevent line. As you can see, we want the script to be there and running in the background however the script will do nothing so, we use 'end;'. Simple to understand? Good.
++++++++++++++++++++++
Loginevent!
++++++++++++++++++++++
Yes, when you realise your npcs require players to click on them to view or on a raidus, now, it's time to learn something that will change the way you script. IT's called the pcloginevent.
Only the registered members can see the link.
it basically loads everytime a player logs in. for example;
Only the registered members can see the link.
this will make, everytime a player log in see that script and have to click
cancel. Please take note, you should only use this script type once and not many times because, the server might run a number of login event scripts at one go, it makes your server do strange bad things.
+++++++++++++++++++++++++++++++++
LEvel modifications, Resets, etc.
+++++++++++++++++++++++++++++++++
OK, so basically, we have gone this very far. From here, i recommend you understand how to do a normal npc. now, you want the npc to do actual things like modifying levels, heals and etc. Let me explain you the simpleness of this.
If you havn't discovered this on your own by looking at other scripts in your server, you should start now. That is how i personally learned scripting. Let's start by learning the job changing command. Open up your job changer script.
Only the registered members can see the link.
Ok, let's pick out the main one first,
jobchange 24;
This would make your current job change from novice or what ever you was formerly was, to 24 which is, high novice.
basically that is what you should know. The next can be found from the reset girl script.
Only the registered members can see the link.
let's look at the first one;
ResetSkill;
This would basically make the npc reset your skills and giving back your previous levels.
ResetStatus;
This here would make the npc reset your character's status and make everything back to 1.So that's about everything you should know about modifications. I'll cover the rest another time.
+++++++++++++++++++++++++++++++++++
Basic Time Gets
+++++++++++++++++++++++++++++++++++
image: Only the registered members can see the link.
The above relatively shows how the time is listed. There is barely any need to explain. For the actual script, refer to ./npc/sample/.
<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
<=<.<.<~TO Becontinued at a later time/date.~>.>.>=>
<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
------------------------------------------------------------------------------------------------------------
Credits:
-Skullbearer [For Npc Dir,]
-Cenix [Clearifying with me about ontouch]
-Valaris[For informing about ontouch]
-nsstrunks[For clearifying with me about the colours]
-Google[For helping find external webpages]
-cHa0s-Lord [For clearifying for me some checkers & alot of other things i couldn't do without him]
-eAthena [For having this great emulator]
-Lupus [For his new school style scripting/Duplicating]
-nox- [for me to post here /nges3 ]
anyway..through this guide..i can script well now /hehe and i hoped you guys can do as well.Best of my wish /buwek
This should be what you are expecting of a basic scriptor. This are the basic fundlementals of scripting and is the minimum any person should know before calling themselves a scriptor. Generally, it is a complete guide to get you to have a basic foundation level of scripting.
Introduction:
Basically, scripts here are very similar to the printf function in c programming. Basically, scripting is very easy and very straight forward. Every emulator have a somewhat different method of scripting, but they all have basically the same structure. For example, aegis uses 'dialog' while Athena uses 'mes'. Athena has a ; at the end of every script line while aegis doesn't. but all the scripts do the same thing. They create npc.
What are npcs?
NPCS stands for non-playing characters. I assume when you are reading this, you would know what are npcs. Basically, you must have a basic understanding of the game before venturing fourth into this part of the server.
What does npcs do?
NPCS are non-playing character that are used in instances whereby a player needs top interact with another. For example, you need npcs to make the game more challenging and even add more spice into your server.
Scripting? What's that?
Scripting is 'programming' a npc. When i say 'programming', you might wonder what i mean, scripts itself are not programming. The real codes are C++ which Athena is codded on. Scripting and coding is different. codding is referred as programming.
Is scripting hard?
Yes & no. Scripting depends on your creativity and your will to create a script. Scripting can and can not be easy. Scripting is what you can do to make your server a different place. Something, special for the players and for the public.
Now, enough of the intros, time for your first script:
++++++++++++
-0.1: Locations-
++++++++++++
Only the registered members can see the link.
basically that is the definition of the script. mapname.gat can be found by typing /where on your server. you will also get your Y co-ords and you will get your X co-ords. the directions depends.
[1][8][7]
[2][0][6]
[3][4][5]
8 being north, 4 being south. the word script and the comers must be there. with out it, the script will not work or will produce errors. the } is also important. The npc sprite number can be defined by going to Only the registered members can see the link.
+++++++++++++++
-0.2 Basic Talking-
+++++++++++++++
Only the registered members can see the link.
That is a basic talking script command. mes is a possible abbreviation of message. the "[]" is compulsory for the header because that identifies the name of the npc whom you are scripting. As said earlier, ; is very important. Without the ';' you will get script errors.
the next; command is when you want the player to click next.
finally the '}' is important because it will mark the ending of the script. finally the 'close;'. It marks the close button on your client. Isn't it easy?
++++++++++++++++
0.3 Colouring time...
++++++++++++++++
Only the registered members can see the link.
Ok, now to introduce you to colors. "[^333333NPC Name^000000]". the colors are as follows ^<Color Hex No.>. It's simple as that. If you wish to change the color back, just do ^000000. Simple as that. For a color chart, refer to this:
Refer to:
Only the registered members can see the link.
++++++++++++++++++
0.4 choices...choices....
++++++++++++++++++
Next on the agenda is menu and labels. These two have to go together. you will need at least 1 label if you intend to use 'menu'. let's look at an example.
Only the registered members can see the link.
menu "bleh",bleh; This simply means, 'menu' "<Choice A>",<Label>,"<Choice B>",<Label>;
treat label as a second layer. The choices are straight forward.
<Label>: This means, the label name or the goto point. Once it hits here, the rest of the script follows as you script it. That's it. Easy ain't it?
++++++++++++++++++
0.5 goto where?
++++++++++++++++++
The next script command you gonna learn is goto;. Look below:
Only the registered members can see the link.
yes. Basically you understand. 'goto' works the same way. goto works the same as menu. At this moment you are probably asking....."why is there such a thing. We don't need it.". On contrair my friend, you need it. It is in my next guide. Intermidiete Scripting.
++++++++++++++++++
0.6 Basic Variables
++++++++++++++++++
Similar to menu and labels, variables must go with the if command.let's look below.
Only the registered members can see the link.
As you can see, the variables are blah, yes & no.Variables yes and no will set the variable to 1 and 2 respectively. The if command will then check if the blah variable is bigger or smaller. Since my example script states that if it is bigger than 0, it will go to blah. That means, talking to the first time will ask the question, 'are you stupid'. Talking the second time will say blah. Simple?....ok, let me explain setting vars abit further.
set <var name>,<number>;
Basically, variables can change to any number but you must remember to not use 0. 0 is default and should remain as default. Simple? now to understand 'if's.
the if statement is a very powerful thing. With it, you can check what items you are holding, what levels, what job, practically everything you want to check the player uses this. Without it, you'll just die. For now, as you can see, it checks the variable. Nothing else. I'll touch item checking later.
+++++++++++++++++
0.7 Items??? Where?
+++++++++++++++++
Basically that's what you will think. heh. ok, let's talk of a scenario. You are a player named A. You want to buy a balmung. but the npc is set that only base lvl 200 can buy it. but you have no idea how to do any of this in the first place. Let me enlighten you.
Only the registered members can see the link.
as you can see above, this is an example script. It is most likely what you will find in many quests and talking shop npcs. Firstly, i must point out, the item ids, used here is 512, can be found in item_db.txt in your db folder. Ok, other than that, let's look at the script.
f (readparam(55) == 200) goto YourLevel200;
This checks if your level is 200 or not. the == sign shows that you must be level 200 and not above nor lower. it checks the player's parameter of 55, which is his base level.
if (Zeny < 1000000) goto no;
This checks if the amount of zeny the player is holding is more than or less then 1000000 or not. yes, this is where the goto statement comes in handy.
if(countitem(512)<1) goto no;
This here checks if the player is holding an apple or not. As state above, you can get the item code you want from the item db.
getitem 1161,1;
delitem 512,1;
set Zeny, Zeny-1000000;
This should be straight forward. the 'getitem' means to receive 1161(balmung) and 'delitem' which is to get rid of item. The set zeny comes in when you want to delete zeny. If you realize, the 'set zeny' looks very similar to a variable.
=====================
0.1 Variable Defined
=====================
Ok, so, you have a variable,yahoo wahha. No. Wrong. that is sometimes what you not need. Let me give you a scenario of this script.Yes, that's right, it's the ice cream script. notice the variable is @something and "+@something+" correct?
Only the registered members can see the link.
ok this comes into the first topic of the guide. let's cover variable defination.firstly,
blah
is a permenent character variable which will survive restart.
@blah
is a temporary character variable which would be destroyed at the end of the
script.
$blah
global permenent variable that won't be lost after restart.
$@blah
is a global temporary variable that will be lost after a server restart.
#blah
is a permenent character variable
#@blah
is a temporary character variable
_blah$
can save txt and numbers. It can be used with settings of any above variable.
"+blah+"
will display the variable in the messege box.
the above is the defination of the variable. if you realise, putting a @# would change a variable. so ensure you do not make the name of your variable contain that. also, the npc displayed:
mes "Here you go" +@input+ "Ice Cream for you.";
the "+___+" would make the npc display that variable. In some cases whereby you want it to do that, you can by doing that. Other than that, that's it for variables. or isit?
++++++++++++++++++++++
0.2 Variables + math!
++++++++++++++++++++++
yes, that's right. So you better love mathemathic. You can add, divide, times, multiply and subtract variables which you have set. How can this be done you ask? Let's look at this.
*
to multiply.
-
to subtract.
/
to divide.
+
to add.
!=
not equal to.
==
equal to
>=
bigger than or equal.
<=
smaller than or equal.
So, now you know that, how do i use that and where should i use it? The answer to your question is this. For example, you want to create a bank or create a limit on how many timews your npc can be used. Let's look at an example.
Only the registered members can see the link.
as you can see, the 'set Zeny,Zeny-100*@input;' makes your z= zeny - (100 x input). This is basically how scripts can be optimised to peak performance and be short and sweet. Tell me which person doesn't want to look through a short script for errors then a long one?.next, did you know variables can also be defined in that manner? for example if you want your script to set +1 everytime to your variable, you can simply do;
set limit,limit+1;
easy and facinating isn't it? IT works the same way for defining variables and the if statement tag.
+++++++++++++++++++++
NPC Duplication
+++++++++++++++++++++
user posted image
as you can see above, there are many of the diffrent locations mentioned at the bottom of the script. The word "Kriemhild" is the name in the game (under the sprite). 'p1-1' is the auxiliary name. It helps you to make several NPC with different IDs and the same title. and lastly, Kriemhild_t which is the internal (real) name of your template NPC scripts.The bottom, you should be able to identify it yourself. It's basically similar to the 'script' header.
++++++++++++++++++++++
Ontouch!
++++++++++++++++++++++
Ok, so it's time to get irritating. Ontouch was a feature added and founded by valaris. It's originally created by jathena. Valaris wondered if eAthena had it and he tried and he found out it had it already. So, enough of background stories, time for some teaching.
Only the registered members can see the link.
Ok, basically, the '<X par>' means the radius on the X axis and the '<Y par>' is the radius on the y axis. For example, i set the header to '5,5', it would make my script be activated everytime the person walks or bypasses there.
++++++++++++++++++++++
End. & Break
++++++++++++++++++++++
When you realise instances where close has no more effect for you, it's time to use either end or break. The commands are 'end;' or 'break;'. Remeber that this use of end and break should only be used in proper places and not in places everywhere in the script. LEt's look at an example.
Only the registered members can see the link.
For now, we'll ignore the loginevent line. As you can see, we want the script to be there and running in the background however the script will do nothing so, we use 'end;'. Simple to understand? Good.
++++++++++++++++++++++
Loginevent!
++++++++++++++++++++++
Yes, when you realise your npcs require players to click on them to view or on a raidus, now, it's time to learn something that will change the way you script. IT's called the pcloginevent.
Only the registered members can see the link.
it basically loads everytime a player logs in. for example;
Only the registered members can see the link.
this will make, everytime a player log in see that script and have to click
cancel. Please take note, you should only use this script type once and not many times because, the server might run a number of login event scripts at one go, it makes your server do strange bad things.
+++++++++++++++++++++++++++++++++
LEvel modifications, Resets, etc.
+++++++++++++++++++++++++++++++++
OK, so basically, we have gone this very far. From here, i recommend you understand how to do a normal npc. now, you want the npc to do actual things like modifying levels, heals and etc. Let me explain you the simpleness of this.
If you havn't discovered this on your own by looking at other scripts in your server, you should start now. That is how i personally learned scripting. Let's start by learning the job changing command. Open up your job changer script.
Only the registered members can see the link.
Ok, let's pick out the main one first,
jobchange 24;
This would make your current job change from novice or what ever you was formerly was, to 24 which is, high novice.
basically that is what you should know. The next can be found from the reset girl script.
Only the registered members can see the link.
let's look at the first one;
ResetSkill;
This would basically make the npc reset your skills and giving back your previous levels.
ResetStatus;
This here would make the npc reset your character's status and make everything back to 1.So that's about everything you should know about modifications. I'll cover the rest another time.
+++++++++++++++++++++++++++++++++++
Basic Time Gets
+++++++++++++++++++++++++++++++++++
image: Only the registered members can see the link.
The above relatively shows how the time is listed. There is barely any need to explain. For the actual script, refer to ./npc/sample/.
<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
<=<.<.<~TO Becontinued at a later time/date.~>.>.>=>
<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>
------------------------------------------------------------------------------------------------------------
Credits:
-Skullbearer [For Npc Dir,]
-Cenix [Clearifying with me about ontouch]
-Valaris[For informing about ontouch]
-nsstrunks[For clearifying with me about the colours]
-Google[For helping find external webpages]
-cHa0s-Lord [For clearifying for me some checkers & alot of other things i couldn't do without him]
-eAthena [For having this great emulator]
-Lupus [For his new school style scripting/Duplicating]
-nox- [for me to post here /nges3 ]
anyway..through this guide..i can script well now /hehe and i hoped you guys can do as well.Best of my wish /buwek