[Release]Gift Box NPC

Code:
/**
    Gift Box NPC
    Based off of Gachapon
    Coded by: bboy242 of RageZone aka Shawn with help from X-Tasis aka Osiris
    Special Thanks: X-Tasis aka Osiris for attempting to teach me randoms and arrays better xD
**/

var status;
var boxes = [4000422, 4000423, 4000424, 4000425, 4031168, 4031169]; // Boxes to choose from
var prize = [[4000000, 4000001, 4000002, 4000003, 4000004, 4000005], [2049**** 2049**** 4031545, 4031545], [4031545, 1112000]]; // Add your prizes here
var rand = Math.floor(Math.random()*100);

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


function action(mode, type, selection) {
    if (mode == -1) {
            cm.dispose();
        }else{
    if (status >= 5 && mode == 0) {
            cm.sendOk("See you next time!.");
            cm.dispose();
            return;                    
        }
    
        if (mode == 1) {
            status++;
        }else{
            status--;
        }
    if (status == 0) {
        if (cm.haveItem("4031545", 1)) { // You choose what item.
            cm.gainItem("4031545", -1); // You choose what item, same as above
            cm.sendNext("Step right up and test your luck. See if you can win an amazing prize by guessing the correct box!");
        }else{
            cm.sendOk("You don't have the right item.");
            cm.dispose();
        }
    } else if (status == 1) {
            cm.sendNext("Do you feel lucky?");
    } else if (status == 2) {
        for(var i = 0, text = "Choose one of the prize below.\r\n\r\n"; i < boxes.length; text += "\t\t#L" + i + "##i" + boxes[i] + "##l" + ((i+1) % 2 == 0 ? "\r\n" : ""), i++);
        cm.sendSimple(text);
    } else if (status == 3) {
        cm.sendYesNo("Do you want to choose #i" + boxes[selection] + "#?");
    } else if (status == 4) {
        var rand2;
        if ((rand >= 1) && (rand <= 50)) {
            rand2 = Math.floor(Math.random() * prize[0].length);
        } else if ((rand >= 51) && (rand <= 90)) {
            rand2 = Math.floor(Math.random() * prize[1].length);
        }else{
            rand2 = Math.floor(Math.random() * prize[2].length);
            }
            cm.gainItem([rand >= 1 && rand <= 50 ? prize[0][rand2] : rand >= 51 && rand <= 90 ? prize[1][rand2] : prize[2][rand2]]);
            cm.sendOk("You have won a #v" + [rand >= 1 && rand <= 50 ? prize[0][rand2] : rand >= 51 && rand <= 90 ? prize[1][rand2] : prize[2][rand2]] + "#");
            cm.dispose();
        }
    }
}

whats wrong with that guys??
 
i get an error when i left this script in "cm.gainItem([rand >= 1 && rand <= 50 ? prize[0][rand2] : rand >= 51 && rand <= 90 ? prize[1][rand2] : prize[2][rand2]]);" but when i took it out it went straight to "sendOK" script but doesn't get the item. do i have to edit my source? in my command promt it said something about npcscript.java but i know it's something with the random thing i dont get it at all thanks for your help.
 
PHP:
            cm.gainItem((rand >= 1 && rand <= 50 ? prize[0][rand2] : rand >= 51 && rand <= 90 ? prize[1][rand2] : prize[2][rand2]));
            cm.sendOk("You have won a #v" + (rand >= 1 && rand <= 50 ? prize[0][rand2] : rand >= 51 && rand <= 90 ? prize[1][rand2] : prize[2][rand2]) + "#");
            cm.dispose();
 
PHP:
            cm.gainItem((rand >= 1 && rand <= 50 ? prize[0][rand2] : rand >= 51 && rand <= 90 ? prize[1][rand2] : prize[2][rand2]));
            cm.sendOk("You have won a #v" + (rand >= 1 && rand <= 50 ? prize[0][rand2] : rand >= 51 && rand <= 90 ? prize[1][rand2] : prize[2][rand2]) + "#");
            cm.dispose();

i edited my script with the script u gave me but i still get the same error. something with the NPC script manager pops up on my CMD.

oh and btw i'm using odinteh v.75 source

CMD says something about abstractplayerinteract.java gainitem <number> something like that. thanks for whoever would like to help me with this.

EDIT: oh wow nvm easy fix, sorry guys. lol
 
Last edited:
Woah awesome,
This is perfect for me & my friends server, cos we fail at gachapons :]

plus, it adds a custom element.
 
Back