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

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

haha no nid
and now i have another prob.the script i have,i can even exchange the wizet invincible hat even with 1 2000005!!!!i am suppose to do i such that i need 2000 '2000005's.i wan the script to be that i i have only 1 '2000005',i cannot exchange and the npc will reply 'you do not have enough 2000005s'.i think it needs this:
Code:
if(cm.haveItem(200005 >= 2000)){
          cm.gainItem(2000005, -2000);
          cm.gainItem(WIZET INVINCIBLE HAT ID, 1);
          cm.dispose();
}
else cm.sendOk("You do not have enough 2000005s");
cm.dispose();
i tried this but it did not work.
 
Re: [Guide] Learning NPC scripts (beginner's guide)

PHP:
if(cm.haveItem(200005, 2000))


Anyway, get31372.. I'm still waiting for your explanation Mr pro.:):
 
Re: [Guide] Learning NPC scripts (beginner's guide)

wow, wonderful job
GREAT guide
this actually helped me out a bit
 
Re: [Guide] Learning NPC scripts (beginner's guide)

PHP:
if(cm.haveItem(200005, 2000))


Anyway, get31372.. I'm still waiting for your explanation Mr pro.:):
thanks!haha another prob now..
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("Alright, see you next time.");
			cm.dispose();
			return;
		}
		if (mode == 1)
			status++;
		else
			status--;
		if (status == 0) {
			cm.sendNext("Hi #r#h ##k, I'm the #bItems#k Exchanger! ");
		} else if (status == 1) {
			cm.sendAcceptDecline("Click accept")
		} else if (status == 2) {
			if (cm.haveItem(2000005)) {
				cm.sendNext("Great, you have a 2000005");
			}
		} else if (status == 3) {
			cm.sendSimple("What would you like to exchange?\r\n#L0##bWizet Invincible Hat#k(#r2000 pwr elixirs#k)#l\r\n#L1# elixirs 30000(#r1 pwr elixir#k)#l\r\n#L2#Crystal Ilbi 1 Set(#r1 pwr elixir#k)#l");
		} else if(status == 4) {
			if (selection == 0) { 
				cm.sendYesNo("Are you sure you want to exchange #bWizet Invincible Hat#k?");
			}
			else if (selection == 1) {
				cm.sendYesNo("Are you sure you want to exchange #b30000 Power Elixirs#k?");	
			}
			else if (selection == 2) {
				cm.sendOk("There you have it!");
				cm.gainItem(2070016, 1);
				cm.gainItem(2000005, -1);
				cm.dispose();	
			}
		} else if(status == 5) {
			if(cm.haveItem(2000005, 2000)){
				if(cm.haveItem(1002140)){
					cm.sendOk("You already have a #bWizet Invincible hat#k !! Why would you need one more?And,thanks for the #rpwr elixirs!");
					cm.gainItem(2000005, -10000);
					cm.dispose();
				}
				else cm.sendOk("There you have it!");
				cm.gainItem(1002140, 1);
				cm.gainItem(2000005, -2000);
				cm.dispose();
			}
			else cm.sendOk("You do not have enough pwr elixirs");
			cm.dispose();
		} else if(status == 6) {
				cm.sendOk("Here's your #b30000 Elixirs#k!");
				cm.gainItem(2000004, 30000);
				cm.gainItem(2000005, -1);
				cm.dispose();
		}
	}
}
when i click 'Yes' in "Are you sure you want to exchange 30000 Elixirs?" it brings me to the WIZET INVINCIBLE HAT THING!!!pls help to solve this prob.
 
Re: [Guide] Learning NPC scripts (beginner's guide)

@get31720

about ur guide
er i think you have a typo here:
gainNX
Gives/Takes the player nx
How to use: gm.gainNX([amount]); <---is it gm.gainNX or cm.gainNX
Make it negative to make it take away.
 
Re: [Guide] Learning NPC scripts (beginner's guide)

@get31720

about ur guide
er i think you have a typo here:
gainNX
Gives/Takes the player nx
How to use: gm.gainNX([amount]); <---is it gm.gainNX or cm.gainNX
Make it negative to make it take away.

@your script

I rushed a bit, I have to leave. If it doesn't work tell me I might have missed something.

PHP:
var status = 0;
var choice = 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("Alright, see you next time.");
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
        if (status == 0) {
            cm.sendNext("Hi #r#h ##k, I'm the #bItems#k Exchanger!");
        } 
        else if (status == 1) {
            cm.sendAcceptDecline("Click accept");
        } 
        else if (status == 2) {
            if (cm.haveItem(2000005)) {
                cm.sendNext("Great, you have a 2000005");
            }
            else {
                cm.sendOk("Get pwr elixirs before talking to me.");
                cm.dispose();
            }
        } 
        else if (status == 3) {
            cm.sendSimple("What would you like to exchange?\r\n#L0##bWizet Invincible Hat#k(#r2000 pwr elixirs#k)#l\r\n#L1# elixirs 30000(#r1 pwr elixir#k)#l\r\n#L2#Crystal Ilbi 1 Set(#r1 pwr elixir#k)#l");
        } 
        else if(status == 4) {
            if (selection == 0) { 
                cm.sendYesNo("Are you sure you want to exchange #bWizet Invincible Hat#k?");
                choice = 1;
            }
            else if (selection == 1) {
                cm.sendYesNo("Are you sure you want to exchange #b30000 Power Elixirs#k?"); 
                choice = 2;   
            }
            else if (selection == 2) {
                cm.sendOk("There you have it!");
                cm.gainItem(2070016, 1);
                cm.gainItem(2000005, -1);
                cm.dispose();    
            }
        } 
        else if(status == 5) {
            if (choice == 1) {
                if(cm.haveItem(2000005, 2000) && cm.haveItem(1002140)) {
                    cm.sendOk("You already have a #bWizet Invincible hat#k !! Why would you need one more?And,thanks for the #rpwr elixirs!");
                    cm.gainItem(2000005, -10000);
                    cm.dispose();
                }
                else if (cm.haveItem(2000005, 2000)) {
                    cm.sendOk("There you have it!");
                    cm.gainItem(1002140, 1);
                    cm.gainItem(2000005, -2000);
                    cm.dispose();
                }
                else { 
                    cm.sendOk("You do not have enough pwr elixirs");
                    cm.dispose();
                }
            }
            else if (choice == 2) {
                cm.sendOk("Here's your #b30000 Elixirs#k!");
                cm.gainItem(2000004, 30000);
                cm.gainItem(2000005, -1);
                cm.dispose();
            }
        }
    }
}
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Hey I made a script for when you rebirth, you talk to an NPC and they give you level 0 clothes. This is what I made so far, but it only goes to the first part of the text and not the next can you see what is wrong with it?


PHP:
var wui = 0;

function start() {
    cm.sendNext ("Hello, if you have just rebirthed and do not got level 0 equipment, press next to get them.");
}

function action(mode, type, selection) {
    cm.dispose();
    if (selection == 0) {
        cm.gainItem(1102041,1);
        cm.gainItem(1002357,1);
        cm.gainItem(1442018,1);
        cm.gainItem(1442039,1);
        
        cm.sendOk ("Ok, let the training begin!");
    }
}


Also I made this of the same thing but the NPC just don't open for this.

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("Bye");   
            cm.dispose();   
            return;   
        }  
   
        if (mode == 1) {  
            status++;  
        }      
        else {  
            status--;  
        } 

        if (status == 2) { 
            cm.sendNext("#bHello #h#, Welcome to FallenStory. If you have rebirthed and you DO NOT got a level 0 weapon or Level 0 armour, click "Next" to get a Begginers items.#b");
        }
        else if (status == 3) {
           cm.sendNextPrev("#d#eHere you go.#e#d \r\n\r\n#b#eThis is what you will get..#e#b \r\n#i<1040002>#     #i<1060002>#     #i<1072005>#     #i<1302000>#");
           cm.gainItem(1040002,1)
           cm.gainItem(1060002,1)
           cm.gainItem(1072005,1)
           cm.gainItem(1302000,1)
           cm.dispose();
        }
    }
}
 
Re: [Guide] Learning NPC scripts (beginner's guide)

@ Jackles

First one you didn't use #L0#selection#l to make a selection

Second one change the status == 2 to a status == 0 and the status == 3 to a status == 1
You also forgot semi colons (;) at the end of the gainItem lines
 
Re: [Guide] Learning NPC scripts (beginner's guide)

Like this?

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("Bye");   
            cm.dispose();   
            return;   
        }  
   
        if (mode == 1) {  
            status++;  
        }      
        else {  
            status--;  
        } 

        if (status == 0) { 
            cm.sendNext("#bHello #h#, Welcome to FallenStory. If you have rebirthed and you DO NOT got a level 0 weapon or Level 0 armour, click "Next" to get a Begginers items.#b");
        }
        else if (status == 1) {
           cm.sendNextPrev("#d#eHere you go.#e#d \r\n\r\n#b#eThis is what you will get..#e#b \r\n#i<1040002>#     #i<1060002>#     #i<1072005>#     #i<1302000>#");
           cm.gainItem;(1040002,1)
           cm.gainItem;(1060002,1)
           cm.gainItem;(1072005,1)
           cm.gainItem;(1302000,1)
           cm.dispose();
        }
    }
}
 
Re: [Guide] Learning NPC scripts (beginner's guide)

hello i got an question hopw to give the npc a id nummer and a name
 
Re: [Guide] Learning NPC scripts (beginner's guide)

It still didn't work. I moved the semi colon to here instead "cm.gainItem(1302000,1);"
 
Re: [Guide] Learning NPC scripts (beginner's guide)

@ Jackles
PHP:
var mysterious;

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

function action(cake, type, selection) {
	if (cake == 1)
		mysterious++;
	else {
		cm.dispose();
		return;
	}
	
	if (mysterious == 0)
		cm.sendNext("Hello, if you have just rebirthed and do not got level 0 equipment, press next to get them.");
	else {
		var items = new Array(1102041, 1002357, 1442018, 1442039);
		for (var i = 0; i < items.length; i++)
			cm.gainItem(items[i], 1);
        cm.sendOk ("Ok, let the training begin!");
		cm.dipose();
    }
}

@ priest
PHP:
var status;
var choice;

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

function action(mode, type, selection) {
    if (mode == 1)
         status++;
    else if (mode == -1) {
		cm.dispose();
		return;
	} else { // mode == 0 is the only possible thing in our case.
		cm.sendOk("Alright, see you next time.");
		cm.dispose();
	}
		
        if (status == 0) {
            cm.sendNext("Hi #r#h ##k, I'm the #bItems#k Exchanger! ");
        } else if (status == 1) {
            cm.sendAcceptDecline("Click accept")
        } else if (status == 2) {
            if (cm.haveItem(2000005))
                cm.sendNext("Great, you have a 2000005");
            else {
				cm.sendNext("MrMysterious is awesome <3.\r\n\r\nYou do not have a #v2000005#");
				cm.dispose();
			}
        } else if (status == 3) {
            cm.sendSimple("What would you like to exchange?\r\n#L0##bWizet Invincible Hat#k(#r2000 pwr elixirs#k)#l\r\n#L1# elixirs 30000(#r1 pwr elixir#k)#l\r\n#L2#Crystal Ilbi 1 Set(#r1 pwr elixir#k)#l");
        } else if(status == 4) {
			choice = selection;
            if (selection == 0) {
                cm.sendYesNo("Are you sure you want to exchange #bWizet Invincible Hat#k?");
            } else if (selection == 1) {
                cm.sendYesNo("Are you sure you want to exchange #b30000 Power Elixirs#k?");    
            } else if (selection == 2) {
                cm.sendOk("There you have it!");
                cm.gainItem(2070016, 1);
                cm.gainItem(2000005, -1);
                cm.dispose();    
            }
        } else if (status == 5) {
			switch (choice) {
				case 0:
						if (cm.haveItem(2000005, 2000)) {
							if (cm.haveItem(1002140))
								cm.sendOk("You already have a #bWizet Invincible hat#k !! Why would you need one more? And,thanks for the #rpwr elixirs!");
							else {
								cm.gainItem(1002140, 1);
								cm.sendOk("There you have it!");
							}
							cm.gainItem(2000005, -10000);
						} else
						cm.sendOk("You do not have enough pwr elixirs");
						cm.dispose();
					break;
				case 1:
						if (cm.haveItem(2000005)) {
							cm.gainItem(2000004, 30000);
							cm.gainItem(2000005, -1);
							cm.sendOk("Here's your #b30000 Elixirs#k!");
						} else
							cm.sendNext("MrMysterious is awesome <3.\r\n\r\nYou do not have a #v2000005#"); // Yeah I know, we made a check earlier but I like my name to be everything <3 LOL
							cm.dispose();
        }
    }
}
 
Re: [Guide] Learning NPC scripts (beginner's guide)

hello i got an question hopw to give the npc a id nummer and a name

You can't give or change an NPCs ID or name. You can get them by using a GM handbook, !id in game, or mapletip.com
 
Status
Not open for further replies.
Back