Posted January 3, 201510 yr I understand how to make the mob drops 0-2 dropping only 1 out of 2 and sometimes nothing, but how would I increase that number to say 10? 1-10 and only 1 out of 10 items? This is what I have now. protected void dropFewItems(boolean par1, int par2) { int random = this.rand.nextInt(4) + this.rand.nextInt(1 + par2); for (int k = 0; k < random; ++k) { if(k == 2){ this.dropItem(PhantasyRealmsItems.blade, 1); } else if (k == 1){ this.dropItem(PhantasyRealmsItems.brand, 1); }
January 3, 201510 yr Author Well, just change how you calculate the number. Random.nextInt(n) gives you a number between 0 (inclusive) and n (exclusive). So Random.nextInt(3) gives you 0, 1 or 2. Then just use math to get to the range you want. yes but when I try to add on to this for (int k = 0; k < random; ++k) { if(k == 2){ this.dropItem(PhantasyRealmsItems.blade, 1); } else if (k == 1){ this.dropItem(PhantasyRealmsItems.brand, 1); } else if (k == 3){ this.dropItem(PhantasyRealmsItems.brand, 1); } and so on it just makes killing the mob drop both items after the first else.. I dont know Im at a loss for what to do after setting Random.nextInt(n) to a higher number.
January 3, 201510 yr Well, you used a 'for' loop, so if random is 3, you will drop both items '1' and '2'. Perhaps Java tutorials are in order? http://i.imgur.com/NdrFdld.png[/img]
January 3, 201510 yr Author Well, you used a 'for' loop, so if random is 3, you will drop both items '1' and '2'. Perhaps Java tutorials are in order? Fair enough and perhaps though an answer would be nice too.
January 3, 201510 yr Author So you have 10 possible drops. You want to drop only 1 of those at every given time and then 1-10 of that selected Item? yes
January 3, 201510 yr Author First select the drop type, it's a number from 0-9 (10 possible types): int dropType = rand.nextInt(10); Then select how many of that Item to drop (1-10): int dropAmount = 1 + rand.nextInt(10); Then switch on the drop type and drop the selected amount of it. This is not hard. No sorry, I read your comment wrong, there are 10 possible Items a mob can drop, each time a mob is killed 1 out of those 10 items is dropped.
January 3, 201510 yr Author Then just remove the drop amount part. Just select the drop type and drop it... Thanks, I know it may seem basic to you guys but I learn by trial and error and by actually testing with things not just reading about them, and I appreciate you helping me out. Thank you
January 3, 201510 yr Switch statement - read it, then USE it and experiment with it until you understand how it works. Once you do, get rid of that for loop you have and replace it with a switch statement on the random number generated for drop type, and return a specific drop for each case that you want. http://i.imgur.com/NdrFdld.png[/img]
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.