Thread: Key chest

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 Key chest 
    Registered Member
    Join Date
    May 2013
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Fixed
    Reply With Quote  
     

  2. #2  
    *breaks walking*

    Cody_'s Avatar
    Join Date
    Dec 2010
    Posts
    732
    Thanks given
    219
    Thanks received
    203
    Rep Power
    286
    Are you having any errors with your current code or anything? Looked it over and it seems good to me.

    To get a random Item from the array use
    Code:
    Item item = commonRewardsI[new Random().nextInt(commonRewardsI.length)];
    player.getInventory().addItem(item);
    Note, for your rewards, you have Utils.random() in the array. This will only be generated once, and then all your rewards will have the same amount until you restart the server.
    Better to generate the random amount when adding to inventory like this:

    Code:
    Random random = new Random();
    Item item = commonRewardsI[random.nextInt(commonRewardsI.length)];
    item.setAmount(random.nextInt(item.getAmount());
    player.getInventory().addItem(item);
    Instead of having Utils.random(10), simply change it to a 10.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    May 2013
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Cody_ View Post
    Are you having any errors with your current code or anything? Looked it over and it seems good to me.

    To get a random Item from the array use
    Code:
    Item item = commonRewardsI[new Random().nextInt(commonRewardsI)];
    player.getInventory().addItem(item);
    Note, for your rewards, you have Utils.random() in the array. This will only be generated once, and then all your rewards will have the same amount until you restart the server.
    Better to generate the random amount when adding to inventory like this:

    Code:
    Random random = new Random();
    Item item = commonRewardsI[random.nextInt(commonRewardsI)];
    item.setAmount(random.nextInt(item.getAmount());
    player.getInventory().addItem(item);
    Instead of having Utils.random(10), simply change it to a 10.
    With this code i get no errors but i don't receive any items but the key is removed from the inventory
    Code:
    Random random = new Random();
    Item item = commonRewardsI[random.nextInt()];
    item.setAmount(random.nextInt(item.getAmount());
    player.getInventory().addItem(item);
    When i use your code i have this error,
    Attached image
    Reply With Quote  
     

  4. #4  
    Member Key chest Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    u didnt say what the problem is..

    Attached imageAttached image
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    May 2013
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Luke132 View Post
    u didnt say what the problem is..
    I do not receive an item from the array at all, the key goes but no item from the chest basically
    The comment above yours explains abit more
    Reply With Quote  
     

  6. #6  
    Member Key chest Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    Quote Originally Posted by DJango View Post
    I do not receive an item from the array at all, the key goes but no item from the chest basically
    The comment above yours explains abit more
    because you havent put in any code to add the item....?

    Attached imageAttached image
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    May 2013
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Luke132 View Post
    because you havent put in any code to add the item....?
    Code:
    Random random = new Random();
    Item item = commonRewardsI[random.nextInt()];
    item.setAmount(random.nextInt(item.getAmount());
    player.getInventory().addItem(item);
    This is the code i've entered to add the item but when i click the chest, no item is given, i've also tried the other solution of
    Code:
    Random random = new Random();
    Item item = commonRewardsI[random.nextInt(commonRewardsI)];
    item.setAmount(random.nextInt(item.getAmount());
    player.getInventory().addItem(item);
    But this gives me an error if you check the reply above your comment you'd see.
    Reply With Quote  
     

  8. #8  
    Registered Member deji's Avatar
    Join Date
    Dec 2018
    Posts
    75
    Thanks given
    4
    Thanks received
    21
    Rep Power
    66
    I just don't understand, why make it this complicated?.. It could be way easier than creating a new class. Use a for to search through the array.
    Reply With Quote  
     

  9. #9  
    Member Key chest Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    random.nextInt()

    you havent set a range..

    I also think youre hugely overcomplicating this as the guy above said

    Quote Originally Posted by DJango View Post
    Code:
    Random random = new Random();
    Item item = commonRewardsI[random.nextInt()];
    item.setAmount(random.nextInt(item.getAmount());
    player.getInventory().addItem(item);
    This is the code i've entered to add the item but when i click the chest, no item is given, i've also tried the other solution of
    Code:
    Random random = new Random();
    Item item = commonRewardsI[random.nextInt(commonRewardsI)];
    item.setAmount(random.nextInt(item.getAmount());
    player.getInventory().addItem(item);
    But this gives me an error if you check the reply above your comment you'd see.

    commonRewardsI.length-1

    Attached imageAttached image
    Reply With Quote  
     

  10. #10  
    Registered Member
    Join Date
    May 2013
    Posts
    10
    Thanks given
    0
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Luke132 View Post
    random.nextInt()

    you havent set a range..

    I also think youre hugely overcomplicating this as the guy above said




    commonRewardsI.length-1
    Alright thank you, that worked,

    Would you be able to tell me why the bound is not positive though when i click the chest ? Sometimes the chest works perfectly but then other times i get no item and i get this in the console ?

    Attached image
    Reply With Quote  
     

Page 1 of 2 12 LastLast

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. crystal key chest code?
    By imurdernubs in forum Help
    Replies: 10
    Last Post: 12-18-2013, 09:35 AM
  2. [PI] Donor Crystal Key Chest 317 [PI]
    By acriley3 in forum Tutorials
    Replies: 5
    Last Post: 07-03-2013, 06:50 PM
  3. 637/639 Crystal Key Chest
    By `Eco in forum Snippets
    Replies: 5
    Last Post: 08-11-2012, 10:04 PM
  4. crystal key chest dementhium
    By GomuGomuFruit in forum Help
    Replies: 10
    Last Post: 04-24-2012, 09:44 PM
  5. crystal key chest system for dementhium 639
    By Zᴀᴄʜ in forum Help
    Replies: 2
    Last Post: 01-24-2012, 01:18 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
  •