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

Status
Not open for further replies.
Re: [Guide] Learning NPC scripts (beginner's guide)

**Updated

More Terms to know. Added some different checks for job,level, gender, etc.
 
Re: [Guide] Learning NPC scripts (beginner's guide)

is it possible for you to add a more advance one? Cause I'm having troubles making an NPC checking two things. It's not working out for me =/
PHP:
// Credits to Moogra
var status = 0;
var map = Array(240010501);

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--;
        if (status == 0) {
            cm.sendSimple("Hello, I am the Meso to Item converter. Do you want to trade in 1 billion mesos for a #b#v4000313##k? Or do you want to trade in my #b#v4000313##k for 1 billion mesos?\r\n#L1# I would like to trade my #b#v4000313##k for 1 billion mesos!#l\r\n\#L2# I would like to exchange 1 billion mesos for a #b#v4000313##k!#l");
        } else if (status == 1) {
            if (selection == 1) {
                if(cm.haveItem(4000313)) {
                    cm.gainMeso(1000000000);
                    cm.gainItem(4000313,-1); 
                    cm.sendOk("Thank you for your mesos!");
                } else {
                    cm.sendOk("Sorry, you don't have a #b#v4000313##k!");
                }
                cm.dispose();
            } else if (status == 2) {
            } else if (selection == 2) {
                if(cm.getMeso() >= 1000000000) {
                    cm.gainMeso(-1000000000);
                    cm.gainItem(4000313,1);
                    cm.sendOk("Thank you for your item!");
                } else {
                    cm.sendOk("Sorry, you don't have enough mesos!");
                }
                cm.dispose();
            }
            else{
                cm.sendOk("All right. Come back later");
            }
        }
    }
}

I want to make it so when it checks for a Golden Maple Leaf it also checks if the player has 2bil so no one loses their Golden Maple Leaves for nothing.
 
Re: [Guide] Learning NPC scripts (beginner's guide)

@zezokicker

I made it so it checks if they have more than or equal to 1.2bil. If they have 1.2bil or more it won't exchange the maple leaf for 1bil.

Untested. Try it. Tell me if it works. If it doesn't I'll look over it again incase I missed something

PHP:
// Credits to Moogra
var status = 0;

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
     
    if (mode == -1) {
        cm.dispose();
    }
    else { 
        if (status >= 3 && mode == 0) { 
            cm.sendOk("All right. Come back later");
            cm.dispose(); 
            return; 
        } 
        
        if (mode == 1) {
            status++;
        }    
        else {
            status--;
        }
        
        if (status == 0) {
            cm.sendSimple("Hello, I am the Meso to Item converter. Do you want to trade in 1 billion mesos for a #b#v4000313##k? Or do you want to trade in my #b#v4000313##k for 1 billion mesos?\r\n#L1# I would like to trade my #b#v4000313##k for 1 billion mesos!#l\r\n\#L2# I would like to exchange 1 billion mesos for a #b#v4000313##k!#l");
        } 
        else if (status == 1) {
            if (selection == 1) {
                if(cm.getMeso() >= 1200000000) {
                    cm.sendOk("You seem to have 1.2bil. You do not have enough space for another bil.");
                    cm.dispose();
                }
                else if(cm.haveItem(4000313)) {
                    cm.gainMeso(1000000000);
                    cm.gainItem(4000313,-1); 
                    cm.sendOk("Thank you for your mesos!");
                    cm.dispose();
                } 
                else {
                    cm.sendOk("Sorry, you don't have a #b#v4000313##k!");
                    cm.dispose();
                }
            } 
            else if (selection == 2) {
                if(cm.getMeso() >= 1000000000) {
                    cm.gainMeso(-1000000000);
                    cm.gainItem(4000313,1);
                    cm.sendOk("Thank you for your item!");
                    cm.dispose();
                } 
                else {
                    cm.sendOk("Sorry, you don't have enough mesos!");
                    cm.dispose();
                }
            }
        }
    }
}
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Wow! Thanks a lot. Can you teach me these things ><
It's confusing me. And Merry Belated Christmas! and it worked.
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Wow! Thanks a lot. Can you teach me these things ><
It's confusing me. And Merry Belated Christmas! and it worked.

The best way is to practice making your own scripts first. If the scripts don't work PM them to me or post them here. I'll fix it and tell you what you forgot.
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Hey get1720.
You must have helped me a lot already, but...
Is there a way to make it so that if you talk to the NPC, you character gets to a higher level in the MySQL database. Like...

"Hello, want to become a GM?"
"Okay, you are now a GM, please relog for everything to take effect such as the ! commands."
 
Re: [Guide] Learning NPC scripts (beginner's guide)

My favorite guide :D
but the Spolier, i don't like D:
Now, make a guide about Arrays (: haha .
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Your finished script at bottom of level 4 doesn't work. I copied it exactly, when I click it, It comes up with a window that says "Hello!" when you hit next, the chat window disappears and glitches so I have to change channel to talk to any npc again.
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Try this.

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("Goodbye");    
            cm.dispose();    
            return;    
        }    
           
        if (mode == 1) {   
            status++;   
        }       
        else {   
            status--;   
        }   
           
        if (status == 0) {  
            cm.sendNext("Hello!"); 
        } 
        else if (status == 1) { 
            if (cm.haveItem(2000005, 1)) { 
                cm.sendSimple("You have power elixirs.\r\n#L0#Can I have some anyway?#l\r\n#L1#I'll see you later#l"); 
            } 
        }
        else if (status == 2) {
        if (selection == 0) { 
            cm.sendOk("Okay here you go"); 
            cm.gainItem(2000005, 1); 
            cm.dispose(); 
        } else if (selection == 1) { 
            cm.sendOk("See you later"); 
            cm.dispose(); 
        } 
        else { 
            cm.sendOk("You don't have a power elixir? Here I'll give you 10!"); 
            cm.gainItem(2000005, 10);
            cm.dispose(); 
            }  
        } 
    }
}
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Yes, I changed the way it looks for the item.
Wait a sec.
Version 55? or 62?
 
Re: [Guide] Learning NPC scripts (beginner's guide)

@AntiHeadShot :
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!");  
        } else if (status == 1) {  
            if (cm.haveItem(2000005, 1))
                cm.sendSimple("You have power elixirs.\r\n#L0#Can I have some anyway?#l\r\n#L1#I'll see you later#l");  
            else {
		cm.sendOk("You don't have a power elixir? Here I'll give you 10!");  
            	cm.gainItem(2000005, 10); 
            	cm.dispose();
	    }
        } else if (status == 2) { 
        	if (selection == 0) {  
            		cm.sendOk("Okay here you go");  
            		cm.gainItem(2000005);  
            		cm.dispose();  
        	} else if (selection == 1) {  
            		cm.sendOk("See you later");  
            		cm.dispose();  
        	}  
        }
    } 
}
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Not quite guys. Here you go:

@Xoti you forgot a { at the end of the cm.haveItem

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!");   
        } 
        else if (status == 1) {   
            if (cm.haveItem(2000005, 1)) {
                cm.sendSimple("You have power elixirs.\r\n#L0#Can I have some anyway?#l\r\n#L1#I'll see you later#l");  
            } 
            else { 
                cm.sendOk("You don't have a power elixir? Here I'll give you 10!");   
                cm.gainItem(2000005, 10);  
                cm.dispose(); 
            }
        } 
        else if (status == 2) {  
            if (selection == 0) {   
                cm.sendOk("Okay here you go");   
                cm.gainItem(2000005);   
                cm.dispose();   
            } 
            else if (selection == 1) {   
                    cm.sendOk("See you later");   
                    cm.dispose();   
            }   
        } 
    }  
}
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Hey guys, I'm new here but keen to learn how to code for Maple Story. Could someone have a look other this script I made and point out any problems with it?

The idea of it is to see if the user has ilbis, and then go on from there. (Its based around the end script of the tutorial :) )

Thanks,
Cloud.

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("Goodbye");    
            cm.dispose();    
            return;    
        }    
           
        if (mode == 1) {   
            status++;   
        }       
        else {   
            status--;   
        }   
           
        if (status == 0) {
		cm.sendNext("Why, hello there my fellow ninja. It seems you may be in need of some throwing stars...");
	}
	else if (status == 1) {
		     if cm.haveItem(ILBI ID HERE);
			cm.sendSimple("Ah, it seems you already have some. Shame. Do you want some more?")
		}
		else {
			cm.sendOk("Ummm, seems you could use some. Here, take these.");
			cm.gainItem(ILBI ID HERE, 5);
			cm.dispose();
			}
		}
		else if (status == 2) {
		if (selection == 0) {
			cm.sendOk("These should help you with your hunting");
			cm.gainItem(ILBI ID HERE, 5);
			cm.dispose();
		} else if (selection == 1) {
			cm.sendOk("Goodbye");
			cm.dispose();
			}
		}	
	}
}
 
Status
Not open for further replies.
Back