Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Add-On] Learning NPC scripts (beginner's guide)

Status
Not open for further replies.
Newbie Spellweaver
Joined
Nov 6, 2008
Messages
5
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

You already cm.dispose()'d it at if (status == 0) { o_O. Sorry if I'm wrong, I'm a noob coder. :p And btw the very last cm.sendOk change it to maple leaf not maplestar :p
 
Newbie Spellweaver
Joined
Mar 16, 2009
Messages
9
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

cm.gainNX doesnt work?!??!
i check it with lowercase "x" too and it didnt work
 
Last edited:
Junior Spellweaver
Joined
Jul 21, 2008
Messages
124
Reaction score
47
Re: [Tut] Learning NPC scripts (beginner's guide)

@jrandall

PHP:
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("Goodbye");   
            cm.dispose();   
            return;   
        }   
          
        if (mode == 1) {  
            status++;  
        }      
        else {  
            status--;  
        }  
          
        if (status == 0) {
	        cm.sendYesNo("Would you like a maple leaf for 20 MILLION mesos? You can use maplestars to buy many cool items that aren't available in shops.");
	    // don't put a cm.dispose(); here. That will end the conversation too early and you won't get to see the rest of your script
        }
	    else if (status == 1} {
            if(cm.getMeso() >= 20000000) { //Changed it a little. You should make it >= so if they have exactly that amount it'll work too
                sendOK("Here you are. One maple leaf for you! If you keep saving you might be able to buy GM Roar =D. Please report any glitches with this npc to a GM immediately. Thank you.  -DukeMS Staff");
                cm.gainMeso(-20000000);
	            cm.gainItem(4001126, 1);
		        cm.dispose();            
	        }	    
            else {
                cm.sendOk("You don't have enough mesos to buy a maplestar D=");
	            cm.dispose();
            } // You had one extra }
        }
    }
}

@Ramsey

Different servers may have different cm. commands for gaining nx. A definite way is to use:

PHP:
cm.getPlayer().modifyCSPoints(0, 10000);

the 10000 is where you should put how much you want it to gain.
 
Mythic Archon
Loyal Member
Joined
May 23, 2008
Messages
779
Reaction score
4
Re: [Tut] Learning NPC scripts (beginner's guide)

Nice guide, Angela.
 
Newbie Spellweaver
Joined
Mar 25, 2009
Messages
6
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

woot thx, time to test my abilities :D
 
Newbie Spellweaver
Joined
Mar 16, 2009
Messages
9
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

@Angel

I tried that cm.getPlayer().modifyCSPoints(0, 10000);
but it didnt work and i saw this is my nxchatmanager thing so how many other ways are there to make it work?

-thanks
 
Newbie Spellweaver
Joined
Oct 9, 2008
Messages
66
Reaction score
2
Re: [Tut] Learning NPC scripts (beginner's guide)

I'm always doing something worng...

PHP:
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("Goodbye");      
            cm.dispose();      
            return;      
        }      
             
        if (mode == 1) {     
            status++;     
        }         
        else {     
            status--;     
        }     
             
        if (status == 0) {    
            cm.sendNext("Hello there!");   
        }   
        else if (status == 1) {   
            if(cm.getMesos(1) {   
                cm.sendSimple("Want get out from here?\r\n#L0#Yes, i'd like to#l\r\n#L1#Nah, I wanna stay here.#l");   
            }    
            else {   
                cm.sendOk("Ok first i give you 100mil mesos =)");   
                cm.gainMesos(100000000);  
                cm.dispose(); 
            }     
        }  
        else if (status == 2) {  
            if (selection == 0) {   
                cm.sendOk("Bye Bye...");   
                cm.warp(40000, 0);   
                cm.dispose();   
            }   
            else if (selection == 1) {   
                cm.sendOk("Lol, bye bye then.");   
                cm.dispose();   
            }  
        }   
    }  
}

Can you guys fix it? :/:
 
Newbie Spellweaver
Joined
Feb 15, 2009
Messages
45
Reaction score
2
Re: [Tut] Learning NPC scripts (beginner's guide)

PHP:
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)
            cm.dispose();
        if (mode == 1)
            status++;
        else
            status--;     
             
        if (status == 0) {    
            cm.sendNext("Hello there!");   
        }   
        else if (status == 1) {   
            if(cm.getMeso() >= 1) {   
                cm.sendSimple("Want get out from here?\r\n#L0#Yes, i'd like to#l\r\n#L1#Nah, I wanna stay here.#l");   
            }    
            else {   
                cm.sendOk("Ok first i give you 100mil mesos =)");   
                cm.gainMesos(100000000);  
                cm.dispose(); 
            }     
        }  
        else if (status == 2) {  
            if (selection == 0) {   
                status = 5;
                cm.sendNext("I'll get you out!");				
            }   
            else if (selection == 1) {   
                cm.sendOk("Lol, bye bye then.");   
                cm.dispose();   
            }  
        } else if (status == 5) {
    cm.warp(40000, 0);   
    cm.dispose();
}	
    }  
}

It's cm.getMeso() >=/==/<= 1 :D
 
Newbie Spellweaver
Joined
Oct 9, 2008
Messages
66
Reaction score
2
Re: [Tut] Learning NPC scripts (beginner's guide)

Oh... thanks for explaining :D

Edited:

Nope NPC wont work. I can click on it. But when i chose "Yes i want get out" it nothing happens. And dont get 100mils =/
 
Mythic Archon
Loyal Member
Joined
May 23, 2008
Messages
779
Reaction score
4
Re: [Tut] Learning NPC scripts (beginner's guide)

PHP:
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)
            cm.dispose();
        if (mode == 1)
            status++;
        else
            status--;     
             
        if (status == 0) {    
            cm.sendNext("Hello there!");   
        }   
        else if (status == 1) {   
            if(cm.getMeso() >= 1) {   
                cm.sendSimple("Want get out from here?\r\n#L0#Yes, i'd like to#l\r\n#L1#Nah, I wanna stay here.#l");   
                else if (status == 2) {  
            if (selection == 0) {   
                cm.sendOk("Ok first i give you 100mil mesos =)");   
                cm.gainMesos(100000000);  
                cm.dispose();  
        else if (status == 3) {  
            if (selection == 1) {   
                cm.sendNext("I'll get you out!");                
      	    cm.warp(40000, 0);   
    		    cm.dispose();
}
}
}

Might not work, but it's really close.
 
Newbie Spellweaver
Joined
Oct 9, 2008
Messages
66
Reaction score
2
Re: [Tut] Learning NPC scripts (beginner's guide)

PHP:
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)
            cm.dispose();
        if (mode == 1)
            status++;
        else
            status--;     
             
        if (status == 0) {    
            cm.sendNext("Hello there!");   
        }   
        else if (status == 1) {   
            if(cm.getMeso() >= 1) {   
                cm.sendSimple("Want get out from here?\r\n#L0#Yes, i'd like to#l\r\n#L1#Nah, I wanna stay here.#l");   
                else if (status == 2) {  
            if (selection == 0) {   
                cm.sendOk("Ok first i give you 100mil mesos =)");   
                cm.gainMesos(100000000);  
                cm.dispose();  
        else if (status == 3) {  
            if (selection == 1) {   
                cm.sendNext("I'll get you out!");                
      	    cm.warp(40000, 0);   
    		    cm.dispose();
}
}
}

Might not work, but it's really close.


Cant even click on it.
 
Newbie Spellweaver
Joined
Mar 7, 2009
Messages
14
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

Sorry i took so long to reply, but THANK YOU. OMG YOU ARE AWESOME!!! I can now start an economy in my server lol xD


Edit: Ok, i just tested it and it still doesnt work D=. If you could try and find a way to get it to work for me i would be very greatful of you. xD
 
Newbie Spellweaver
Joined
Jul 15, 2008
Messages
36
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

Code:
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)
            cm.dispose();
        if (mode == 1)
            status++;
        else
            status--;     
             
        if (status == 0) {    
            cm.sendNext("Hello there!");   
        }   
        else if (status == 1) {   
            if(cm.getMeso() >= 1) {   
                cm.sendSimple("Want get out from here?\r\n#L0#Yes, i'd like to#l\r\n#L1#Nah, I wanna stay here.#l");   
            }    
            else {   
                cm.sendOk("Ok first i give you 100mil mesos =)");   
                cm.gainMeso(100000000);  
                cm.dispose(); 
            }     
        }  
        else if (status == 2) {  
            if (selection == 0) {   
                status = 5;
                cm.sendOk("I'll get you out!");
                cm.warp(40000, 0);
                cm.dispose();
            }   
            else if (selection == 1) {   
                cm.sendOk("Lol, bye bye then.");   
                cm.dispose();   
            }  
    }  
}

isnt it gainMeso instead of gainMesos
 
Newbie Spellweaver
Joined
Mar 7, 2009
Messages
14
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

Ok, since the last script you gave me didn't end up working, I tried to make another script using a different format. AND IT STILL DOESN'T WORK!!! argh. Heres the script
PHP:
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("Goodbye");   
            cm.dispose();   
            return;   
        }   
          
        if (mode == 1) {  
            status++;  
        }      
        else {  
            status--;  
        }  
          
        if (status == 0) {  
            cm.sendSimple("What Would you like?\r\n#L0#Maple Coin (2 Billion Mesos)#l");
        }
        else if (status == 1) {
        if (selection = 0) {
            cm.getMeso(>= 2000000000);
            sendOk("Here you are. One Maple Leaf for you. Keep saving them, theyre will be awesome items you can buy in the near future.");
            cm.gainMeso(-2000000000);
            cm.gainItem(4001126, 1);
            cm.dispose();
        }
        else {
            cm.sendOk("You don't have enough mesos for a Maple Lead D=. They cost 2Bil.");
            cm.dispose();
        }
    }
}

I dont have to compile it right? Because its not in the source folder.

Edit: Rofl, I spelled Maple Leaf different each time lmao
 
Last edited:
Newbie Spellweaver
Joined
Aug 6, 2008
Messages
5
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

This guide actually taught me how to script NPC
 
Junior Spellweaver
Joined
Apr 2, 2009
Messages
141
Reaction score
1
Re: [Tut] Learning NPC scripts (beginner's guide)

Very Useful to me! =]
 
Initiate Mage
Joined
Mar 19, 2009
Messages
1
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

thank you very much XD
 
I'm back ಠ_ಠ
Joined
Apr 9, 2008
Messages
450
Reaction score
12
Re: [Tut] Learning NPC scripts (beginner's guide)

Can you check out my code, I got a few errors.

Code:
// Created by Garvorious
// NPC: The Perma-Noob Teleporter
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("All right, enjoy iStory!");
   cm.dispose();
   return;
  }
  if (mode == 1) {
   status++;
  }
  else {
   status--;
  }

  if (status == 0) {
   cm.sendNext("Hey! Welcome to iStory. I'm Garv's witch here to help you out.");
  }
  else if (status == 1) {
   cm.sendSimple("Since the magic bush teleports users, Im here to tele you. Sorry for the confusion");
  }
  else {
   cm.sendOk("Where do you want to go? \r\n#L0I want to go to Victoria Island!#l\r\n#L1#I want to be a Perma-Noob.#l");
  }
  else if (status == 2) {
   if (selection == 0) {
   cm.sendOk("Allright, have fun in Victoria Island!);
   cm.warp(100000000, 0);
   cm.dispose();
  }
  else if (selection == 1) {
   cm.sendOk("Okay, have fun being a noob!");
   cm.warp(1010000, 0) {
   cm.dispose();
  }
 }
}

Sorry for the close spaceing, the copy paste didnt copy all of it.

Here's the acual .js:

 
Master Summoner
Loyal Member
Joined
Jul 27, 2008
Messages
583
Reaction score
0
Re: [Tut] Learning NPC scripts (beginner's guide)

Can you check out my code, I got a few errors.

Code:
// Created by Garvorious
// NPC: The Perma-Noob Teleporter
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("All right, enjoy iStory!");
   cm.dispose();
   return;
  }
  if (mode == 1) {
   status++;
  }
  else {
   status--;
  }

  if (status == 0) {
   cm.sendNext("Hey! Welcome to iStory. I'm Garv's witch here to help you out.");
  }
  else if (status == 1) {
   cm.sendSimple("Since the magic bush teleports users, Im here to tele you. Sorry for the confusion");
  }
  else {
   cm.sendOk("Where do you want to go? \r\n#L0I want to go to Victoria Island!#l\r\n#L1#I want to be a Perma-Noob.#l");
  }
  else if (status == 2) {
   if (selection == 0) {
   cm.sendOk("Allright, have fun in Victoria Island!);
   cm.warp(100000000, 0);
   cm.dispose();
  }
  else if (selection == 1) {
   cm.sendOk("Okay, have fun being a noob!");
   cm.warp(1010000, 0) {
   cm.dispose();
  }
 }
}

Sorry for the close spaceing, the copy paste didnt copy all of it.

Here's the acual .js:


PHP:
var status = -1; //Why puting the value of 0 here, and -1 ni start function? it's a waste of time.
function start() {
    cm.sendNext("Hey! Welcome to iStory. I'm Garv's witch here to help you out."); //In this case, this can basically remplace the action(1,0,0) since the user will make the value at next.
}

function action(mode, type, selection) {
    status++; //status will never get status--, so, why bother to add it?
    if (mode == -1) { //Reduce all  the poop, because the one you used it obvious a copy paste from another one, plus, it will never be mode == 0 unless you press Exit Chat in sendSimple, but since it said "&& status >= 2", then it will NEVER research that point.
        cm.dispose();
	    return;
    }
    if (status == 0) //Removed brackets because It's only 1 line of procedure, you cna leave the brackets, I just like it without brackets.
        cm.sendSimple("Since the magic bush teleports users, Im here to tele you. Sorry for the confusion\r\n #L0#Continue talking hottie"); //ou forgot to add a option. Or not use sendSimple here.
    else if(status == 1) //You don't put "else" to choose a option. Also I removed brackets again.
        cm.sendSimple("Where do you want to go? \r\n#L0#I want to go to Victoria Island!#l\r\n#L1#I want to be a Perma-Noob.#l"); //You forgot a # after #L0, Also, this should be sendSimple
    else if (status == 2) {
        cm.sendOk(selection == 0 ? "Allright, have fun in Victoria Island!" : "Okay, have fun being a noob!"); //You missed a " in the victoria one, Also I make it shorten.
        cm.warp(selection == 0 ? 100000000 : 1010000); //Why defining the spawn point if it's 0? lets just use the 1 parameter one. ALso, I make it shorten too.
        cm.dispose(); //1 dispose at the end with you way of do this would be better, since boths will research this part anyhow.
    }
}

Thought you where dev.
 
I'm back ಠ_ಠ
Joined
Apr 9, 2008
Messages
450
Reaction score
12
Re: [Tut] Learning NPC scripts (beginner's guide)

So you're saying devs are perfect in every way?

I never knew that o.o


Well the comments, deserves a thanks.
 
Status
Not open for further replies.
Back
Top