Thread: Issue with NPC Drops

Results 1 to 3 of 3
  1. #1 Issue with NPC Drops 
    Registered Member
    Join Date
    Jun 2013
    Thanks given
    Thanks received
    Rep Power
    Anyone help with a drop issue? Been trying to debug it all day and come too no conclusion.. Bare in mind this only happens on certain npcs. This is the method giving the error:

        public static boolean shouldDrop(Player p,NPC npc, double drops,NpcDropItem[] c, boolean[] b, DropChance chance,
                 boolean ringOfWealth, boolean ringOfWealth1, boolean ringOfWealth2, boolean ringOfWealth3, boolean ringOfWealthLucky, boolean amuletOfInsanity, boolean ringOfGods, boolean extreme, PlayerRights rights) {
    int x = 0;
    double random = chance.getRandom(); //pull the chance from the table
    double drBoost = NPCDrops.getDroprate(p);
    for (int i = 0; i < drops; i++) {
    if (random == c[i].getChance().getRandom()) {
    random *= x;
    if (p.getTransform() == npc.getId()) {
    drBoost += 5;
    p.sendMessage("Your soul boosted your droprate by 5% on this npc!");
    random = (int)random * ((100-drBoost)/100);
    return !b[chance.ordinal()] && Misc.getRandom((int) random) == 0;

    The line giving error is:
    return !b[chance.ordinal()] && Misc.getRandom((int) random) == 0;

    The error it's giving..
    java.lang.ArrayIndexOutOfBoundsException: 12
    I cannot work out where on earth it's pulling 12 from

    Any ideas?
    [Only registered and activated users can see links. ]
    Reply With Quote  

  2. #2  
    Be the change you wanna see!

    Nozemi's Avatar
    Join Date
    Jul 2010
    Thanks given
    Thanks received
    Rep Power
    DropChance is an Enum, which is where you get 12 from. So the error would be:

    Because it can't find the array index of 12, in the boolean array held in variable b.

    So what you could do is:
    if(chance.ordinal >= b.size()) {
    return !b[chance.ordinal()] && Misc.getRandom((int) random) == 0;
    return false;
    I'm tired, I might have fucked up the if statement, flipped the greater than symbol, and it might be length instead of size. Just throw the code in your IDE and alter it to your needs.
    Reply With Quote  

  3. #3  
    Boy Wonder

    Join Date
    Mar 2012
    Thanks given
    Thanks received
    Rep Power
    The boolean array b is an being passed in as an argument, so that means that whichever function calls #shouldDrop() and passes in that array does not have a size set to the amount of elements in the enum.

    for example

    boolean[10] b = {false, false, true, ...};
    shouldDrop(..., b, ...);

    This is an issues if you have more than 10 elements in your enum, you need to initialize it with the value of the amount of elements in your enum.

    To fix it, find whatever method is calling #shouldDrop(), find where the variable for b is initialized, and initialize it to this value.

    boolean[] b = new boolean[Chance.values().length];
    This sets it to the same value as the amount of elements in your enum, meaning you won't have this issues since it can never out of the index values.
    Make sure that the values are all being set how they should be originally tho, otherwise it will always be false since it will initialize to false unless it is the Boolean object type instead of primitive which would default to null and give you a NullPointerException.
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

User Tag List

Similar Threads

  1. Replies: 0
    Last Post: 11-09-2016, 06:49 PM
  2. Request help with NPC drops line
    By ralax in forum Requests
    Replies: 2
    Last Post: 08-23-2015, 06:28 AM
  3. Need help with NPC Drops
    By bl00d w0lf in forum Help
    Replies: 8
    Last Post: 02-02-2014, 09:24 AM
  4. Replies: 8
    Last Post: 09-07-2010, 05:28 PM
  5. something with npc drops
    By sexyrussian in forum Help
    Replies: 5
    Last Post: 04-09-2010, 05:25 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts