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.
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
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: