Need help with this npc code.....
Well, today I made an npc script for a maplestory private server..... but, something went wrong. I've done coding before and I'm kinda sure what the problem is.... I just don't know how to fix it and make the npc still do what I want. Here is the script:
var status = 0;
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
}
else {
if (status >= 0 && mode == 0) {
cm.sendOk("See you next time!");
cm.dispose();
return;
}
if (mode == 1) {
status++;
}
else {
status--;
}
if (status == 0) {
if(cm.haveItem(1142009, 1) && cm.haveItem(4000029, 1000) && cm.haveItem(4031453, 100) && cm.haveItem(4031737, 1) && cm.getLevel() >=10) {
cm.gainItem(4000029, -1000);
cm.gainItem(4031453, -100);
cm.gainItem(4031737, -1);
cm.gainItem(1102094, 1);
cm.sendNext("Wow that was fast! Thank you so much! All you really had to do was defeat the Ape Saiyan who was being controlled by evil spirit and bring me back his blood..... I just wanted the bananas because I was really hungry.");
cm.dispose();
}
}
else {
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
else if (status == 1) {
if(cm.haveItem(1142009, 1) && cm.getLevel() >=10) {
cm.sendNext("Hmmm, you look strong enough for sure! Well, my secret is that there is a way to gain the power of the Saiyan race without being born as one!");
}
else {
cm.sendNext("Actually, nevermind..... you seem a bit weak at the moment. Come back when you can prove your power level is at least 9000 and that you've got the power of at least 10 humans!");
cm.dispose();
}
}
else if (status == 2) {
cm.sendNext("See my tail? It gives me incredible power! Usually you would need to be born as a Saiyan to get a tail like me, but I know a way for you to grow one too!");
}
else if (status == 3) {
cm.sendNext("All you have to do is bring me 1000 bananas which can be found by killing some monkeys in the forest, and Saiyan's Blood which can be found by killing the Ape Saiyan who is being controlled by an evil spirit.");
}
else if (status == 4) {
cm.sendOk("Once you have all the stuff, come back to me and I'll make you an official Saiyan!");
cm.dispose();
}
}
}
Thanks for any help you can give. :>
Re: Need help with this npc code.....
Re: Need help with this npc code.....
belongs in the MapleStory help section.
Re: Need help with this npc code.....
Quote:
Originally Posted by
alphaest
very messy to read...
Code:
var status = 0;
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
}
else {
if (status >= 0 && mode == 0) {
cm.sendOk("See you next time!");
cm.dispose();
return;
}
if (mode == 1) {
status++;
}
else {
status--;
}
if (status == 0) {
if(cm.haveItem(1142009, 1) && cm.haveItem(4000029, 1000) && cm.haveItem(4031453, 100) && cm.haveItem(4031737, 1) && cm.getLevel() >=10) {
cm.gainItem(4000029, -1000);
cm.gainItem(4031453, -100);
cm.gainItem(4031737, -1);
cm.gainItem(1102094, 1);
cm.sendNext("Wow that was fast! Thank you so much! All you really had to do was defeat the Ape Saiyan who was being controlled by evil spirit and bring me back his blood..... I just wanted the bananas because I was really hungry.");
cm.dispose();
}
}
else {
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
else if (status == 1) {
if(cm.haveItem(1142009, 1) && cm.getLevel() >=10) {
cm.sendNext("Hmmm, you look strong enough for sure! Well, my secret is that there is a way to gain the power of the Saiyan race without being born as one!");
}
else {
cm.sendNext("Actually, nevermind..... you seem a bit weak at the moment. Come back when you can prove your power level is at least 9000 and that you've got the power of at least 10 humans!");
cm.dispose();
}
}
else if (status == 2) {
cm.sendNext("See my tail? It gives me incredible power! Usually you would need to be born as a Saiyan to get a tail like me, but I know a way for you to grow one too!");
}
else if (status == 3) {
cm.sendNext("All you have to do is bring me 1000 bananas which can be found by killing some monkeys in the forest, and Saiyan's Blood which can be found by killing the Ape Saiyan who is being controlled by an evil spirit.");
}
else if (status == 4) {
cm.sendOk("Once you have all the stuff, come back to me and I'll make you an official Saiyan!");
cm.dispose();
}
}
}
As said before, else is after any else if's
Wouldn't work because the cm.sendNext has a cm.dispose after it, which would end the NPC after that window. Also, your brackets are not aligned properly. All status brackets should connect with each other. This means, the opening bracket for Status 0 should "connect" with the closing bracket on the same line as Status 1. Let me point it out better...
Code:
if (status == 0) {
if(cm.haveItem(1142009, 1) && cm.haveItem(4000029, 1000) && cm.haveItem(4031453, 100) && cm.haveItem(4031737, 1) && cm.getLevel() >=10) {
cm.gainItem(4000029, -1000);
cm.gainItem(4031453, -100);
cm.gainItem(4031737, -1);
cm.gainItem(1102094, 1);
cm.sendNext("Wow that was fast! Thank you so much! All you really had to do was defeat the Ape Saiyan who was being controlled by evil spirit and bring me back his blood..... I just wanted the bananas because I was really hungry.");
cm.dispose();
} // This is the extra bracket that ruins the NPC
}else {
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
else if (status == 1) {
The red is currently what's lined up, and how it's wrong. This is how it should be.
Code:
if (status == 0) {
if(cm.haveItem(1142009, 1) && cm.haveItem(4000029, 1000) && cm.haveItem(4031453, 100) && cm.haveItem(4031737, 1) && cm.getLevel() >=10) {
cm.gainItem(4000029, -1000);
cm.gainItem(4031453, -100);
cm.gainItem(4031737, -1);
cm.gainItem(1102094, 1);
cm.sendNext("Wow that was fast! Thank you so much! All you really had to do was defeat the Ape Saiyan who was being controlled by evil spirit and bring me back his blood..... I just wanted the bananas because I was really hungry.");
cm.dispose();
}else {
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
} else if (status == 1) {
@On Topic: This should be in the MapleStory section, but here...
PHP Code:
status = 0;
function start() {
if (cm.haveItem(1142009, 1) && cm.haveItem(4000029, 1000) && cm.haveItem(4031453, 100) && cm.haveItem(4031737, 1) && cm.getLevel() >=10) {
cm.gainItem(4000029, -1000);
cm.gainItem(4031453, -100);
cm.gainItem(4031737, -1);
cm.gainItem(1102094, 1);
cm.sendNext("Wow that was fast! Thank you so much! All you really had to do was defeat the Ape Saiyan who was being controlled by evil spirit and bring me back his blood..... I just wanted the bananas because I was really hungry.");
}else{
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
}
function action(mode, type, selection) {
if (mode > 0)
status++;
else {
cm.sendOk("See you next time!");
cm.dispose();
return;
}
if (status == 1) {
cm.sendNext("Hmmm, you look strong enough for sure! Well, my secret is that there is a way to gain the power of the Saiyan race without being born as one!");
else{
cm.sendOk("Actually, nevermind..... you seem a bit weak at the moment. Come back when you can prove your power level is at least 9000 and that you've got the power of at least 10 humans!");
cm.dispose();
}
} else if (status == 2) {
cm.sendNext("See my tail? It gives me incredible power! Usually you would need to be born as a Saiyan to get a tail like me, but I know a way for you to grow one too!");
} else if (status == 3) {
cm.sendNext("All you have to do is bring me 1000 bananas which can be found by killing some monkeys in the forest, and Saiyan's Blood which can be found by killing the Ape Saiyan who is being controlled by an evil spirit.");
} else if (status == 4) {
cm.sendOk("Once you have all the stuff, come back to me and I'll make you an official Saiyan!");
cm.dispose();
}
}
Re: Need help with this npc code.....
Also, use proper indentation in your code. It makes it much more readable 'cause now it's a maze for finding if you correctly put all brackets where they should be.
Re: Need help with this npc code.....
Code:
else {
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
else if (status == 1) {
This should not work, obviously if there are else if's, the plain else part should be the last in the chain.
Re: Need help with this npc code.....
very messy to read...
Code:
var status = 0;
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
}
else {
if (status >= 0 && mode == 0) {
cm.sendOk("See you next time!");
cm.dispose();
return;
}
if (mode == 1) {
status++;
}
else {
status--;
}
if (status == 0) {
if(cm.haveItem(1142009, 1) && cm.haveItem(4000029, 1000) && cm.haveItem(4031453, 100) && cm.haveItem(4031737, 1) && cm.getLevel() >=10) {
cm.gainItem(4000029, -1000);
cm.gainItem(4031453, -100);
cm.gainItem(4031737, -1);
cm.gainItem(1102094, 1);
cm.sendNext("Wow that was fast! Thank you so much! All you really had to do was defeat the Ape Saiyan who was being controlled by evil spirit and bring me back his blood..... I just wanted the bananas because I was really hungry.");
cm.dispose();
}
}
else {
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
else if (status == 1) {
if(cm.haveItem(1142009, 1) && cm.getLevel() >=10) {
cm.sendNext("Hmmm, you look strong enough for sure! Well, my secret is that there is a way to gain the power of the Saiyan race without being born as one!");
}
else {
cm.sendNext("Actually, nevermind..... you seem a bit weak at the moment. Come back when you can prove your power level is at least 9000 and that you've got the power of at least 10 humans!");
cm.dispose();
}
}
else if (status == 2) {
cm.sendNext("See my tail? It gives me incredible power! Usually you would need to be born as a Saiyan to get a tail like me, but I know a way for you to grow one too!");
}
else if (status == 3) {
cm.sendNext("All you have to do is bring me 1000 bananas which can be found by killing some monkeys in the forest, and Saiyan's Blood which can be found by killing the Ape Saiyan who is being controlled by an evil spirit.");
}
else if (status == 4) {
cm.sendOk("Once you have all the stuff, come back to me and I'll make you an official Saiyan!");
cm.dispose();
}
}
}
As said before, else is after any else if's
Re: Need help with this npc code.....
Quote:
Originally Posted by
alphaest
very messy to read...
Code:
var status = 0;
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
}
else {
if (status >= 0 && mode == 0) {
cm.sendOk("See you next time!");
cm.dispose();
return;
}
if (mode == 1) {
status++;
}
else {
status--;
}
if (status == 0) {
if(cm.haveItem(1142009, 1) && cm.haveItem(4000029, 1000) && cm.haveItem(4031453, 100) && cm.haveItem(4031737, 1) && cm.getLevel() >=10) {
cm.gainItem(4000029, -1000);
cm.gainItem(4031453, -100);
cm.gainItem(4031737, -1);
cm.gainItem(1102094, 1);
cm.sendNext("Wow that was fast! Thank you so much! All you really had to do was defeat the Ape Saiyan who was being controlled by evil spirit and bring me back his blood..... I just wanted the bananas because I was really hungry.");
cm.dispose();
}
}
else {
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
else if (status == 1) {
if(cm.haveItem(1142009, 1) && cm.getLevel() >=10) {
cm.sendNext("Hmmm, you look strong enough for sure! Well, my secret is that there is a way to gain the power of the Saiyan race without being born as one!");
}
else {
cm.sendNext("Actually, nevermind..... you seem a bit weak at the moment. Come back when you can prove your power level is at least 9000 and that you've got the power of at least 10 humans!");
cm.dispose();
}
}
else if (status == 2) {
cm.sendNext("See my tail? It gives me incredible power! Usually you would need to be born as a Saiyan to get a tail like me, but I know a way for you to grow one too!");
}
else if (status == 3) {
cm.sendNext("All you have to do is bring me 1000 bananas which can be found by killing some monkeys in the forest, and Saiyan's Blood which can be found by killing the Ape Saiyan who is being controlled by an evil spirit.");
}
else if (status == 4) {
cm.sendOk("Once you have all the stuff, come back to me and I'll make you an official Saiyan!");
cm.dispose();
}
}
}
As said before, else is after any else if's
Haha, much better, PM me, I might need you.
Quote:
Originally Posted by
holthelper
belongs in the MapleStory help section.
qft?
Re: Need help with this npc code.....
Quote:
Originally Posted by
CioNide
...I might need you..
don't think so.
Here's the fixed code that should work if you didn't fix it yet (well atleast there shouldn't be any more compile errors) :
Code:
var status = 0;
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
}
else {
if (status >= 0 && mode == 0) {
cm.sendOk("See you next time!");
cm.dispose();
return;
}
if (mode == 1) {
status++;
}
else {
status--;
}
if (status == 0) {
if(cm.haveItem(1142009, 1) && cm.haveItem(4000029, 1000) && cm.haveItem(4031453, 100) && cm.haveItem(4031737, 1) && cm.getLevel() >=10) {
cm.gainItem(4000029, -1000);
cm.gainItem(4031453, -100);
cm.gainItem(4031737, -1);
cm.gainItem(1102094, 1);
cm.sendNext("Wow that was fast! Thank you so much! All you really had to do was defeat the Ape Saiyan who was being controlled by evil spirit and bring me back his blood..... I just wanted the bananas because I was really hungry.");
cm.dispose();
}
}
else if (status == 1) {
if(cm.haveItem(1142009, 1) && cm.getLevel() >=10) {
cm.sendNext("Hmmm, you look strong enough for sure! Well, my secret is that there is a way to gain the power of the Saiyan race without being born as one!");
}
else {
cm.sendNext("Actually, nevermind..... you seem a bit weak at the moment. Come back when you can prove your power level is at least 9000 and that you've got the power of at least 10 humans!");
cm.dispose();
}
}
else if (status == 2) {
cm.sendNext("See my tail? It gives me incredible power! Usually you would need to be born as a Saiyan to get a tail like me, but I know a way for you to grow one too!");
}
else if (status == 3) {
cm.sendNext("All you have to do is bring me 1000 bananas which can be found by killing some monkeys in the forest, and Saiyan's Blood which can be found by killing the Ape Saiyan who is being controlled by an evil spirit.");
}
else if (status == 4) {
cm.sendOk("Once you have all the stuff, come back to me and I'll make you an official Saiyan!");
cm.dispose();
}
else {
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
}
}
Re: Need help with this npc code.....
Quote:
Originally Posted by
alphaest
don't think so.
Here's the fixed code that should work if you didn't fix it yet (well atleast there shouldn't be any more compile errors) :
Code:
var status = 0;
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
}
else {
if (status >= 0 && mode == 0) {
cm.sendOk("See you next time!");
cm.dispose();
return;
}
if (mode == 1) {
status++;
}
else {
status--;
}
if (status == 0) {
if(cm.haveItem(1142009, 1) && cm.haveItem(4000029, 1000) && cm.haveItem(4031453, 100) && cm.haveItem(4031737, 1) && cm.getLevel() >=10) {
cm.gainItem(4000029, -1000);
cm.gainItem(4031453, -100);
cm.gainItem(4031737, -1);
cm.gainItem(1102094, 1);
cm.sendNext("Wow that was fast! Thank you so much! All you really had to do was defeat the Ape Saiyan who was being controlled by evil spirit and bring me back his blood..... I just wanted the bananas because I was really hungry.");
cm.dispose();
}
}
else if (status == 1) {
if(cm.haveItem(1142009, 1) && cm.getLevel() >=10) {
cm.sendNext("Hmmm, you look strong enough for sure! Well, my secret is that there is a way to gain the power of the Saiyan race without being born as one!");
}
else {
cm.sendNext("Actually, nevermind..... you seem a bit weak at the moment. Come back when you can prove your power level is at least 9000 and that you've got the power of at least 10 humans!");
cm.dispose();
}
}
else if (status == 2) {
cm.sendNext("See my tail? It gives me incredible power! Usually you would need to be born as a Saiyan to get a tail like me, but I know a way for you to grow one too!");
}
else if (status == 3) {
cm.sendNext("All you have to do is bring me 1000 bananas which can be found by killing some monkeys in the forest, and Saiyan's Blood which can be found by killing the Ape Saiyan who is being controlled by an evil spirit.");
}
else if (status == 4) {
cm.sendOk("Once you have all the stuff, come back to me and I'll make you an official Saiyan!");
cm.dispose();
}
else {
cm.sendNext("Pssssst! I know a cool secret that you might be interested in!");
}
}
}
var status = 0;
No. Refer to my post previous please.
Re: Need help with this npc code.....
reading your code then it seems this isnt a usual C-style syntax. In that case, nevermind me ;)
I got no idea what maplestory uses.
Re: Need help with this npc code.....
Quote:
Originally Posted by
alphaest
reading your code then it seems this isnt a usual C-style syntax. In that case, nevermind me ;)
I got no idea what maplestory uses.
Most sources are Java based. The off one, like Titan and Vana, are coded in other languages like C++ and I think C#. Regardless, This NPC, along with any other from a Java based source/repack, uses JavaScript, which like any other language, does not require brackets or statements to be on separate lines. The NPC can be on one line if the creator feels like doing so, but it's be a huge hassle trying to edit or read it. Most scripters/coders place brackets on separate lines because it's easier for them to read/understand. I find it more organized to keep the closing bracket to the previous actions on the same line as the else which will start or open the next set of actions.
PHP Code:
}else{
rather than
}
else {
cm.dispose(); ends the conversation. It basically wipes everything clean. It sets the players mode to 0 so they can talk to NPCs again. By having a cm.dispose(); in the same status (under the cm.sendNext) as the cm.sendNext, you are stopping the NPC from advancing to the next status i.e. when Next is clicked. The way I coded it is, to me, easier to read.
If you are ever interested, although I can understand why you wouldn't be, you should check out my tutorial on NPCs. It's pretty thorough and will soon be updated with more information on how to do things better.
http://forum.ragezone.com/f428/learn...finish-643364/