Hello. I tought of releasing this tut to you because it seems that there is no such in this forum.
Please tell me if there is one already.
Please tell me if there is one already.
Do you ever wanted to script your own NPC?
Did you fail?
Well take a look at this TuT!
Did you fail?
Well take a look at this TuT!
Tutorial 1 [The base of a NPC scripting]
Tutorial 2 [How to fix the NPC if you got a problem with it]
Tutorial 3 [The NPC commands]
Tutorial 4 [The Text commands]
Nice JavaScript Editors
Tutorial 2 [How to fix the NPC if you got a problem with it]
Tutorial 3 [The NPC commands]
Tutorial 4 [The Text commands]
Nice JavaScript Editors
TUTORIAL 1 [The basics of NPC scripting]
So you want to learn the basics?
Okay! Here we go.
We will make a simple NPC and teach you on the way.
To begin with. You should download a JavaScript editor below at the Javascript editor downloads.
When you have done that, you are ready to start!
Open the program. Go to file and open and then go to your servers main folder and then you go to scripts folder--> NPC folder. If you dont know how to do that, then you should not have a private server at all because its just to go to the NPC folder inside scripts folder in your Server folder. Ok?
When you have got that far, choose a npc to edit.
Click open (remember we are still using the script editor!).
Now, (if you haven't made an new empty NPCID.js) it should get up some weird text.
(It may look weird to you if you are a beginner at this)
Do not panic.(Lol)
All you have to do is to delete the text. (Hotkey - CTRL + A and then delete)
Now you can start scripting!
To begin with, type this at the top:
Explanation:
This is the variable to the status that we will get into later. I added a = 0 because I want the script to start at status 0. If you want to add a new variable you always have to make a var [Name]; at the top or the variable might not work.
When you have added that script, your first variable is set. Under this variable, you can set more variables.
That depends on what you will use them for but we will go into that later.
Now, you have to add the string that actually makes your NPC work.
Explanation:
This makes the script actually work. You may notice that because of the function_start(). This has to be included in every npc script you are making.
Now you can go in game and talk to your NPC!... JOKES! The npc is not done yet..
Now you will have to add a string for the ACTIONS to work. Still, the above string is the base of the script. Did you notice that action(1, 0, 0);
? Well I did.
What do that variable do? We will come into that now.
Add this string to the script:
Explanation:
This is taking care of the actions that we will come to in a moment. There are three variables. Mode, Type, Selection.
Now we can add our modes.
Explanation:
The mode variable, actually takes care of if you have clicked End Chat or finished talking to a NPC. The mode == -1 checks if you have clicked a negative button like, No. The mode == 0 and status == 1 checks the status assigned for choices. The status == 1 should be changed if you have a question in another status. We will not talk about that cm.sendOK in this tut. Please check out Tutorial 3 if you want to knwo about it.
There is ONE more mode that we will add.. It is the one that checks if we did go backwards or forwards in the script.
[code] if (mode == 1)
status++;
else
status--;[/CODE]
Explanation:
You should now knwo about what the modes do. Yes, they take care of the status's actions. Now lets explain what the status++; actually does. Did you remember the status == -1; variable under function_start()? Now you may have noticed what I mean? It is actually adding +1 when you are going to next window(in-game)/status(in-script). The status--; is subtracting -1 when you are going to previous window(in-game)/status(in-script).
Now are we done? The answer is both no and yes. If you want the npc to not say anything, yes. If you want the npc to actually do anything, no. The script will wonder "Hey! What to do with the statuses then? It's useless!". It isn't useless if you add this if statement:
Explanation:
This is a npc window(in-game)/status(in-script). If you are gonna add more statuses, You wil?l have to add +1 to the number all the time. For example: If you have status ==1, and want to add a new status, that status will have to be status == 2. But it won't do anything if you leave without the commands (Tutorial 3).
Now you have your first NPC window! Gratz! Now we will add a simple cm.sendNext(""); into it.
Youn will find explanation at Tutorial 3.
Now we will add a new status. This time it has to be "else" because if its not status 0 = if the mode added +1 to the variable "status" it will be 1.
You won't need a explanation for this. The explanation is in the status == 0 explanation.So you want to learn the basics?
Okay! Here we go.
We will make a simple NPC and teach you on the way.
To begin with. You should download a JavaScript editor below at the Javascript editor downloads.
When you have done that, you are ready to start!
Open the program. Go to file and open and then go to your servers main folder and then you go to scripts folder--> NPC folder. If you dont know how to do that, then you should not have a private server at all because its just to go to the NPC folder inside scripts folder in your Server folder. Ok?
When you have got that far, choose a npc to edit.
Click open (remember we are still using the script editor!).
Now, (if you haven't made an new empty NPCID.js) it should get up some weird text.
(It may look weird to you if you are a beginner at this)
Do not panic.(Lol)
All you have to do is to delete the text. (Hotkey - CTRL + A and then delete)
Now you can start scripting!
To begin with, type this at the top:
Code:
[COLOR="purple"]var status = 0;[/COLOR]
This is the variable to the status that we will get into later. I added a = 0 because I want the script to start at status 0. If you want to add a new variable you always have to make a var [Name]; at the top or the variable might not work.
When you have added that script, your first variable is set. Under this variable, you can set more variables.
That depends on what you will use them for but we will go into that later.
Now, you have to add the string that actually makes your NPC work.
Code:
[COLOR="Purple"]function start() {
status = -1;
action(1, 0, 0);
}[/COLOR]
This makes the script actually work. You may notice that because of the function_start(). This has to be included in every npc script you are making.
Now you can go in game and talk to your NPC!... JOKES! The npc is not done yet..
Now you will have to add a string for the ACTIONS to work. Still, the above string is the base of the script. Did you notice that action(1, 0, 0);
? Well I did.
What do that variable do? We will come into that now.
Add this string to the script:
Code:
[COLOR="Purple"]function action(mode, type, selection) { [/COLOR]
This is taking care of the actions that we will come to in a moment. There are three variables. Mode, Type, Selection.
Now we can add our modes.
Code:
[COLOR="Purple"]if (mode == -1)
cm.sendOk("Goodbye then!");
cm.dispose();
else {
if (mode == 0 && status == 1) {
cm.dispose();
return;
} [/COLOR]
The mode variable, actually takes care of if you have clicked End Chat or finished talking to a NPC. The mode == -1 checks if you have clicked a negative button like, No. The mode == 0 and status == 1 checks the status assigned for choices. The status == 1 should be changed if you have a question in another status. We will not talk about that cm.sendOK in this tut. Please check out Tutorial 3 if you want to knwo about it.
There is ONE more mode that we will add.. It is the one that checks if we did go backwards or forwards in the script.
[code] if (mode == 1)
status++;
else
status--;[/CODE]
Explanation:
You should now knwo about what the modes do. Yes, they take care of the status's actions. Now lets explain what the status++; actually does. Did you remember the status == -1; variable under function_start()? Now you may have noticed what I mean? It is actually adding +1 when you are going to next window(in-game)/status(in-script). The status--; is subtracting -1 when you are going to previous window(in-game)/status(in-script).
Now are we done? The answer is both no and yes. If you want the npc to not say anything, yes. If you want the npc to actually do anything, no. The script will wonder "Hey! What to do with the statuses then? It's useless!". It isn't useless if you add this if statement:
Code:
[COLOR="Purple"] if (status == 0) { [/COLOR]
This is a npc window(in-game)/status(in-script). If you are gonna add more statuses, You wil?l have to add +1 to the number all the time. For example: If you have status ==1, and want to add a new status, that status will have to be status == 2. But it won't do anything if you leave without the commands (Tutorial 3).
Now you have your first NPC window! Gratz! Now we will add a simple cm.sendNext(""); into it.
Code:
[COLOR="Purple"] cm.sendNext("Hello there! My name is Henki! I want to teach you how to script NPCs!"); [/COLOR]
Now we will add a new status. This time it has to be "else" because if its not status 0 = if the mode added +1 to the variable "status" it will be 1.
Code:
[COLOR="purple"] } else if (status == 1) { [/COLOR]
Now we will make the player choose between two choices.
[code] cm.sendSimple("So, why are you talking to me? \r\n #L0##bI want to learn NPC scripting#k#l /r/n #L1##bNevermind#k#l");[/CODE]
Tutorial 3/4 for explanation.
Now we will add the 3rd status
[CODE] } else if (status == 2) {[/CODE]
Same as status == 0/1
Now I'm gonna explain some of the cm.sendSimple. The L0 and L1 you see, is selection text commands and for them to take you somewhere when you click one, we have to add selections.
Code:
[COLOR="purple"] if (selection == 0) { [/COLOR]
When you have clicked a selection at the sendSimple, you will be taken to this strings. the selections L0 = selection == 0, L1 = selection == 1 and so on..
Now when we click the first choice, we will be taken to selection 0. But now we will make that one do something.
Code:
[COLOR="Purple"] cm.sendOk("Then you have to go to ******** and find my tutorial. Cya in ********!"); [/COLOR]
Now we want to add a selection for the second choice.
Code:
[COLOR="purple"] } else if (selection == 1) { [/COLOR]
Code:
[COLOR="purple"] cm.dispose();[/COLOR]
Now we will add some end branches and another dispose and were done!
This is the final result:
Code:
[COLOR="Purple"]var status = 0;
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
} else {
if (mode == 0 && status == 1) {
cm.dispose();
return;
}
if (mode == 1)
status++;
else
status--;
if (status == 0) {
cm.sendNext("Hello there! My name is Henki! I want to teach you how to script NPCs!");
} else if (status == 1) {
cm.sendSimple("So, why are you talking to me? \r\n #L0##bI want to learn NPC scripting#k#l \r\n #L1##bNevermind#k#l");
} else if (status == 2) {
if (selection == 0) {
cm.sendOk("Then you have to go to ******** and find my tutorial. Cya in ********!");
} else if (selection == 1) {
cm.dispose();
}
}
}
} [/COLOR]
Im sorry but the rest is in the 2 post from me
Credits goes to






