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

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

I don't understand what the mode means.

Like in here,

Code:
    if (mode == -1) {
 
Re: [Tut] Learning NPC scripts (beginner's guide)

/* Cody
*/

importPackage(net.sf.odinms.client);

var status = 0;
var job;

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

function action(mode, type, selection) {
if (mode == -1) {
cm.dispose();
} else {
if (mode == 1)
status++;
else
status--;
if (status == 0) {
cm.sendOK("Hello. I'm Cody. Nice to meet you! =)");
cm.dispose();
return;
}
}
}

This is cody script ,
when i replace with another script .
It won't update to my new script .(v75 arberms)
Last time i host using v62 , it will always auto update the scripts even the server is running .
How to solve it ? ty :O:
 
Re: [Tut] Learning NPC scripts (beginner's guide)

This is cody script ,
when i replace with another script .
It won't update to my new script .(v75 arberms)
Last time i host using v62 , it will always auto update the scripts even the server is running .
How to solve it ? ty :O:

This is because Cody can't be changed in v75. Neither can the Maple Administrator.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Something is wrong in my script oO The selection 0 part doesn't work the other part does help xD?
Code:
var status = 0;
function start() {
	status = -1;
	action(1, 0, 0);
}
function action(mode, type, selection) {
	if (mode == 1) {
		status++;
	}else{
		status--;
	}

	if (status == 0) {
		cm.sendSimple("Hey there. would you like to \r\n#L0# Trade 1 billion mesos for a tetris piece#l  \r\n or \r\n #L1#Trade a tetris piece for 1 billion mesos#l");
	}else if (status == 1){
		if (selection == 0) {
			if (cm.getMesos() >= 1000000000){
				cm.sendOk("Congratz! succesfull trade!");
				cm.gainItem(4030002, 1);
				cm.gainMesos(-1000000000);
				cm.dispose();			
			}else{
				cm.sendOk("You don't have enough mesos! Go hunt more :D");
				cm.dispose();
			}
		}else if (selection == 1) {
			if (cm.haveItem(4030002) >= 1) {
				cm.sendOk("Congratz! succesfull trade!");
				cm.gainItem(4030002, -1);
				cm.gainMesos(1000000000);
				cm.dispose();
			}else{
				cm.sendOk("You dont have a tetris piece! Go hunt mesos :D");
				cm.dispose();
			}
		}
	}
}
 
Last edited:
Re: [Tut] Learning NPC scripts (beginner's guide)

HEY! i am new here :3 and new to making a sever.. and i folowed you giude. it is good.. but.. i created v55 and when i click my npc, it is not opening anything.... i did a super rebirth with your guides.. can you edit it for me?
link :
:
 
Re: [Tut] Learning NPC scripts (beginner's guide)

HEY! i am new here :3 and new to making a sever.. and i folowed you giude. it is good.. but.. i created v55 and when i click my npc, it is not opening anything.... i did a super rebirth with your guides.. can you edit it for me?
link :
:
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Nice job made about 3 npc's from scratch with this, took me a while though anyways nice job :).





If god was a dj, life was a dance floor, rhythem was the love, then we are the music.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

nice explanation...im still learning the basics, i'm trying to add more lines to this...ive tried...and one way i tried it d/c'ed me f6...lol, so if you or anyone could help explain how to do that to me...it would be greatly appreaciated.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

I get an Auto-DC when I talk to Thomas Swift with this code. Can anyone help please?

PHP:
// Thomas Swift [Heneseys] / [Amoria]

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 && status == 1) {
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
            if (status == 0) {
				if (cm.getPlayer().getMapId() == 100000000){
					cm.sendYesNo("Hi there, would you like to goto Amoria?");
					} else if (status == 1){
						cm.sendSimple("Alright then, enjoy your stay there. Come back to me from there if you want to ever head back.");
						cm.warp(680000000, 0);
						cm.dispose();
						} else {
						cm.sendOk("Ok then. Come back when you are interested.");
						cm.dispose();
						}
				if (cm.getPlayer().getMapId() == 680000000){
					cm.sendYesNo("Hey, would you like to go back to Henesys?");
					} else if (status == 2){
						cm.sendSimple("Alright then, I will take you back.");
						cm.warp(100000000, 0);
						cm.dispose();
						} else {
						cm.sendOk("Ok, come back whenever you want to leave.");
						cm.dispose();
						}
				}
				}
			}
 
Re: [Tut] Learning NPC scripts (beginner's guide)

I get an Auto-DC when I talk to Thomas Swift with this code. Can anyone help please?

PHP:
// Thomas Swift [Heneseys] / [Amoria]

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 && status == 1) {
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
            if (status == 0) {
				if (cm.getPlayer().getMapId() == 100000000){
					cm.sendYesNo("Hi there, would you like to goto Amoria?");
					} else if (status == 1){
						cm.sendSimple("Alright then, enjoy your stay there. Come back to me from there if you want to ever head back.");
						cm.warp(680000000, 0);
						cm.dispose();
						} else {
						cm.sendOk("Ok then. Come back when you are interested.");
						cm.dispose();
						}
				if (cm.getPlayer().getMapId() == 680000000){
					cm.sendYesNo("Hey, would you like to go back to Henesys?");
					} else if (status == 2){
						cm.sendSimple("Alright then, I will take you back.");
						cm.warp(100000000, 0);
						cm.dispose();
						} else {
						cm.sendOk("Ok, come back whenever you want to leave.");
						cm.dispose();
						}
				}
				}
			}

Not 100% sure, but you can try this...

PHP:
// Thomas Swift [Heneseys] / [Amoria] 

var hene = 0;
var amor = 0;

function start() {
    if (cm.getPlayer().getMapId() == 100000000) {
        cm.sendYesNo("Hi there, would you like to goto Amoria?");
		hene == 1;
	} else if (cm.getPlayer().getMapId() == 680000000) {
		cm.sendYesNo("Hey, would you like to go back to Henesys?");
		amor == 1;
	}else{
		cm.sendOk("I'm doing good here.");
		cm.dispose();
	}
}

function action(mode, type, selection) {
    if (mode > 0) {
		if (hene == 1) {
			cm.sendOk("Alright then, enjoy your stay there. Come back to me from there if you want to ever head back.");
			cm.warp(680000000, 0);
		} else if (amor == 1) {
			cm.sendOk("Alright then, I will take you back.");
			cm.warp(100000000, 0);
		}else{
			cm.sendOk("Ok then. Come back when you are interested.");
		}
		cm.dispose();
    }
}
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Didn't work, but then I am trying this with selections.. Would this work?:

PHP:
var status = 0;
var AMORIA = 0;
var HENESYS = 0;

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

function action(mode, type, selection) {
    if (mode == -1) {
		cm.sendSimple("Alright then, come back later when you want to.");
        cm.dispose();
    } else {
        if (mode == 0 && status == 1) {
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
            if (status == 0) {
				HENESYS++;
				if ((cm.getPlayer().getMapId() == 100000000) && (HENESYS == 1)){
				cm.sendSimple("Would you like to goto Amoria? \r\n#L0#Yes#l \r\n#L0L1#No#l");
					switch(selection){
					case 0:
					status++;
					cm.sendSimple("Alright, then I will take you there");
					AMORIA++;
					HENESYS--;
					cm.dispose();
					break;
					case 1:
					status++;
					cm.sendSimple("Alright then come back when you want to.");
					cm.dispose();
					break;
					}
					
				
				} else if ((cm.getPlayer().getMapId() == 680000000) && (AMORIA == 1)){
				cm.sendSimple("Hey! Would you like to go back to Henesys now? \r\n#L0#Yes#l \r\n#L0L1#No#l");
					switch(selection){
					case 0:
					status++;
					cm.sendSimple("Alright, I will take you back then");
					AMORIA--;
					HENESYS++;
					cm.dispose();
					break;
					case 1:
					status++;
					cm.sendSimple("Alright, then come back when you want to.");
					cm.dispose();
					}
				}
				}
			}
	}
 
Last edited:
Re: [Tut] Learning NPC scripts (beginner's guide)

Didn't work, but then I am trying this with selections.. Would this work?:

PHP:
var status = 0;
var AMORIA = 0;
var HENESYS = 0;

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

function action(mode, type, selection) {
    if (mode == -1) {
		cm.sendSimple("Alright then, come back later when you want to.");
        cm.dispose();
    } else {
        if (mode == 0 && status == 1) {
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
            if (status == 0) {
				HENESYS++;
				if ((cm.getPlayer().getMapId() == 100000000) && (HENESYS == 1)){
				cm.sendSimple("Would you like to goto Amoria? \r\n#L0#Yes#l \r\n#L0L1#No#l");
					switch(selection){
					case 0:
					status++;
					cm.sendSimple("Alright, then I will take you there");
					AMORIA++;
					HENESYS--;
					cm.dispose();
					break;
					case 1:
					status++;
					cm.sendSimple("Alright then come back when you want to.");
					cm.dispose();
					break;
					}
					
				
				} else if ((cm.getPlayer().getMapId() == 680000000) && (AMORIA == 1)){
				cm.sendSimple("Hey! Would you like to go back to Henesys now? \r\n#L0#Yes#l \r\n#L0L1#No#l");
					switch(selection){
					case 0:
					status++;
					cm.sendSimple("Alright, I will take you back then");
					AMORIA--;
					HENESYS++;
					cm.dispose();
					break;
					case 1:
					status++;
					cm.sendSimple("Alright, then come back when you want to.");
					cm.dispose();
					}
				}
				}
			}
	}

Try this

PHP:
// Thomas Swift [Heneseys] / [Amoria]  

function start() {
    if (cm.getPlayer().getMapId() == 100000000) {
        cm.sendYesNo("Hi there, would you like to goto Amoria?");
    } else if (cm.getPlayer().getMapId() == 680000000) {
        cm.sendYesNo("Hey, would you like to go back to Henesys?");
    }else{
        cm.sendOk("I'm doing good here.");
        cm.dispose();
    }
}

function action(mode, type, selection) {
    if (mode > 0) {
        cm.sendOk("Alright then, enjoy your stay there. Come back to me from there if you want to ever head back.");
        cm.warp(680000000, 0);
    else{
        cm.sendOk("Alright then, I will take you back.");
        cm.warp(100000000, 0);
    }
        cm.dispose();
    }else{
		cm.sendOk("Ok then. Come back when you are interested.");
		cm.dispose();
	}
}

Remember to @dispose yourself.
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Hey, I read this and it helped a LOT. Made my first NPC, and it worked ^^

But I tried making a second, and I can't click on the NPC. I tried editing it alot, nothing.

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("Hey, I exchange mesos for items!\r\n#b#L0#I want to exchange one billion mesos for one #i4031545##l");
			cm.sendDispose();
		}
		if (selection == 0) {
			cm.sendOk("Are you sure you want to trade?");
			cm.getMeso(1000000000);
		}
		else {
			cm.sendOk("You don't have enough mesos.");
			cm.dispose();
		}
	else if (status == 1) {
		if (selection == 0) {
			if (cm.getMeso(1000000000));
				cm.gainItem(4031545, 1);
				cm.gainMeso(-1000000000);
				cm.dispose(); 
			}
		}
	}
}

What did I do wrong, I know it's something with the elses and if's when I got to the selections....

Please and thanks!
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Hey, I read this and it helped a LOT. Made my first NPC, and it worked ^^

But I tried making a second, and I can't click on the NPC. I tried editing it alot, nothing.

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("Hey, I exchange mesos for items!\r\n#b#L0#I want to exchange one billion mesos for one #i4031545##l");
			cm.sendDispose();
		}
		if (selection == 0) {
			cm.sendOk("Are you sure you want to trade?");
			cm.getMeso(1000000000);
		}
		else {
			cm.sendOk("You don't have enough mesos.");
			cm.dispose();
		}
	else if (status == 1) {
		if (selection == 0) {
			if (cm.getMeso(1000000000));
				cm.gainItem(4031545, 1);
				cm.gainMeso(-1000000000);
				cm.dispose(); 
			}
		}
	}
}

What did I do wrong, I know it's something with the elses and if's when I got to the selections....

Please and thanks!

http://forum.ragezone.com/f566/help-npc-script-674785/#post5759081
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Hey,

I really liked your tutorial and it helped me out alot. But when I try to add the script into a npc, i get an error that says : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntac to use near 'var status = 1' at line 1
I got this even with the simple npc you made, so it can't be the script!?
I hope you guys can help me =)
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Heey I cant get this script to work, can you guys help me??

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 && status == 0) {
cm.dispose();
return;
}
if (mode == 1)
status++;
else
status--;
if (status == 0) {
cm.sendYesNo("I can make you a Female... LOL. Are you ready? (Remember THAT you need to Change Channel, That Way the Sex Transfer Will Be Succesfull)");
} else if (status == 1) {
if (cm.getMeso() >= 20000000);
cm.gainMeso(-20000000);
cm.getChar().setGender(1);
cm.sendOk("Alright, we're done.");
cm.dispose();
else
cm.sendOk("You don't have enough mesos")
cm.dispose();
}
}
}
 
Re: [Tut] Learning NPC scripts (beginner's guide)

Heey I cant get this script to work, can you guys help me??

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 && status == 0) {
cm.dispose();
return;
}
if (mode == 1)
status++;
else
status--;
if (status == 0) {
cm.sendYesNo("I can make you a Female... LOL. Are you ready? (Remember THAT you need to Change Channel, That Way the Sex Transfer Will Be Succesfull)");
} else if (status == 1) {
if (cm.getMeso() >= 20000000);
cm.gainMeso(-20000000);
cm.getChar().setGender(1);
cm.sendOk("Alright, we're done.");
cm.dispose();
else
cm.sendOk("You don't have enough mesos")
cm.dispose();
}
}
}

PHP:
function start() {
	cm.sendYesNo("I can make you a Female... LOL. Are you ready? (Remember THAT you need to Change Channel, That Way the Sex Transfer Will Be Succesfull)");
}

function action(mode, type, selection) {
	if (mode == -1) {
		cm.dispose();
		return;
	} else if (mode == 0) {
		cm.sendOk("Alright, come back when you change your mind.");
		cm.dispose();
	}else{
		if (cm.getMeso() >= 20000000) {
			cm.gainMeso(-20000000);
			cm.getChar().setGender(1);
			cm.sendOk("Alright, we're done.");
		}else{
			cm.sendOk("You don't have enough mesos");
		}
		cm.dispose();
	}
}
 
Status
Not open for further replies.
Back