-
Re: [Tut] Learning NPC scripts (beginner's guide)
SHAWN GET ON MSN
Code:
function start() {
cm.sendYesNo("I can make you a Female... LOL. Are you ready? (Remember THAT you need to Change Channel, That Way the Sex Transfer Will Be Succesfull)");
}
function action(mode, type, selection) {
if (mode == 0) {
cm.sendOk("Alright, come back when you change your mind.");
}else if (mode > 0) {
if (cm.getMeso() >= 20000000) {
cm.gainMeso(-20000000);
cm.getChar().setGender(1);
cm.sendOk("Alright, we're done.");
}else{
cm.sendOk("You don't have enough mesos");
}
}
cm.dispose();
}
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Quote:
Originally Posted by
SuperLol
SHAWN GET ON MSN
Code:
function start() {
cm.sendYesNo("I can make you a Female... LOL. Are you ready? (Remember THAT you need to Change Channel, That Way the Sex Transfer Will Be Succesfull)");
}
function action(mode, type, selection) {
if (mode == 0) {
cm.sendOk("Alright, come back when you change your mind.");
}else if (mode > 0) {
if (cm.getMeso() >= 20000000) {
cm.gainMeso(-20000000);
cm.getChar().setGender(1);
cm.sendOk("Alright, we're done.");
}else{
cm.sendOk("You don't have enough mesos");
}
}
cm.dispose();
}
End Chat is not defined :love:
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Then where do i put the scripts in? Do i put it in my MYSQL query browser?
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Quote:
Originally Posted by
Omgkenishere
Then where do i put the scripts in? Do i put it in my MYSQL query browser?
Source/Repack folder > scripts > npc > save as NPC ID.js
When I say NPC ID, I hope you understand that means it's ID... such as... if Cody was 1000, you would save it as 1000.js.
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Quote:
Originally Posted by
Shawn
PHP Code:
function start() {
cm.sendYesNo("I can make you a Female... LOL. Are you ready? (Remember THAT you need to Change Channel, That Way the Sex Transfer Will Be Succesfull)");
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
return;
} else if (mode == 0) {
cm.sendOk("Alright, come back when you change your mind.");
cm.dispose();
}else{
if (cm.getMeso() >= 20000000) {
cm.gainMeso(-20000000);
cm.getChar().setGender(1);
cm.sendOk("Alright, we're done.");
}else{
cm.sendOk("You don't have enough mesos");
}
cm.dispose();
}
}
I don't get why there don't have to be var status == 0; in this script :?:
Edit:
And somehow it doesn't work either, I think the setGender parts isn't right or something, because i get a "This npc isn't working properly"
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Quote:
Originally Posted by
Vinnynib
I don't get why there don't have to be var status == 0; in this script :?:
Edit:
And somehow it doesn't work either, I think the setGender parts isn't right or something, because i get a "This npc isn't working properly"
There doesn't need to be a status because it can perform the desired action in the very next status, aka function action. If you wanted it to give another option as well, then you would need a status. Think of it like this. Someone asks you if you are a guy. If yes, do action, if no, do action. That is what this NPC does. Now say someone asked you if you were a guy, if yes, ask another question... That would require a status.
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Aha I get it! Thanks =)
And do you know how to solve that problem, It's so weird. I just used the script you edited and it still doesn't work properly
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Quote:
Originally Posted by
Vinnynib
Aha I get it! Thanks =)
And do you know how to solve that problem, It's so weird. I just used the script you edited and it still doesn't work properly
What is the error? Show the bat error.
-
Re: [Tut] Learning NPC scripts (beginner's guide)
I get this bat error
Error: NPC 101205. UndeclaredThrowableExeption.
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Quote:
Originally Posted by
Vinnynib
I get this bat error
Error: NPC 101205. UndeclaredThrowableExeption.
What line? Post the actual error please...
-
Re: [Tut] Learning NPC scripts (beginner's guide)
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Try this...
PHP Code:
function start() {
cm.sendYesNo("I can make you a Female... LOL. Are you ready? (Remember THAT you need to Change Channel, That Way the Sex Transfer Will Be Succesfull)");
}
function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
return;
} else if (mode == 0) {
cm.sendOk("Alright, come back when you change your mind.");
cm.dispose();
}else{
if (cm.getMeso() >= 20000000) {
cm.gainMeso(-20000000);
cm.getPlayer().setGender(1);
cm.sendOk("Alright, we're done.");
}else{
cm.sendOk("You don't have enough mesos");
}
cm.dispose();
}
}
If not, then figure out how to properly use the setGender method. That is the error. It can't find the function "getChar".
-
Re: [Tut] Learning NPC scripts (beginner's guide)
-
Re: [Tut] Learning NPC scripts (beginner's guide)
-
Re: [Tut] Learning NPC scripts (beginner's guide)
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Very useful and so easy to understand.
Although I believe those are not all of the cm. commands..
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Thank alot, This is helping for beginners scripting.
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Hello, first off I would like to say that this is an amazing tutorial and has helped me a lot. Here i have created a script and tested it. It works on the server besides of one problem. At the bottom where it checks if they have all of those items that part works perfectly. It checks for all of those items. Then after that where it says they lose the items the only one that is actually deleted from the inventory is "cm.gainItem(2022015, -100)" Then after that gaining the one power elixer works perfectly. (I put one power elixer just as a test). I just need to know how to make it so that you lose all of the items from the inventory instead of that one item, even though it checks for all of the items. Any help is appreciated. Thanks.
PHP 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 >= 2 && mode == 0) {
cm.sendOk("Aww.. I guess I'll just ask somebody else.");
cm.dispose();
return;
}
if (mode == 1) {
status++;
}
else {
status--;
}
if (status == 0) {
cm.sendYesNo("Hey you! Can you get me some ramen?");
}
else if (status == 1) {
cm.sendNext("I'm STARVING and I am in a rush. I have to go take the genin exam, and can't get any for myself.");
}
else if (status == 2) {
cm.sendNext("The types of ramen I need you to get for me are 100 Mushroom Miso Ramen, 50 W Ramen, 30 Ramen, 20 Roasted Pork Kinoko Ramen, 20 Pig Head Kinoko Ramen, and 20 Salt Kinoko Ramen.");
}
else if (status == 3) {
if (cm.haveItem(2022015, 100) && cm.haveItem(2020011, 50) && cm.haveItem(2022017, 30) && cm.haveItem(2022018, 20) && cm.haveItem(2022019, 20) && cm.haveItem(2022020, 20)) {
cm.gainItem(2022015, -100) && cm.gainItem(2020011, -50) && cm.gainItem(2022017, -30) && cm.gainItem(2022018, -20) && cm.gainItem(2022019, -20) && cm.gainItem(2022020, -20);
cm.sendNext("Yes! Thank you for the ramen! I found a weird object on the ground in the ramen shop, I figured I'd give it to you because I don't need it. See ya later!");
cm.gainItem(2000005);
cm.dispose();
}
else {
cm.sendOk("What?! That amount of ramen won't fill me up! Get me some more!");
cm.dispose();
}
}
}
}
-
Re: [Tut] Learning NPC scripts (beginner's guide)
That's because this isn't a valid statement:
PHP Code:
cm.gainItem(2022015, -100) && cm.gainItem(2020011, -50) && cm.gainItem(2022017, -30) && cm.gainItem(2022018, -20) && cm.gainItem(2022019, -20) && cm.gainItem(2022020, -20);
At least... to my knowledge. It should be a single statement each, like this.
PHP Code:
cm.gainItem(2022015, -100);
cm.gainItem(2020011, -50);
cm.gainItem(2022017, -30);
cm.gainItem(2022018, -20);
cm.gainItem(2022019, -20);
cm.gainItem(2022020, -20);
Or if you want to save space (but also makes it a little harder to read, you could do this.
PHP Code:
cm.gainItem(2022015, -100); cm.gainItem(2020011, -50); cm.gainItem(2022017, -30); cm.gainItem(2022018, -20); cm.gainItem(2022019, -20); cm.gainItem(2022020, -20);
You have to have a semicolon at the end of each statement, otherwise the script throws an error because it tries to read all of them as one statement, and the method doesn't support that. Now... if you are trying to remove all the items they have, like say... they need 20 of an item, and they have 50, and you want to take all of them, you use...
PHP Code:
cm.removeAll(itemId);
Almost all repacks/sources have this method.
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Quote:
Originally Posted by
Shawn
That's because this isn't a valid statement:
PHP Code:
cm.gainItem(2022015, -100) && cm.gainItem(2020011, -50) && cm.gainItem(2022017, -30) && cm.gainItem(2022018, -20) && cm.gainItem(2022019, -20) && cm.gainItem(2022020, -20);
At least... to my knowledge. It should be a single statement each, like this.
PHP Code:
cm.gainItem(2022015, -100);
cm.gainItem(2020011, -50);
cm.gainItem(2022017, -30);
cm.gainItem(2022018, -20);
cm.gainItem(2022019, -20);
cm.gainItem(2022020, -20);
Or if you want to save space (but also makes it a little harder to read, you could do this.
PHP Code:
cm.gainItem(2022015, -100); cm.gainItem(2020011, -50); cm.gainItem(2022017, -30); cm.gainItem(2022018, -20); cm.gainItem(2022019, -20); cm.gainItem(2022020, -20);
You have to have a semicolon at the end of each statement, otherwise the script throws an error because it tries to read all of them as one statement, and the method doesn't support that. Now... if you are trying to remove all the items they have, like say... they need 20 of an item, and they have 50, and you want to take all of them, you use...
PHP Code:
cm.removeAll(itemId);
Almost all repacks/sources have this method.
IIRC technically you dont need semicolons in javascript if you format it right, but it is good practice.
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Hello, I have another script problem. This time its not with an error, but It's on how to set something up. I want to make a selection and have different status in it so that each selection will say multiple things instead of only one thing. I have set up a script how you would do it based on what i learned from this tutorial and i wasn't surprised to see that it didn't work. Here is the script i made just so you can possibly see what i mean. Please help if possible, if this doesn't work it would be helpful if someone could possibly tell me an easier way to do something like this. Thanks again.
PHP 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 >= 2 && mode == 0) {
cm.sendOk("Cya later!");
cm.dispose();
return;
}
if (mode == 1) {
status++;
}
else {
status--;
}
if (status == 0) {
cm.sendYesNo("Hey, can you help me? I seem to have lost my hat.");
}
else if (status == 1) {
cm.sendNext("I've looked all over the place and can't find it!");
}
else if (status == 2) {
cm.sendSimple("So, can you help me find it?\r\n#L0#It's on your head idiot.#l");
}
else if (status == 3) {
if (selection == 0) {
cm.sendNext("What are you talking about? There's no hat on my head..");
}
else if (status == 4) {
cm.sendNext("Ok, so please get me 50 straw hats, that way I wont ever run out. I'll reward you if you do.");
}
else if (status == 5) {
if cm.haveItem(2000005)) {
cm.sendOk("GREAT! You got my straw hats!" Here's your reward as I promised.");
cm.gainItem(2000006);
cm.dispose();
}
}
else {
cm.sendOk("Are you trying to trick me? *Punches you away* GET ME SOME MORE!");
cm.dispose();
}
}
}
}
-
Re: [Tut] Learning NPC scripts (beginner's guide)
This is sooo useful. :ott:
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Thanks, from 0 to level 5 ]=P woot
well I got 1 question how I may to know what "x - X coordinate" & "y - Y coordinate" to type ?
-
Re: [Tut] Learning NPC scripts (beginner's guide)
Dont work ? how make it work ?
-
Re: [Add-On] Learning NPC scripts (beginner's guide)
Where do you put the scripts? o.o