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.
Junior Spellweaver
Joined
Jul 21, 2008
Messages
124
Reaction score
47
Re: [Guide] Learning NPC scripts (beginner's guide)

**Updated

More Terms to know. Added some different checks for job,level, gender, etc.
 
Newbie Spellweaver
Joined
Feb 14, 2008
Messages
39
Reaction score
0
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.
 
Junior Spellweaver
Joined
Jul 21, 2008
Messages
124
Reaction score
47
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();
                }
            }
        }
    }
}
 
Newbie Spellweaver
Joined
Feb 14, 2008
Messages
39
Reaction score
0
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.
 
Newbie Spellweaver
Joined
Nov 29, 2008
Messages
33
Reaction score
0
Re: [Guide] Learning NPC scripts (beginner's guide)

Good Job Angel ! :laugh:
 
Junior Spellweaver
Joined
Jul 21, 2008
Messages
124
Reaction score
47
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.
 
Getting into Graphics
Joined
Jun 22, 2008
Messages
173
Reaction score
0
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."
 
Newbie Spellweaver
Joined
Dec 7, 2008
Messages
84
Reaction score
0
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 .
 
Junior Spellweaver
Joined
Jul 21, 2008
Messages
124
Reaction score
47
Re: [Guide] Learning NPC scripts (beginner's guide)

checks for donator

Code:
if(cm.getJob().equals(net.sf.odinms.client.MapleJob.BOWMAN)) {

Huh?

You got it backwards. I'm describing the codes by what's UNDER it. Not above.
 
Newbie Spellweaver
Joined
Nov 14, 2008
Messages
5
Reaction score
0
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.
 
Getting into Graphics
Joined
Jun 22, 2008
Messages
173
Reaction score
0
Re: [Guide] Learning NPC scripts (beginner's guide)

Works fine for me.
Did you change ANYTHING at all?
 
Newbie Spellweaver
Joined
Nov 14, 2008
Messages
5
Reaction score
0
Re: [Guide] Learning NPC scripts (beginner's guide)

Works fine for me.
Did you change ANYTHING at all?

I just tried again, I didn't change anything and it's doing the same thing. Why would it be doing this???
 
Getting into Graphics
Joined
Jun 22, 2008
Messages
173
Reaction score
0
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(); 
            }  
        } 
    }
}
 
Newbie Spellweaver
Joined
Nov 14, 2008
Messages
5
Reaction score
0
Re: [Guide] Learning NPC scripts (beginner's guide)

did you change anything? It's still doing the same thing.
 
Getting into Graphics
Joined
Jun 22, 2008
Messages
173
Reaction score
0
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?
 
Newbie Spellweaver
Joined
Nov 14, 2008
Messages
5
Reaction score
0
Re: [Guide] Learning NPC scripts (beginner's guide)

I'm using v61 valhalla source.
 
Newbie Spellweaver
Joined
Dec 8, 2008
Messages
41
Reaction score
2
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();  
        	}  
        }
    } 
}
 
Junior Spellweaver
Joined
Jul 21, 2008
Messages
124
Reaction score
47
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();   
            }   
        } 
    }  
}
 
Newbie Spellweaver
Joined
Dec 30, 2008
Messages
10
Reaction score
0
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
Top