• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

MoopleDEV, scripting NPC!

Newbie Spellweaver
Joined
Apr 19, 2016
Messages
17
Reaction score
0
So I am very very new to this and I am trying to learn a little bit of javascript and I got help writing a script for a gachapon but I am running into some problems, when it should reward me an item it gives me the error "An unknown error occurred while executing this NPC"

I came across this and I kinda tried the advice but I probably should have read all the posts first, it's to fix cm.haveItem, I have no idea if I am just bad at this but I have problems getting cm.haveItem work, so I guess that could be the problem? I should be running on REV 120, yes it's a different REV in that thread as well, don't judge me... :*:
http://forum.ragezone.com/f427/mini-add-fixing-moopledev-rev-743167/

Here is the script I am trying to get working, the problem starts after "Would you like to use a coupon" that's where I get the error and I am stuck, and kindly asks for your assistance.
I removed the item ID's cause there were a lot of them and not relevant right now.
Code:
var status = 0;
var Tier1 = Array(3010378, 3010379, 3010380, 3010381, 3010382);
var Tier2 = Array(3010378, 3010379, 3010380, 3010381, 3010382);
var Tier3 = Array(3010378, 3010379, 3010380, 3010381, 3010382);
var Tier4 = Array(3010378, 3010379, 3010380, 3010381, 3010382); 


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


function action(mode, type, selection) {
   if (mode == -1) {
       cm.dispose();
   } else {
      if (status == 0 && mode == 0) {
         cm.sendOk("Okay, see you next time");
         cm.dispose();
         return;
      }
      if (mode == 1)
         status++;
      else  
         status--;
      if (status == 0) {
         cm.sendYesNo("Would you like to use a Coupon?");
      } else if (status == 1) {
         if (cm.haveItem(5220000, 1)) {
            var rand = math.floor(math.random() * 100) + 1;
            cm.gainItem(5220000, -1);
            if (rand >= 0 && rand <= 40) { //Do the ">=" cause problems? if it should use ">" only instead
               cm.gainItem(Tier1[math.floor(math.random() * Tier1.length())], 1);
            } else if (rand >= 41 && rand <= 70) {
               cm.gainItem(Tier2[math.floor(math.random() * Tier2.length())], 1);
            } else if (rand >= 71 && rand <= 80) {
               cm.gainItem(Tier3[math.floor(math.random() * Tier3.length())], 1);
            } else if (rand >= 81 && rand <= 100) {
               cm.gainItem(Tier4[math.floor(math.random() * Tier4.length())], 1);
            }
            cm.dispose();
         } else {
            cm.sendOk("You don't have a coupon");
            cm.dispose(); 
         }
      }   
   }
}


These php tags are really frustrating, I have no idea how to make it readable...
If it helps here is an image of the code and if you would like to download it:
https://i.imgur.com/HW7kuOH.png

https://mega.nz/#!jVhRhAbJ!Kh1sU4AJZTd2tfLZDNYdrJZtXCd5TBiA5IN-AkMSD2o
 
Last edited:
Junior Spellweaver
Joined
Aug 13, 2010
Messages
111
Reaction score
16
cm.haveItem ...

var Tier1 = Array(itemid,itemid,itemid);
var Tier2 = Array(itemid,itemid,itemid);
var Tier3 = Array(itemid,itemid,itemid);
var Tier4 = Array(itemid,itemid,itemid);
 
Upvote 0
Newbie Spellweaver
Joined
Apr 19, 2016
Messages
17
Reaction score
0
cm.haveItem ...

var Tier1 = Array(itemid,itemid,itemid);
var Tier2 = Array(itemid,itemid,itemid);
var Tier3 = Array(itemid,itemid,itemid);
var Tier4 = Array(itemid,itemid,itemid);
Yes I am aware that there are no item ID's in the arrays like I said I did remove them?
I don't know what you are tying to say with "cm.haveItem..." either.
 
Upvote 0
Newbie Spellweaver
Joined
Aug 27, 2015
Messages
25
Reaction score
3
Code:
if (cm.haveItem(5220000, 1)) {

Always remember to add "cm." in front of the function you're trying to call from NPCConversationManager

Also, try using [ CODE ] tag instead of [ PHP ]

By the way, rand > 0 && rand <= 40 and rand > 41 && rand <= 70? What about 41?
Same thing with 71 and 81
 
Last edited:
Upvote 0
Newbie Spellweaver
Joined
Apr 19, 2016
Messages
17
Reaction score
0
>>> if (haveItem(5220000, 1)) { <<<
Ohh okey, was quite confusing at first, thank you!
Code:
if (cm.haveItem(5220000, 1)) {

Always remember to add "cm." in front of the function you're trying to call from NPCConversationManager

Also, try using [ CODE ] tag instead of [ PHP ]

By the way, rand > 0 && rand <= 40 and rand > 41 && rand <= 70? What about 41?
Same thing with 71 and 81
Thank you very much for the help, everything you mentioned worked for the better, I appreciate the help!

There is still a problem with the script it still refuses to give me an item, I added a few random chairs in the script.
 
Upvote 0
Back
Top