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

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

Hey everyone! I'm back! I haven't scripted much but I remember so I'll be trying to fix your scripts again.

@ gnomedrago

I saw you got some help on Clysse's thread. I fixed yours anyway. Tell me if it works.

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("Okay then, if you still want to try a #bJumpquest#k, talk to me!");
            cm.dispose();
            return;    
        }    

        if (mode == 1) {   
            status++;
        }
        else {   
            status--;
        }   

        if (status == 0) {
            cm.sendNext("Hi, I'm Nana of Orbis! I'm the #bUnrealStory Jumpquest Npc#k!!");
        }
        else if (status == 1) {
            cm.sendSimple("Where do you want me to take you?#b\r\n#L0#The Chimney JQ#l\r\n#L1#The Physical Training#l#k\r\n\r\nAt the end of each #bJumpquest#k there will be a Npc who gives rewards! So grab your chance and");
        } // You had an extra }
        else if  (status == 2) {
            if (selection == 0) {
            cm.warp(0, 0); // cm.warp not cm.Warp small mistakes like these can stop the command from working.
            cm.dispose();
            }
            else if (selection == 1) {
            cm.warp(0, 0);
            cm.dispose();
            }
        }
    }
}

@ randompeep

Karma are points recorded in the Database right? I don't think there's an NPC command to add Karma but check your NPCConversationManagar sql anyway.

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("See you around!");   
            cm.dispose();   
            return;   
        }   
          
        if (mode == 1) {  
            status++;  
        }      
        else {  
            status--;  
        }  
          
        if (status == 0) { 
            cm.sendNext("Hello, welcome to RandompeepMS!");
        } // remember that when you add a dispose(); it ends the conversation so save it for the end.
        else if (status == 1) {
            cm.sendNext("How goes the hunting?");
        } // extra }
        else if (status == 2) {
            cm.sendSimple("Do you need mesos? \r\n#L0#Yes, I'm broke and need some to start!#l\r\n#L1#No, but can I have some anyways?#l\r\n#L2#No, thank you.#l");
        } // extra }
        else if (status == 3) {
            if (selection == 0) {
                if (cm.getMeso() <= 1000) { // Caps the M in Meso or the cm. won't work 
                    cm.gainMeso(500000); // no [] I know people get confused because it shows the [] in the cm. commands spoiler
                    cm.sendOk("Wow, you really do need mesos. Well, I do not have much myself, but I hope it'll do."); // forgot a ;
                    cm.dispose();
                }
                else {
                    cm.sendOk("No, you aren't. Don't rip me off!");
                    cm.dispose();
                }
            } // This closes the if (selection == 0) {
            else if (selection == 1) {
                if (cm.getMeso() <= 1000000) {
                    cm.gainMeso(100000);
                    cm.sendOk("Well, you don't really need it, but... have a little anyways.");
                    cm.dispose();
                }
                else {
                    cm.sendOk("You don't have enough already? Stop leeching off my mesos; you have more than me now!");
                    cm.dispose();
                }
            } // This closes the else if (selection == 1) {
            else if (selection == 2) {
                if (cm.getFame() <= 25) {
                    cm.sendOk("You're an honest one. Unfortunately I don't have anything else to give you. Maybe some other day.");
                    cm.gainFame(1); // no []
                    cm.dispose();
                }
                else {
                    cm.sendOk("You're an honest one. Unfortunately I don't have anything else to give you. Maybe some other day.");
                    cm.dispose();
                }
            }
        }
    }
}
 
Last edited:
Re: [Tut] Learning NPC scripts (beginner's guide)

@ get -

PHP:
var status;

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

function action(mode, type, selection) {
	if (mode != 1) {
        cm.dispose();
		return;
    }
	status++;
	if (status == 0) {
		cm.sendNext("Hi, I'm Nana of Orbis! I'm the #bUnrealStory Jumpquest Npc#k!!");
	} else if (status == 1) {
		cm.sendSimple("Where do you want me to take you?#b\r\n#L0#The Chimney JQ#l\r\n#L1#The Physical Training#l#k\r\n\r\nAt the end of each #bJumpquest#k there will be a Npc who gives rewards! So grab your chance and");
	} else if (status == 2) {
		var warpMap;
		if (selection == 0) {
			warpMap = 0;
		} else if (selection == 1) {
            warpMap = 1;
		}
		cm.warp(warpMap, 0);
		cm.dispose();
	}
}

Your layout is ugly.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

@ PinkGatsby

So, I use a different way to start my scripts.
So, the way I start my scripts are spaced out so it seems long.
So, I like to space out my } like this:

PHP:
}
else {

So, I don't use variables in my scripts all the time.

If they work, they work. If that's how you like to do your scripts that's fine, but don't come here and say my layout is ugly. I'm not furious at you just annoyed you'd say that in my own thread.

@ kamoda

Doesn't it not work completely or stops are a certain point? Use spacing I think you're missing some brackets.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Thanks! One other question, how do you create custom quest IDs to make your own quest?
 
Re: [Tut] Learning NPC scripts (beginner's guide)

@ PinkGatsby

So, I use a different way to start my scripts.
So, the way I start my scripts are spaced out so it seems long.
So, I like to space out my } like this:

PHP:
}
else {

So, I don't use variables in my scripts all the time.

If they work, they work. If that's how you like to do your scripts that's fine, but don't come here and say my layout is ugly. I'm not furious at you just annoyed you'd say that in my own thread.

LOL.
You couldn't put 15 seconds max in to making the script more readable. People like you are the reason that some of the stuff people releases are hard to interpret and manage and hence chance of memory leaks. (Talking about Java in general.)



PHP:
var status;

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

function action(mode, type, selection) {
    if (mode != 1) {
        cm.dispose();
		
        return;
    }
	
	
	
	
	
    status++;
    i
	f 
	(status == 0) 
	{
	
	
	
	
        cm.sendN
		ext("Hi, I'm Nana of Orbis! I'm the #bUnrealStory Jumpquest Npc#k!!");
    } else 
	if (status == 1) {
	
        cm.sendSi
		mple("Where do you want me to take you?#b\r\n#L0#The Chimney JQ#l\r\n#L1#The Physical Training#l#k\r\n\r\nAt the end of each #bJumpquest#k there will be a Npc who gives rewards! So grab your chance and");
    } else if (status == 2)
	{
        var warpMap;
        if 
		(selection == 0) {
            warpMap = 0;
        } else if (selection == 1) {
            warpMap = 1;
        }
		
		
        cm.warp(warpMap, 0);
        cm.dis
		pose();
		
    }
}

The script works but is it easily readable ? No.
 
Last edited:
Re: [Tut] Learning NPC scripts (beginner's guide)

LOL.
You couldn't put 15 seconds max in to making the script more readable. People like you are the reason that some of the stuff people releases are hard to interpret and manage and hence chance of memory leaks. (Talking about Java in general.)



PHP:
var status;

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

function action(mode, type, selection) {
    if (mode != 1) {
        cm.dispose();
        
        return;
    }
    
    
    
    
    
    status++;
    i
    f 
    (status == 0) 
    {
    
    
    
    
        cm.sendN
        ext("Hi, I'm Nana of Orbis! I'm the #bUnrealStory Jumpquest Npc#k!!");
    } else 
    if (status == 1) {
    
        cm.sendSi
        mple("Where do you want me to take you?#b\r\n#L0#The Chimney JQ#l\r\n#L1#The Physical Training#l#k\r\n\r\nAt the end of each #bJumpquest#k there will be a Npc who gives rewards! So grab your chance and");
    } else if (status == 2)
    {
        var warpMap;
        if 
        (selection == 0) {
            warpMap = 0;
        } else if (selection == 1) {
            warpMap = 1;
        }
        
        
        cm.warp(warpMap, 0);
        cm.dis
        pose();
        
    }
}
The script works but is it easily readable ? No.

Then what does that make you? At least get has helped ALOT of people through this thread. Read through the entire thread and see for yourself. Regardless of it being "neat" or "better organized", it gets the job done, and if it teachs noobs along the way how to code NPCs, then so be it.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Two questions.

1. Same as the one from earlier. How do you actually make a custom quest ID, so your quests work?

2. How do you script an NPC so that it says something different from its original. Like, for example, a storage NPC summons a boss. (I was given cm.c.getPlayer().getMapId(), but I don't even know where to put that in the script.)
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Then what does that make you? At least get has helped ALOT of people through this thread. Read through the entire thread and see for yourself. Regardless of it being "neat" or "better organized", it gets the job done, and if it teachs noobs along the way how to code NPCs, then so be it.

I'm pretty sure I've created and fixed more npcs for other people than the thread starter. Remember the NPC helpdesk ? Sigh Shawn, why are you defending this guy
 
Re: [Tut] Learning NPC scripts (beginner's guide)

@ randompeep

1. A custom quest ID for a quest you made compeltly by yourself? I'm sorry, I haven't heard or done that before. I've just started playing private servers again so I haven't seen any servers do that either. Most people just make the NPC require you to get an item and check for the item.

2. I'm not sure what you mean. You mean the kind of NPC that says stuff already and even if you add a script it won't change? Explain a little more.

@ PinkGatsby

Could you please stop? Could you at least say something helpful while you're critisizing me? Why are you posting all this stuff against me? What do you have against me? Could you just PM me how you feel instead of writing it all in my tutorial?

I script this way and I show people how to script this way because it's straightforward and simple.

Here's a serious and true suggestion: If you truly want people to start scripting better with more variables and stuff, then do me and a lot of other people in this community a big favor. Go write a tutorial on how you script. Just stop critisizing my tutorial. I'm sure you wouldn't like it if you had a NPC scripting tutorial and someone started saying your work was ugly and unorganized.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

1. A custom quest ID for a quest you made compeltly by yourself? I'm sorry, I haven't heard or done that before. I've just started playing private servers again so I haven't seen any servers do that either. Most people just make the NPC require you to get an item and check for the item.
Ah, ok. I just saw that cm.startQuest and wondered.

2. I'm not sure what you mean. You mean the kind of NPC that says stuff already and even if you add a script it won't change? Explain a little more.
I've seen vids of people reusing NPCs for different purposes. For example, the Mu Lung storage NPC was placed on another map and summoned bosses for people to train on. I don't know if the original storage keeper still worked normally, but obviously someone could change what the NPC did. (The point is, if the last part is true, how do you code an NPC to do one thing on one map, and do another thing on another map?)

I don't know, I don't even know where to place the script after it's finished, or how to specify which NPC uses it. :?: Though, because my private server isn't up yet, I can't even test the 4 or so scripts I have had time to write.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Ah, ok. I just saw that cm.startQuest and wondered.


I've seen vids of people reusing NPCs for different purposes. For example, the Mu Lung storage NPC was placed on another map and summoned bosses for people to train on. I don't know if the original storage keeper still worked normally, but obviously someone could change what the NPC did. (The point is, if the last part is true, how do you code an NPC to do one thing on one map, and do another thing on another map?)

I don't know, I don't even know where to place the script after it's finished, or how to specify which NPC uses it. :?: Though, because my private server isn't up yet, I can't even test the 4 or so scripts I have had time to write.

if (cm.getPlayer().getMapId() == mapid) {

credits: moogra lol
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Good job leeching from GameCheetah. I saw this exact guide on gamecheetah. If your going to steal someones guide atleast give credits.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

hey uuh. how make a script.. notpad?
or w/e its java script right?

Edit: i maked one whit notepad but how let it work
i have only my notpad (where to put)
 
Last edited:
Re: [Tut] Learning NPC scripts (beginner's guide)

@ Tropicano-Marc

You can make a script on nearly anything. Including regular Notepad. Save it as a .js file and put it in your scripts > NPC folder and you're done :]

@ koldoleboy

To be honest. I have no idea. I tried search some info. on it and this is what I found:

I managed to find a few scripts that actually checked for AP. Whether this works or not is completely unknown to me. I could not find it in the NPCCommandProcessor.java but you could try.

In the scripts they used:
PHP:
p.getStr() // checks for Str (Same applys to Dex,Int,and Luk
PHP:
p.setStr() // sets Str (Same applys to Dex,Int and Luk

Bascially the same sort of thing with cm. commands except it had p. All the scripts I could find used this. The only reason I'm IFing it is because I couldn't find it in the repacks. Good Luck tell me if this works or not. Somebody else will probably reply with a better answer or agree with this.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Hey there I got problem and I hope you guys can help me out.

I need a code for a NPC to warp players somewhere BUT they need a certain level to get warped.

this is what I need,
- If a player is level 120 then he/she gets warped to map ("xxx")
- If a player is BELOW level 120 he/she gets warped to FM("910000000")

Can someone help me out?

Kind regards,
Frank
 
Re: [Tut] Learning NPC scripts (beginner's guide)

PHP:
var status = 0;
var mapxxx = 1000000;
var fm = 910000000;

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("Alright, see you next time.");
			cm.dispose();
			return;
		}
		if (mode == 1) {
			status++;
		}
		else {
			status--;
		}
		if (status == 0) {
			if(cm.getLevel() >= 120) {
			cm.sendNext("You're gonna be warped to map xxx.");
			status = 9;
			} else if (cm.getLevel() < 120) {
			cm.sendNext("You're not Level 120 yet,so you'll be warped to FM!");
			status = 11;
			}
		} else if (status == 10) {
		cm.warp(mapxxx);
		cm.dispose();
		} else if (status == 12) {
		cm.warp(fm);
		cm.dispose();
		}
	}
  }

I'm a freaking bit rusty at scripting,lol. Test if it works and if not,post me the bat error.
 
Last edited:
Status
Not open for further replies.
Back