Help me how to code Npc Gain random item drop rate 6%.. Please! :rolleyes:
Printable View
Help me how to code Npc Gain random item drop rate 6%.. Please! :rolleyes:
You lost me at the part of " npc gain random item drop rate" Care you re-explain? o-o
http://forum.ragezone.com/f428/add-l...finish-643364/
Might I recommend starting from here?
Well if this is what you wanted, here it is! If not, sorry :blink:
Spoiler:
Code:var status = 0;
var items = [1010000, 1010001, 1010002]; // Enter at will your item ID's you want your player to win.
var req = 5220000; //gachapon ticket
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == 1)
status++;
else if (mode == -1)
status--;
else {
cm.dispose();
return;
}
if (status == 0) {
cm.sendYesNo("Do you want to try to gain a random item?");
} else if (status == 1) {
/* for (var i = 0; i < items.length; i++) {
var randitem = items[i];
}*/ what the fuck was the point of an array if you just do that?
if (cm.haveItem(req)) {
var randitem = Math.floor(Math.random()*items.length);
cm.gainItem(req,-1);
cm.gainItem(randitem, 1);
cm.sendOk("#eYou have won a #b#t"+randitem+"##k!");
cm.dispose();
} else
cm.sendOk("You don't have any #i"+req+#". Just because I don't speak English doesn't mean you shouldn't.");
} else
cm.sendOk("Ahhh, better luck next time my friend!");
cm.dispose();
}
Your script is pretty fucked up and doesn't even work. Plus, it doesn't makes it 6% at all. It makes it gain every single time. I don't think you will teach me anything in NPC Scripting. So be cool and don't act like a pro scripter please.
Back to subject, LeafKora, Here's a cleaner version:
PHP Code:var status = 0;
var items = [1010000, 1010001, 1010002]; // Enter at will your item ID's you want your player to win.
var reqitem = 5220000;
function start() {
status = -1;
action(1, 0, 0);
}
function action(mode, type, selection) {
if (mode == 1)
status++;
else if (mode == -1)
status--;
else {
cm.dispose();
return;
}
if (status == 0) {
cm.sendYesNo("Do you want to try to gain a random item?\r\n");
} else if (status == 1) {
if (cm.haveItem(reqitem, 1)) {
for (var i = 0; i < items.length; i++) {
var randitem = items[Math.floor(Math.random() * items.length)];
}
if (Math.floor(Math.random() * 100) >= 0 && Math.floor(Math.random() * 100) <= 50) { // Which makes it 6%, like you asked!
cm.gainItem(randitem, 1);
cm.gainItem(reqitem, -1);
cm.sendOk("#eYou have won a #b#t"+randitem+"##k!");
cm.dispose();
} else {
cm.sendOk("Ahhh, better luck next time my friend!");
cm.gainItem(reqitem, -1);
cm.dispose();
}
} else {
cm.sendOk("You must have a #b#t"+ reqitem + "##k to be able to use me!");
cm.dispose();
}
}
}
Clearly, he wants a gachapon NPC. An idiot wouldn't be able to understand someone's intentions regardless of their inability to explain them in 3rd grader English, but I can. So I removed the 6% and your useless array and fixed it up. It's okay though, I guess he can use your NPC if he wants to.
Since you probably still don't get it, here's your retarded array.
for (var i = 0; i < items.length; i++) {
var randitem = items[i];
}
i = 0. Creates a new variable and sets it = item[0].
i = 1. Creates a new variable (losing the old one) and sets it = item[1].
i = 2. Creates a new variable (losing the old one) and sets it = item[2].
Now what about when he has 50-60 items in it (if he ever does add that many)? You're going to loop 60 times creating new variables and setting it equal to the last item? Why not just set var randitem = item[item.length - 1] if you want to get the same effect but be a little less useless?
Now be cool and quit talking like you know what you're talking about until you actually do.
Here is the working NPC (I had messed up a curly brace earlier)
Spoiler: