NPC Basic Scripting Guide

Discussion in 'MapleStory Tutorials & Guides' started by Remi, Jan 13, 2016.

  1. Remi

    Remi New Member

    Joined:
    Aug 30, 2015
    Messages:
    6
    IMPORTANT!: This guide is for those who understand the basics of Programming.

    Part One
    Basic Scripting
    I won't be detailing everything in this guide, as it is a basic starting point. I don't want you or my self getting confused. :tongue:

    Most scripts start with a comment. How do you comment? First let's take a look at single line comments:
    Code:
    //This is a comment.
    //Remi is awesome.
    //Comments are just a way of telling yourself that this code does this and that.
    //But this is a single line comment which is only useful for single lines of text or code.
    
    Like i said above single line comments are ok but what if you need to comment out a block of code? Let's do this:
    Code:
    /*I am going to explain this in another line.
    This is called a multi-line comment.
    useful for large blocks of code and enormous text.
    You can start it with "/*"
    don't forget to close off the multi-line comment with "*/"
    */
    Now let us begin with the scripting! :wink:
    To start a script it is wise to use this format.
    Code:
    */
    @    Author: Remi
    */
    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;   
            }   
      }
    }
    
    Part Two
    The explanation


    Well first, var mean variable (I think so don't quote). So now looking at this, what do you see? Right! our variable status = 0. Simple right? Just think of that good ole' algebra here. So say if x = 10 then when ever we use this "x" in the script it would do something to 10, something like print to chat, multiply it, add to it, subtract from it, etc. You only really need to use var to make your code look neat.
    Code:
     var status = 0; 
    Onward!!
    Code:
    function start() {
           status = -1;
           action(1, 0, 0);
    }
    
    This block of code is telling the NPC to start at status -1 and the action is stated to this part of the script.

    Wow you're getting the hang of this? No? Let's keep going.

    Code:
    function action(mode, type, selection) {
    
    This means that (mode, type, selection) is = to (-1,0,0) above. Which says that mode is used (mode, = (action, -1)) (type = (action, 0)) and so on..

    Don't stop now...

    Code:
    if (mode == -1) {
             cm.dispose();
    
    This is using "end chat" leaving the chat window.

    Cool right?
    Code:
    if (mode == -1) {
            cm.dispose();
    } else {
           if (status >= 2 && mode == 0) {
                   cm.sendOk("Goodbye");
                   cm.dispose();
                   return;
            }
    
    See where it says Goodbye? That text there is what shows when someone hits Exit Chat or No in a conversation. If you don't want it to say anything just remove the cm.sendOk line and leave the cm.dispose();

    cm.sendOk is pretty much bringing up a conversation with an OK button at the bottom of it. Simple right? cm.dispose(); is there to end it.

    And you made your first npc, even though it's like the most basic one it's still a npc right? :biggrin:
    +Rep if you liked this tut and want more advanced NPCs. Thanks for reading!! :redface: