Latest topics
Who is online?
In total there are 4 users online :: 0 Registered, 0 Hidden and 4 Guests None
Most users ever online was 166 on Fri May 07, 2021 9:47 am
Guide to Coding
4 posters
Guide to Coding
Got this guide from a friend:
Ok, starting off, all methods in your NPC scripts are defined by a source file called NPCConversationManager in your net.sf.odinms.scripting.npc package, or it might be in AbstractPlayerInteraction (the class is not an abstract class) which has methods that are universal or all scripting, meaning if you put a method in there, you can use it in ANY script.
For exmaple, if I put a method like this
The thing in the paranthesis after the declaration of the method is called a parameter, something you have to provide when using the method. You may put a method with no parameter if you dont need any parameters.
The basic NPC Script
You will need to start the NPC script with variable, status, which is used in any NPC that is properly scripted to keep it from flooding everything at once.
So at the top of your script, add
All NPCs that are properly scripted have two functions start and action.
Usually, in the start function, all that is set is the status and action.
You should always set the status to -1 unless you're making a weird-ass NPC and action doesnt matter right now, most of the time it should be (1, 0, 0)
So your start function should look like this
So to use this method, you would look at the parameter, which is an integer value, so you would have to fill in an integer value for the parameter and use the method like this: cm.openShop(INTVALUEHERE).
Usually the name of the parameter should give you an idea what it is, like int shopid should give you a clue that the parameter is the shopId.
If there is nothing in the paranthesis, that means that you dont need to add anything in the paranthesis, such as getJob, you do not need a parameter for that so you can just use it as cm.getJob();
NOTE: Captilization matters, openSHOP isn't the same as openShop.
When you use a method, you need to add a ; after all of them Ex: cm.sendOk("Hi");
You miss the semicolon and it wont work.
Some of the most commonly used methods are listed
First you have to start your action function which should be like this
if (mode = -1) happens if the mode is negative 1, which in that case the NPC does nothing.
if (mode == 1) status++;, this increments status by 1 if the mode is 1, which allows you to use status correctly and code your NPC.
But before we get started on coding your body, I have to explain if, else, and else if statements which are very basic.
If statements are used like this
If the boolean in paranthesis returns true, the BLAHBLAHBLAH gets execute (put whatever you want there, such as cm.sendOk("Whatever") if not, it executes the else, simple right?
Now how you work this with status is that everytime your NPC does something, the status is incremented, so simply code your NPC like this.
Note: anything with // in front of it is a comment, which is completely ignored when the NPC is executed
What's different about coding NPCs is the body, there are many methods in your NPCConversationManager, and you can even add your own, I suggest you first start out reading NPCConversationManager and make sure you understand what all the methods in there do, this will help you when you want to code NPCs that do more than sit and talk, because that isn't very useful
A helpful programs for coding:
Here
And pics to help explain it:
Here
Ok, starting off, all methods in your NPC scripts are defined by a source file called NPCConversationManager in your net.sf.odinms.scripting.npc package, or it might be in AbstractPlayerInteraction (the class is not an abstract class) which has methods that are universal or all scripting, meaning if you put a method in there, you can use it in ANY script.
For exmaple, if I put a method like this
- Code:
public void setHp(int newhp) {
c.getPlayer().setHp(newHp);
}
The thing in the paranthesis after the declaration of the method is called a parameter, something you have to provide when using the method. You may put a method with no parameter if you dont need any parameters.
The basic NPC Script
You will need to start the NPC script with variable, status, which is used in any NPC that is properly scripted to keep it from flooding everything at once.
So at the top of your script, add
- Code:
var status = 0;
All NPCs that are properly scripted have two functions start and action.
Usually, in the start function, all that is set is the status and action.
You should always set the status to -1 unless you're making a weird-ass NPC and action doesnt matter right now, most of the time it should be (1, 0, 0)
So your start function should look like this
- Code:
function start() {
status = -1;
action(1, 0, 0);
}
So to use this method, you would look at the parameter, which is an integer value, so you would have to fill in an integer value for the parameter and use the method like this: cm.openShop(INTVALUEHERE).
Usually the name of the parameter should give you an idea what it is, like int shopid should give you a clue that the parameter is the shopId.
If there is nothing in the paranthesis, that means that you dont need to add anything in the paranthesis, such as getJob, you do not need a parameter for that so you can just use it as cm.getJob();
NOTE: Captilization matters, openSHOP isn't the same as openShop.
When you use a method, you need to add a ; after all of them Ex: cm.sendOk("Hi");
You miss the semicolon and it wont work.
Some of the most commonly used methods are listed
- Code:
cm.sendOk(String text) : Sends a box with the text in the paranthesis (Note: All strings must have "Quotes" around them
cm.sendNext(String text) : Like sendok except with a next button
cm.sendNextPrev (String text): Like sendNext except with a next and a previous button
cm.openShop(int shopid): Opens the shop with the specified ID
cm.getPlayer() : This is a huge one, it lets you access most of the methods in the 2nd biggest file in your OdinMS folder (unless yours is really fucked up), MapleCharacter, but it simply gets the object of the player, and you can apply maplecharacter methods here such as saveToDb and other important ones, you will use this A LOT.
cm.dispose(): disposes the NPC, ends the instance, whatever, use this when you want the NPC box to close, you should always add this method to the end of your NPC scripts, or the player will have to relog after using the NPC to talk to another NPC.
Too lazy to add the rest, just read your NPCConversationManager
First you have to start your action function which should be like this
- Code:
function action(mode, type, selection) { //close this bracket when the NPC ends
- Code:
if (mode == -1) {
cm.dispose();
} else {
if (mode == 0 && status == 0) {
cm.dispose();
return;
}
if (mode == 1)
status++;
else
status--;
if (mode = -1) happens if the mode is negative 1, which in that case the NPC does nothing.
if (mode == 1) status++;, this increments status by 1 if the mode is 1, which allows you to use status correctly and code your NPC.
But before we get started on coding your body, I have to explain if, else, and else if statements which are very basic.
If statements are used like this
- Code:
if (BOOLEAN GOES HERE) {
BLAHBLAHBLAH;
} else {
BLAHBLAH
}
If the boolean in paranthesis returns true, the BLAHBLAHBLAH gets execute (put whatever you want there, such as cm.sendOk("Whatever") if not, it executes the else, simple right?
Now how you work this with status is that everytime your NPC does something, the status is incremented, so simply code your NPC like this.
- Code:
if (status == 1) {
whateveryouwanttodohere;
} else if (status ==2) {
blahblah;
}else if (status == 3) {
hhhhhh;
}
and so on......
Note: anything with // in front of it is a comment, which is completely ignored when the NPC is executed
- Code:
//This only includes the action part of the action that makes the NPC do stuff
if (status == 1) {
cm.sendOk("Hi, would you like a brownie?");
} else if (status == 2) {
cm.sendOk("Well too bad, you're a fag and you're not getting one.");
}
- Code:
var status = 0; //status
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
} else {
if (mode == 0 && status == 0) {
cm.dispose();
return;
}
if (mode == 1)
status++;
else
status--;
//This only includes the action part of the action that makes the NPC do stuff
if (status == 1) {
cm.sendOk("Hi, would you like a brownie?");
} else if (status == 2) {
cm.sendOk("Well too bad, you're a fag and you're not getting one.");
cm.dispose(); //ends the NPC and exits window
}
} //closes the action function
What's different about coding NPCs is the body, there are many methods in your NPCConversationManager, and you can even add your own, I suggest you first start out reading NPCConversationManager and make sure you understand what all the methods in there do, this will help you when you want to code NPCs that do more than sit and talk, because that isn't very useful
A helpful programs for coding:
Here
And pics to help explain it:
Here
Last edited by Fizzle on Sun Feb 22, 2009 1:42 pm; edited 1 time in total
Re: Guide to Coding
btw, do u have a tutorial on how to learn java? not just creating npc's. Like the language and what each of those term mean
wondertwins- Member
- Posts : 30
Join date : 2009-02-19
Re: Guide to Coding
kevin why didnt u just edit ur first post instead of double posting. anywase i think im not gonna bother coding lmao.
mandu- New Member
- Posts : 21
Join date : 2009-02-19
Re: Guide to Coding
mandu wrote:kevin why didnt u just edit ur first post instead of double posting. anywase i think im not gonna bother coding lmao.
lmao nice, is it too long for u o.0
Re: Guide to Coding
no i just remembered how coding was such a drag for me lmao
mandu- New Member
- Posts : 21
Join date : 2009-02-19
Re: Guide to Coding
mandu wrote:no i just remembered how coding was such a drag for me lmao
do u have like books on Java or something?
wondertwins- Member
- Posts : 30
Join date : 2009-02-19
Re: Guide to Coding
nope o.o. you kno i think theres some people willing to help u if u just search the internet.
mandu- New Member
- Posts : 21
Join date : 2009-02-19
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Sun Jun 15, 2014 4:08 pm by mykmark
» ClearLock V1.4.0-Lock Screen With Password Protection[ak]
Sun Jun 15, 2014 3:21 pm by mykmark
» Hay Day Hack Tool V 1.8.rar Mediafire
Sun Jun 15, 2014 2:29 pm by mykmark
» Teaching Community Hooks, Bell||
Sun Jun 15, 2014 2:26 pm by mykmark
» Teaching Community Hooks, Bell||
Sun Jun 15, 2014 2:25 pm by mykmark
» Teaching Community Hooks, Bell||
Sun Jun 15, 2014 2:25 pm by mykmark
» Manga Studio 5 Download
Sun Jun 15, 2014 1:48 pm by mykmark
» Stargate Universe Saison 3 Hacker Streaming
Sun Jun 15, 2014 1:24 pm by mykmark
» GraphicRiver Colourful Win 8 Business Card
Sun Jun 15, 2014 6:52 am by mykmark