NPC Script Issue

Newbie Spellweaver
Joined
Oct 2, 2012
Messages
82
Reaction score
0
Honestly, i'm not sure why this happens but everytime i click on the npc and i go to select where it says 15 Sleepy Dream for a cygnus weapon, and when i select a cygnus weapon, it doesn't do anything, even though i wrote the code for if selection == 7 etc.

Here's the NPC:
PHP:
importPackage(Packages.server);

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){
        cm.dispose();
		return;		
    } else {
        if (mode == 1)
            status++;
        else
            status--;
			if (status == 0) {
			cm.sendSimple("#e#bWelcome to the #kSleepy Dream NPC #bHere you can exchange your Sleepy Dreams for rewards."                     +
					"\r\n#L0##b  10 Sleepy Dream for 3 Dragon Spirit."         +
					"\r\n#L1##b  15 Sleepy Dream for Cygnas Weapons."         +
					"\r\n#L2##b  35 Sleepy Dream for Spectrum Goggles +1000 All Stat and +1000 Watk/Matk."         +
					"\r\n#L3##b  25 Sleepy Dream for 10,000NX and 5 JQ Point."         +
					"\r\n#L4##b  40 Sleepy Dream for Clear/Transparent Chair."         +
					"\r\n#L5##b  50 Sleepy Dream for 25 Gachapon Stamp."         +
					"\r\n#L6##b  60 Sleepy Dream for 1 Rare NX Item of your choice."            );
					
					}else if (selection == 0) {
      if (cm.haveItem(4001063,  10)) {   
          cm.gainItem(4001063, -10); 
		  cm.gainItem(4000244, 3);
		  cm.sendOk("Here are your 3 Dragon Spirit #i4000244");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 1) {
      if (cm.haveItem(4001063,  15)) {   
          cm.sendSimple("\r\n#L7##b  Guardian Of Irina: #i1702256\r\n"         +
					"\r\n#L8##b  Guardian Of Mihail: #i1702257\r\n"         +
					"\r\n#L9##b  Guardian Of Oz: #i1702258\r\n"         +
					"\r\n#L10##b  Guardian Of Hawkeye: #i1702259\r\n"         +
					"\r\n#L11##b  Guardian Of Ickart: #i1702260\r\n"         );
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		}else if (selection == 7) {
	  if (cm.haveItem(4001063, 15)) {
		cm.gainItem(4001063, -15);
		cm.gainItem(1702256, 1);
		cm.sendOk("Here is your Guardian Of Irina: #i1702256");
		
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		}else if (selection == 8) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
		  cm.gainItem(1702257, 1);
		  cm.sendOk("Here is your Guardian Of Mihail: #i1702257");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 9) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
		  cm.gainItem(1702258, 1);
		  cm.sendOk("Here is your Guardian Of Oz: #i1702258");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 10) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
		  cm.gainItem(1702259, 1);
		  cm.sendOk("Here is your Guardian Of Hawkeye: #i1702259");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 11) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
		  cm.gainItem(1702260, 1);
		  cm.sendOk("Here is your Guardian Of Ickart: #i1702260");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  }
		  }
		  }
 
You need multiple statuses. It's like this
if (status == 0) { cm.sendSimple(list); }
else if (status == 1) { if (selection == 0) { selection } if (selection == 1) {selection}}
else if (status == 2) ...
 
Upvote 0
ALotOfPosts is correct.

Every time that you make a selection, or press next on an NPC etc. the action method is called again, with mode, type and selection.
In the case of selcting option 7, it would call the action method with mode = 1, selection = 7

In your script, if mode = 1, status is increased :
if (mode == 1)
status++;

so you should have in your code:
Code:
if(status == 0){
//your current code
}else if(status == 1){
if(selection == 7){
 if (cm.haveItem(4001063, 15)) { 
        cm.gainItem(4001063, -15); 
        cm.gainItem(1702256, 1); 
        cm.sendOk("Here is your Guardian Of Irina: #i1702256"); 
         
    } else { 
          cm.sendOk("You don't have enough Sleepy Dreams.");
          cm.dispose(); 
           
        }
}
}

And do the same for all your other selections, because the same thing will happen with them.
 
Last edited:
Upvote 0
ALotOfPosts is correct.

Every time that you make a selection, or press next on an NPC etc. the action method is called again, with mode, type and selection.
In the case of selcting option 7, it would call the action method with mode = 1, selection = 7

In your script, if mode = 1, status is increased :
if (mode == 1)
status++;

so you should have in your code:
Code:
if(status == 0){
//your current code
}else if(status == 1){
if(selection == 7){
 if (cm.haveItem(4001063, 15)) { 
        cm.gainItem(4001063, -15); 
        cm.gainItem(1702256, 1); 
        cm.sendOk("Here is your Guardian Of Irina: [URL=http://forum.ragezone.com/usertag.php?do=list&action=hash&hash=i1702256]#i1702256[/URL] "); 
         
    } else { 
          cm.sendOk("You don't have enough Sleepy Dreams.");
          cm.dispose(); 
           
        }
}
}

And do the same for all your other selections, because the same thing will happen with them.

I tried what you told me and changed it to the code below, but still it doesn't go to selection 7..
PHP:
 importPackage(Packages.server);

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){
        cm.dispose();
		return;		
    } else {
        if (mode == 1)
            status++;
        else
            status--;
			if (status == 0) {
			cm.sendSimple("#e#bWelcome to the #kSleepy Dream NPC #bHere you can exchange your Sleepy Dreams for rewards."                     +
					"\r\n#L0##b  10 Sleepy Dream for 3 Dragon Spirit."         +
					"\r\n#L1##b  15 Sleepy Dream for Cygnas Weapons."         +
					"\r\n#L2##b  35 Sleepy Dream for Spectrum Goggles +1000 All Stat and +1000 Watk/Matk."         +
					"\r\n#L3##b  25 Sleepy Dream for 10,000NX and 5 JQ Point."         +
					"\r\n#L4##b  40 Sleepy Dream for Clear/Transparent Chair."         +
					"\r\n#L5##b  50 Sleepy Dream for 25 Gachapon Stamp."         +
					"\r\n#L6##b  60 Sleepy Dream for 1 Rare NX Item of your choice."            );
					
					}else if (selection == 0) {
      if (cm.haveItem(4001063,  10)) {   
          cm.gainItem(4001063, -10); 
		  cm.gainItem(4000244, 3);
		  cm.sendOk("Here are your 3 Dragon Spirit #i4000244");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 1) {
      if (cm.haveItem(4001063,  15)) {   
          cm.sendSimple("\r\n#L7##b  Guardian Of Irina: #i1702256\r\n"         +
					"\r\n#L8##b  Guardian Of Mihail: #i1702257\r\n"         +
					"\r\n#L9##b  Guardian Of Oz: #i1702258\r\n"         +
					"\r\n#L10##b  Guardian Of Hawkeye: #i1702259\r\n"         +
					"\r\n#L11##b  Guardian Of Ickart: #i1702260\r\n"         );
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		}else if (status == 1) {  
		if (selection == 7) {
	  if (cm.haveItem(4001063, 15)) {
		cm.gainItem(4001063, -15);
		cm.gainItem(1702256, 1);
		cm.sendOk("Here is your Guardian Of Irina: #i1702256");
		
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  }
}
}
}
 
Upvote 0
You have quite a few issues with your code. You actually need 3 statuses, and your curly braces are a bit wonkey.
This should work for you, but you will need to add in the code for the rest of the selections.
Code:
importPackage(Packages.server);


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){
        cm.dispose();
        return;        
    } else {
        if (mode == 1)
            status++;
        else
            status--;
            if (status == 0) {
            cm.sendSimple("#e#bWelcome to the #kSleepy Dream NPC #bHere you can exchange your Sleepy Dreams for rewards."                     +
                    "\r\n#L0##b  10 Sleepy Dream for 3 Dragon Spirit."         +
                    "\r\n#L1##b  15 Sleepy Dream for Cygnas Weapons."         +
                    "\r\n#L2##b  35 Sleepy Dream for Spectrum Goggles +1000 All Stat and +1000 Watk/Matk."         +
                    "\r\n#L3##b  25 Sleepy Dream for 10,000NX and 5 JQ Point."         +
                    "\r\n#L4##b  40 Sleepy Dream for Clear/Transparent Chair."         +
                    "\r\n#L5##b  50 Sleepy Dream for 25 Gachapon Stamp."         +
                    "\r\n#L6##b  60 Sleepy Dream for 1 Rare NX Item of your choice."            );
                    
            }else if(status == 1){
                if (selection == 0) {
                  if (cm.haveItem(4001063,  10)) {   
                      cm.gainItem(4001063, -10); 
                      cm.gainItem(4000244, 3);
                      cm.sendOk("Here are your 3 Dragon Spirit #i4000244");
                      
                } else {
                      cm.sendOk("You don't have enough Sleepy Dreams.");
                      cm.dispose();
                  }
                }else if (selection == 1) {
                  if (cm.haveItem(4001063,  15)) {   
                      cm.sendSimple("\r\n#L7##b  Guardian Of Irina: #i1702256\r\n"         +
                                "\r\n#L8##b  Guardian Of Mihail: #i1702257\r\n"         +
                                "\r\n#L9##b  Guardian Of Oz: #i1702258\r\n"         +
                                "\r\n#L10##b  Guardian Of Hawkeye: #i1702259\r\n"         +
                                "\r\n#L11##b  Guardian Of Ickart: #i1702260\r\n"         );
                      
                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.");
                          cm.dispose();
                    }
                } else{
                    //Either list more selections from the first 6, or you have reached an invalid selection
                }
            } else if(status == 2){
                 if (selection == 7) {
                  if (cm.haveItem(4001063, 15)) {
                    cm.gainItem(4001063, -15);
                    cm.gainItem(1702256, 1);
                    cm.sendOk("Here is your Guardian Of Irina: #i1702256");
                    
                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.") }
                          cm.dispose();
                    }
            }
        }
}

What you have to understand about how the NPC's work is that every time you make a selection or hit yes/next in an NPC window, the status is increased. By making selection 1 (status++), and then making selection 7(status++), your status is now at 2.
 
Last edited:
Upvote 0
Tbh I'm pritty lost atm.... This is the final code, could you edit it so that it would work ;o i'll look over your edits and understand if you could leave // next to your edits :) thanks XD sorry for being a bother.

PHP:
 importPackage(Packages.server);

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){
        cm.dispose();
		return;		
    } else {
        if (mode == 1)
            status++;
        else
            status--;
			if (status == 0) {
			cm.sendSimple("#e#bWelcome to the #kSleepy Dream NPC #bHere you can exchange your Sleepy Dreams for rewards."                     +
					"\r\n#L0##b  10 Sleepy Dream for 3 Dragon Spirit."         +
					"\r\n#L1##b  15 Sleepy Dream for Cygnas Weapons."         +
					"\r\n#L2##b  35 Sleepy Dream for Spectrum Goggles +1000 All Stat and +1000 Watk/Matk."         +
					"\r\n#L3##b  25 Sleepy Dream for 10,000NX and 5 JQ Point."         +
					"\r\n#L4##b  40 Sleepy Dream for Clear/Transparent Chair."         +
					"\r\n#L5##b  50 Sleepy Dream for 25 Gachapon Stamp."         +
					"\r\n#L6##b  60 Sleepy Dream for 1 Rare NX Item of your choice."            );
					
					}else if(status == 1){
					if (selection == 0) {
      if (cm.haveItem(4001063,  10)) {   
          cm.gainItem(4001063, -10); 
		  cm.gainItem(4000244, 3);
		  cm.sendOk("Here are your 3 Dragon Spirit #i4000244");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  }
		  }else if (selection == 1) {
      if (cm.haveItem(4001063,  15)) {   
          cm.sendSimple("\r\n#L7##b  Guardian Of Irina: #i1702256\r\n"         +
					"\r\n#L8##b  Guardian Of Mihail: #i1702257\r\n"         +
					"\r\n#L9##b  Guardian Of Oz: #i1702258\r\n"         +
					"\r\n#L10##b  Guardian Of Hawkeye: #i1702259\r\n"         +
					"\r\n#L11##b  Guardian Of Ickart: #i1702260\r\n"         );
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		
		 } else if(status == 2){	
		if (selection == 7) {
	  if (cm.haveItem(4001063, 15)) {
		cm.gainItem(4001063, -15);
		cm.gainItem(1702256, 1);
		cm.sendOk("Here is your Guardian Of Irina: #i1702256");
		
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  }
		  
		}else if (selection == 8) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
		  cm.gainItem(1702257, 1);
		  cm.sendOk("Here is your Guardian Of Mihail: #i1702257");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 9) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
		  cm.gainItem(1702258, 1);
		  cm.sendOk("Here is your Guardian Of Oz: #i1702258");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 10) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
		  cm.gainItem(1702259, 1);
		  cm.sendOk("Here is your Guardian Of Hawkeye: #i1702259");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 11) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
		  cm.gainItem(1702260, 1);
		  cm.sendOk("Here is your Guardian Of Ickart: #i1702260");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 2) {
      if (cm.haveItem(4001063,  35)) {   
          cm.gainItem(4001063, -35); 
		  cm.gainItem(1022082, 1);
		  Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "str", 1000);
            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "dex", 1000);
            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "int", 1000);
            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "luk", 1000);
			Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "watk", 1000);
			Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "matk", 1000);
		  cm.reloadChar();
		  cm.dispose();
		  cm.sendOk("Here are your Spectrum Goggles: #i1022082");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 3) {
      if (cm.haveItem(4001063,  25)) {   
          cm.gainItem(4001063, -25); 
		  cm.gainJqPoints(5);
		  cm.modifyNX(10000, 1);
		  cm.sendOk("You have Now Received 5 JQ Points and 10,000 NX");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 4) {
      if (cm.haveItem(4001063,  40)) {   
          cm.gainItem(4001063, -40); 
		  cm.gainItem(3010038, 1);
		  cm.sendOk("Here is your Transparent/Clear Chair #i3010038");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 5) {
      if (cm.haveItem(4001063,  50)) {   
          cm.gainItem(4001063, -50); 
		  cm.gainItem(4031408, 25);
		  cm.sendOk("Here are your 25 Gachapon Stamp. #i4031408");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 6) {
      if (cm.haveItem(4001063,  60)) {
		cm.sendSimple("#e#bPlease pick a #kRare NX Item #bPlease remember that their will be no refunds."                     +
					"\r\n#L11##b  Onmyouji Fan #i1702376\r\n"         +
					"\r\n#L12##b  Cat Hood Pink #i1003186\r\n"         +
					"\r\n#L13##b  Cat Hood Blue #i1003559\r\n"         +
					"\r\n#L14##b  Harmony Wings #i1102325\r\n"         +
					"\r\n#L15##b  Angelic Whispers #i1102326\r\n"         +
					"\r\n#L16##b  Bunny T-Shirt #i1048001\r\n"         +
					"\r\n#L17##b  Carrot T-Shirt #i1048002\r\n"            );

	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  
		  }else if (selection == 11) {
      if (cm.haveItem(4001063,  60)) {   
          cm.gainItem(4001063, -60); 
		  cm.gainItem(1702376, 1);
		  cm.sendOk("Here is your Onmyouji Fan #i1702376");
		  
	} else {
		  cm.sendOk("You don't have enough Sleepy Dreams.") }
		  cm.dispose();
		  }
		  }
		  }
 
Upvote 0
Tbh I'm pritty lost atm.... This is the final code, could you edit it so that it would work ;o i'll look over your edits and understand if you could leave // next to your edits :) thanks XD sorry for being a bother.

PHP:
 importPackage(Packages.server);

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){
        cm.dispose();
        return;        
    } else {
        if (mode == 1)
            status++;
        else
            status--;
            if (status == 0) {
            cm.sendSimple("#e#bWelcome to the #kSleepy Dream NPC #bHere you can exchange your Sleepy Dreams for rewards."                     +
                    "\r\n#L0##b  10 Sleepy Dream for 3 Dragon Spirit."         +
                    "\r\n#L1##b  15 Sleepy Dream for Cygnas Weapons."         +
                    "\r\n#L2##b  35 Sleepy Dream for Spectrum Goggles +1000 All Stat and +1000 Watk/Matk."         +
                    "\r\n#L3##b  25 Sleepy Dream for 10,000NX and 5 JQ Point."         +
                    "\r\n#L4##b  40 Sleepy Dream for Clear/Transparent Chair."         +
                    "\r\n#L5##b  50 Sleepy Dream for 25 Gachapon Stamp."         +
                    "\r\n#L6##b  60 Sleepy Dream for 1 Rare NX Item of your choice."            );
                    
                    }else if(status == 1){
                    if (selection == 0) {
      if (cm.haveItem(4001063,  10)) {   
          cm.gainItem(4001063, -10); 
          cm.gainItem(4000244, 3);
          cm.sendOk("Here are your 3 Dragon Spirit #i4000244");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          }
          }else if (selection == 1) {
      if (cm.haveItem(4001063,  15)) {   
          cm.sendSimple("\r\n#L7##b  Guardian Of Irina: #i1702256\r\n"         +
                    "\r\n#L8##b  Guardian Of Mihail: #i1702257\r\n"         +
                    "\r\n#L9##b  Guardian Of Oz: #i1702258\r\n"         +
                    "\r\n#L10##b  Guardian Of Hawkeye: #i1702259\r\n"         +
                    "\r\n#L11##b  Guardian Of Ickart: #i1702260\r\n"         );
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
        
         } else if(status == 2){    
        if (selection == 7) {
      if (cm.haveItem(4001063, 15)) {
        cm.gainItem(4001063, -15);
        cm.gainItem(1702256, 1);
        cm.sendOk("Here is your Guardian Of Irina: #i1702256");
        
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          }
          
        }else if (selection == 8) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
          cm.gainItem(1702257, 1);
          cm.sendOk("Here is your Guardian Of Mihail: #i1702257");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          
          }else if (selection == 9) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
          cm.gainItem(1702258, 1);
          cm.sendOk("Here is your Guardian Of Oz: #i1702258");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          
          }else if (selection == 10) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
          cm.gainItem(1702259, 1);
          cm.sendOk("Here is your Guardian Of Hawkeye: #i1702259");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          
          }else if (selection == 11) {
      if (cm.haveItem(4001063,  15)) {   
          cm.gainItem(4001063, -15); 
          cm.gainItem(1702260, 1);
          cm.sendOk("Here is your Guardian Of Ickart: #i1702260");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          
          }else if (selection == 2) {
      if (cm.haveItem(4001063,  35)) {   
          cm.gainItem(4001063, -35); 
          cm.gainItem(1022082, 1);
          Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "str", 1000);
            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "dex", 1000);
            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "int", 1000);
            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "luk", 1000);
            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "watk", 1000);
            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "matk", 1000);
          cm.reloadChar();
          cm.dispose();
          cm.sendOk("Here are your Spectrum Goggles: #i1022082");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          
          }else if (selection == 3) {
      if (cm.haveItem(4001063,  25)) {   
          cm.gainItem(4001063, -25); 
          cm.gainJqPoints(5);
          cm.modifyNX(10000, 1);
          cm.sendOk("You have Now Received 5 JQ Points and 10,000 NX");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          
          }else if (selection == 4) {
      if (cm.haveItem(4001063,  40)) {   
          cm.gainItem(4001063, -40); 
          cm.gainItem(3010038, 1);
          cm.sendOk("Here is your Transparent/Clear Chair #i3010038");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          
          }else if (selection == 5) {
      if (cm.haveItem(4001063,  50)) {   
          cm.gainItem(4001063, -50); 
          cm.gainItem(4031408, 25);
          cm.sendOk("Here are your 25 Gachapon Stamp. #i4031408");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          
          }else if (selection == 6) {
      if (cm.haveItem(4001063,  60)) {
        cm.sendSimple("#e#bPlease pick a #kRare NX Item #bPlease remember that their will be no refunds."                     +
                    "\r\n#L11##b  Onmyouji Fan #i1702376\r\n"         +
                    "\r\n#L12##b  Cat Hood Pink #i1003186\r\n"         +
                    "\r\n#L13##b  Cat Hood Blue #i1003559\r\n"         +
                    "\r\n#L14##b  Harmony Wings #i1102325\r\n"         +
                    "\r\n#L15##b  Angelic Whispers #i1102326\r\n"         +
                    "\r\n#L16##b  Bunny T-Shirt #i1048001\r\n"         +
                    "\r\n#L17##b  Carrot T-Shirt #i1048002\r\n"            );

    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          
          }else if (selection == 11) {
      if (cm.haveItem(4001063,  60)) {   
          cm.gainItem(4001063, -60); 
          cm.gainItem(1702376, 1);
          cm.sendOk("Here is your Onmyouji Fan #i1702376");
          
    } else {
          cm.sendOk("You don't have enough Sleepy Dreams.") }
          cm.dispose();
          }
          }
          }

I guess I'm feeling generous today. Here is what I have so far, should be obvious how to finish. Watch out for your curly braces where you are doing cm.sendOk("You don't ahve enough sleepy dreams) it should be a semicolon instead of the curly brace.

Here you go:
Code:
importPackage(Packages.server);


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){
        cm.dispose();
        return;        
    } else {
        if (mode == 1)
            status++;
        else
            status--;
            if (status == 0) {
            cm.sendSimple("#e#bWelcome to the #kSleepy Dream NPC #bHere you can exchange your Sleepy Dreams for rewards."                     +
                    "\r\n#L0##b  10 Sleepy Dream for 3 Dragon Spirit."         +
                    "\r\n#L1##b  15 Sleepy Dream for Cygnas Weapons."         +
                    "\r\n#L2##b  35 Sleepy Dream for Spectrum Goggles +1000 All Stat and +1000 Watk/Matk."         +
                    "\r\n#L3##b  25 Sleepy Dream for 10,000NX and 5 JQ Point."         +
                    "\r\n#L4##b  40 Sleepy Dream for Clear/Transparent Chair."         +
                    "\r\n#L5##b  50 Sleepy Dream for 25 Gachapon Stamp."         +
                    "\r\n#L6##b  60 Sleepy Dream for 1 Rare NX Item of your choice."            );
                    
            }else if(status == 1){
                if (selection == 0) {
                  if (cm.haveItem(4001063,  10)) {   
                      cm.gainItem(4001063, -10); 
                      cm.gainItem(4000244, 3);
                      cm.sendOk("Here are your 3 Dragon Spirit #i4000244");
                      
                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.");
                          cm.dispose();
                    }
                }else if (selection == 1) {
                  if (cm.haveItem(4001063,  15)) {   
                      cm.sendSimple("\r\n#L7##b  Guardian Of Irina: #i1702256\r\n"         +
                                "\r\n#L8##b  Guardian Of Mihail: #i1702257\r\n"         +
                                "\r\n#L9##b  Guardian Of Oz: #i1702258\r\n"         +
                                "\r\n#L10##b  Guardian Of Hawkeye: #i1702259\r\n"         +
                                "\r\n#L11##b  Guardian Of Ickart: #i1702260\r\n"         );
                      
                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.");
                          cm.dispose();
                    }
                 }else if(selection == 2){
                    if (cm.haveItem(4001063,  35)) {   
                          cm.gainItem(4001063, -35); 
                          cm.gainItem(1022082, 1);
                          Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "str", 1000);
                            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "dex", 1000);
                            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "int", 1000);
                            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "luk", 1000);
                            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "watk", 1000);
                            Packages.server.MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "matk", 1000);
                          cm.reloadChar();
                          cm.dispose();
                          cm.sendOk("Here are your Spectrum Goggles: #i1022082");
                          
                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.");
                          cm.dispose();
                    }
                }else if(selection == 3){
                     if (cm.haveItem(4001063,  25)) {   
                      cm.gainItem(4001063, -25); 
                      cm.gainJqPoints(5);
                      cm.modifyNX(10000, 1);
                      cm.sendOk("You have Now Received 5 JQ Points and 10,000 NX");
                      
                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.");
                          cm.dispose();
                          
                    }
                }else if(selection == 4){
                    if (cm.haveItem(4001063,  40)) {   
                          cm.gainItem(4001063, -40); 
                          cm.gainItem(3010038, 1);
                          cm.sendOk("Here is your Transparent/Clear Chair #i3010038");
                          
                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.");
                          cm.dispose();
                          
                    }
                }else if(selection == 5){
                    if (cm.haveItem(4001063,  50)) {   
                          cm.gainItem(4001063, -50); 
                          cm.gainItem(4031408, 25);
                          cm.sendOk("Here are your 25 Gachapon Stamp. #i4031408");
                          
                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.");
                          cm.dispose();
                    }
                }else if(selection == 6){
                    if (cm.haveItem(4001063,  60)) {
                        cm.sendSimple("#e#bPlease pick a #kRare NX Item #bPlease remember that their will be no refunds."                     +
                                    "\r\n#L11##b  Onmyouji Fan #i1702376\r\n"         +
                                    "\r\n#L12##b  Cat Hood Pink #i1003186\r\n"         +
                                    "\r\n#L13##b  Cat Hood Blue #i1003559\r\n"         +
                                    "\r\n#L14##b  Harmony Wings #i1102325\r\n"         +
                                    "\r\n#L15##b  Angelic Whispers #i1102326\r\n"         +
                                    "\r\n#L16##b  Bunny T-Shirt #i1048001\r\n"         +
                                    "\r\n#L17##b  Carrot T-Shirt #i1048002\r\n"            );


                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.");
                          cm.dispose();
                          
                    }
                }else{


                } // END FIRST 6 SELECTIONS
            } else if(status == 2){
                 if (selection == 7) {
                  if (cm.haveItem(4001063, 15)) {
                    cm.gainItem(4001063, -15);
                    cm.gainItem(1702256, 1);
                    cm.sendOk("Here is your Guardian Of Irina: #i1702256");
                    
                    } else {
                          cm.sendOk("You don't have enough Sleepy Dreams.");
                          cm.dispose();
                    }
                }else if(selection == 8){


                }else if(selection == 9){
                    
                }else if(selection == 10){
                    
                }else if(selection == 11){
                    //conflict here, selection 11 = both Guardian of Ickart selection, and  Onmyouji Fan selection
                }else if(selection == 12){
                    
                }else if(selection == 13){
                    
                }else if(selection == 14){
                    
                }else if(selection == 15){
                    
                }else if(selection == 16){
                    
                }else if(selection == 17){
                    
                }
        }
    }
 
Upvote 0
your code is extremely messy and hard to read. I don't know if pasting it here messed it up or if you just code like this but proper spaces and comments to explain what you did is the way to go.
so it turns out I have high ping in LoL so I actually spent some time for this.
I haven't executed your code but the issue was missing brackets.(or at least, 1 of the issues)
anyways here's a better version.
PHP:
importPackage(Packages.server); //Are you using Java 7? will throw an error in Java 8.

var status = -1;
var reqAmount = [10, 15, 35, 25, 40, 50, 60];
var cashItems = [1702376, 1003186, 1003559, 1102325, 1102326, 1048001, 1048002];
function start() {
	cm.sendSimple("#e#bWelcome to the #kSleepy Dream NPC #bHere you can exchange your Sleepy Dreams for rewards." +
				"\r\n#L0##b  10 Sleepy Dream for 3 Dragon Spirit." + //better take amount from array by using reqAmount[0/1/2/etc]
				"\r\n#L1##b  15 Sleepy Dream for Cygnus Weapons." +
				"\r\n#L2##b  35 Sleepy Dream for Spectrum Goggles +1000 All Stat and +1000 Watk/Matk." +
				"\r\n#L3##b  25 Sleepy Dream for 10,000NX and 5 JQ Point." +
				"\r\n#L4##b  40 Sleepy Dream for Clear/Transparent Chair." +
				"\r\n#L5##b  50 Sleepy Dream for 25 Gachapon Stamp." +
				"\r\n#L6##b  60 Sleepy Dream for 1 Rare NX Item of your choice.");
}

function action(mode, type, selection) {
	if (mode != 1){
        cm.dispose();
        return;        
    }
    status++;
    if (status == 0) {
        if (cm.haveItem(4001063,  reqAmount[selection])) {
			cm.gainItem(4001063, -reqAmount[selection]);
		} else {
			cm.sendOk("You don't have enough Sleepy Dreams.");
			cm.dispose();
			return;
		}
		//before rewarding make sure the player has enough space!
        switch (selection) {
			case 0:
				cm.gainItem(4000244, 3);
				break;
			case 1:
				cm.sendSimple("\r\n#L7##b  Guardian Of Irina: #i1702256\r\n" +
							"\r\n#L8##b  Guardian Of Mihail: #i1702257\r\n" +
							"\r\n#L9##b  Guardian Of Oz: #i1702258\r\n" +
							"\r\n#L10##b  Guardian Of Hawkeye: #i1702259\r\n" +
							"\r\n#L11##b  Guardian Of Ickart: #i1702260\r\n");
				return; //you don't want the reward message now.
			case 2:
				cm.gainItem(1022082, 1);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "str", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "dex", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "int", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "luk", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "watk", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "matk", 1000);
				cm.reloadChar(); //does that warp him to the map again while inside the npc? poor method. might get your character stuck and force a manual dispose.
				break;
			case 3:
				cm.gainJqPoints(5);
				cm.modifyNX(10000, 1);
				break;
			case 4:
				cm.gainItem(3010038, 1);
				break;
			case 5:
				cm.gainItem(4031408, 25);
				break;
			case 6:
				cm.sendSimple("#e#bPlease pick a #kRare NX Item #bPlease remember that their will be no refunds." +
							"\r\n#L0##b  Onmyouji Fan #i1702376\r\n" +
							"\r\n#L1##b  Cat Hood Pink #i1003186\r\n" +
							"\r\n#L2##b  Cat Hood Blue #i1003559\r\n" +
							"\r\n#L3##b  Harmony Wings #i1102325\r\n" +
							"\r\n#L4##b  Angelic Whispers #i1102326\r\n" +
							"\r\n#L5##b  Bunny T-Shirt #i1048001\r\n" +
							"\r\n#L6##b  Carrot T-Shirt #i1048002\r\n");
				return;
			default:
				cm.sendOk("I have nothing against this server, its SuperLol i do, hes always been a selfish bitchy, flaming cock sucking son of a *****, every one? knows that from his history of duping on moongrams. My main point is hes a selfish bastard.");
				cm.dispose();
				return;
		}
		cm.sendOk("Enjoy your rewards. Moongra had better ones.");
		cm.dispose();
    } else if (status == 1) {
		switch (selection) {
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
				cm.gainItem(cashItems[selection], 1);
				break;
			case 7:
			case 8:
			case 9:
			case 10:
			case 11:
				cm.gainItem((1702249 + selection) | 0, 1); // |0 because I don't remember if js throws exception for doing this. probably unnecessary
				break; 
			default:
				cm.sendOk("I swear your mother is so stupid. I saw your mother alway cut her pussy. The most stupid in the world.");
				cm.dispose();
				return;
		}
		cm.sendOk("Enjoy your rewards. Moongra had better ones.");
		cm.dispose();
	}
}





*not tested. might have syntax errors or something.
 
Upvote 0
your code is extremely messy and hard to read. I don't know if pasting it here messed it up or if you just code like this but proper spaces and comments to explain what you did is the way to go.
so it turns out I have high ping in LoL so I actually spent some time for this.
I haven't executed your code but the issue was missing brackets.(or at least, 1 of the issues)
anyways here's a better version.
PHP:
importPackage(Packages.server); //Are you using Java 7? will throw an error in Java 8.

var status = -1;
var reqAmount = [10, 15, 35, 25, 40, 50, 60];
var cashItems = [1702376, 1003186, 1003559, 1102325, 1102326, 1048001, 1048002];
function start() {
	cm.sendSimple("#e#bWelcome to the #kSleepy Dream NPC #bHere you can exchange your Sleepy Dreams for rewards." +
				"\r\n#L0##b  10 Sleepy Dream for 3 Dragon Spirit." + //better take amount from array by using reqAmount[0/1/2/etc]
				"\r\n#L1##b  15 Sleepy Dream for Cygnus Weapons." +
				"\r\n#L2##b  35 Sleepy Dream for Spectrum Goggles +1000 All Stat and +1000 Watk/Matk." +
				"\r\n#L3##b  25 Sleepy Dream for 10,000NX and 5 JQ Point." +
				"\r\n#L4##b  40 Sleepy Dream for Clear/Transparent Chair." +
				"\r\n#L5##b  50 Sleepy Dream for 25 Gachapon Stamp." +
				"\r\n#L6##b  60 Sleepy Dream for 1 Rare NX Item of your choice.");
}

function action(mode, type, selection) {
	if (mode != 1){
        cm.dispose();
        return;        
    }
    status++;
    if (status == 0) {
        if (cm.haveItem(4001063,  reqAmount[selection])) {
			cm.gainItem(4001063, -reqAmount[selection]);
		} else {
			cm.sendOk("You don't have enough Sleepy Dreams.");
			cm.dispose();
			return;
		}
		//before rewarding make sure the player has enough space!
        switch (selection) {
			case 0:
				cm.gainItem(4000244, 3);
				break;
			case 1:
				cm.sendSimple("\r\n#L7##b  Guardian Of Irina: #i1702256\r\n" +
							"\r\n#L8##b  Guardian Of Mihail: #i1702257\r\n" +
							"\r\n#L9##b  Guardian Of Oz: #i1702258\r\n" +
							"\r\n#L10##b  Guardian Of Hawkeye: #i1702259\r\n" +
							"\r\n#L11##b  Guardian Of Ickart: #i1702260\r\n");
				return; //you don't want the reward message now.
			case 2:
				cm.gainItem(1022082, 1);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "str", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "dex", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "int", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "luk", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "watk", 1000);
				MapleInventoryManipulator.editEquipById(cm.getPlayer(), 1, 1022082, "matk", 1000);
				cm.reloadChar(); //does that warp him to the map again while inside the npc? poor method. might get your character stuck and force a manual dispose.
				break;
			case 3:
				cm.gainJqPoints(5);
				cm.modifyNX(10000, 1);
				break;
			case 4:
				cm.gainItem(3010038, 1);
				break;
			case 5:
				cm.gainItem(4031408, 25);
				break;
			case 6:
				cm.sendSimple("#e#bPlease pick a #kRare NX Item #bPlease remember that their will be no refunds." +
							"\r\n#L0##b  Onmyouji Fan #i1702376\r\n" +
							"\r\n#L1##b  Cat Hood Pink #i1003186\r\n" +
							"\r\n#L2##b  Cat Hood Blue #i1003559\r\n" +
							"\r\n#L3##b  Harmony Wings #i1102325\r\n" +
							"\r\n#L4##b  Angelic Whispers #i1102326\r\n" +
							"\r\n#L5##b  Bunny T-Shirt #i1048001\r\n" +
							"\r\n#L6##b  Carrot T-Shirt #i1048002\r\n");
				return;
			default:
				cm.sendOk("I have nothing against this server, its SuperLol i do, hes always been a selfish bitchy, flaming cock sucking son of a *****, every one? knows that from his history of duping on moongrams. My main point is hes a selfish bastard.");
				cm.dispose();
				return;
		}
		cm.sendOk("Enjoy your rewards. Moongra had better ones.");
		cm.dispose();
    } else if (status == 1) {
		switch (selection) {
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
				cm.gainItem(cashItems[selection], 1);
				break;
			case 7:
			case 8:
			case 9:
			case 10:
			case 11:
				cm.gainItem((1702249 + selection) | 0, 1); // |0 because I don't remember if js throws exception for doing this. probably unnecessary
				break; 
			default:
				cm.sendOk("I swear your mother is so stupid. I saw your mother alway cut her pussy. The most stupid in the world.");
				cm.dispose();
				return;
		}
		cm.sendOk("Enjoy your rewards. Moongra had better ones.");
		cm.dispose();
	}
}





*not tested. might have syntax errors or something.

now that's how people should script their npc's! so beautiful and neat, +1 for you sir ;P
 
Upvote 0
Cool cm.sendOk

cm.sendOk("I have nothing against this server, its SuperLol i do, hes always been a selfish bitchy, flaming cock sucking son of a *****, every one? knows that from his history of duping on moongrams. My main point is hes a selfish bastard.");
cm.dispose();
 
Upvote 0
Back