Thread: Issue with NPC Drops

Results 1 to 3 of 3
  1. #1 Issue with NPC Drops 
    Registered Member
    Join Date
    Jun 2013
    Posts
    336
    Thanks given
    57
    Thanks received
    23
    Rep Power
    13
    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:

    Code:
        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()) {
    x++;
    }
    }
    random *= x;
    p.setDroprate(drBoost);
    
    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:
    Code:
    return !b[chance.ordinal()] && Misc.getRandom((int) random) == 0;

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

    Any ideas?
    Reply With Quote  
     

  2. #2  
    Be the change you wanna see!
    Nozemi's Avatar
    Join Date
    Jul 2010
    Posts
    254
    Thanks given
    60
    Thanks received
    57
    Rep Power
    40
    DropChance is an Enum, which is where you get 12 from. So the error would be:

    Code:
    b[chance.ordinal()]
    Because it can't find the array index of 12, in the boolean array held in variable b.

    So what you could do is:
    Code:
    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
    Posts
    842
    Thanks given
    133
    Thanks received
    80
    Rep Power
    74
    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

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

    Code:
    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)

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
  •