I'm trying to make an item gettable on BlockBreakEvent but I don't know how to set up chances, can anyone help?
use mt_rand on onBreakBlockEvent and dont forgot setDrop(); PHP: mt_rand(1, 30) // 1 chance out of 30mt_rand(1, 999) // 1 chance out of 999mt_rand(10,100) // 10 chance out of 100
In your BlockBreakEvent method: PHP: $ch/* * @var Player $player; */$chance = 35; // chance in percentage$random = round(mt_rand(1, (1 / $chance) * 100)); // round it to make an integerif($random == 1) { // 35% chance to get a diamond (264) $drops = $event->getDrops(); $drops[] = Item::get(264); $event->setDrops($drops);} If you want to give each item a specific percentage to drop: PHP: /* * @var Player $player; */$items = ["357:0:8" => 50, "388:0:1" => 20, "399:0:1" => 20, "293:0:1" => 10]; // key = <ID>:<meta>:<amount>, value = percentage// The sum of ALL values together needs to be 100// Example: ""351:3:32" => 50" will be "32 Cocoa Beans => Drop chance 50%"$random = mt_rand(0, 100);$w = 0;foreach($items as $id => $percentage) { // chooses a number $w += $percentage; if ($w > $random) { $data = explode(":", $id); $item = Item::get($data[0], $data[1], $data[2]); break; }}$drops = $event->getDrops();$drops[] = $item;$event->setDrops($drops); // drop the item If you want 10% chance to drop an emerald and 15% to drop a diamond (the rest 65% will be nothing), just use: PHP: $items = ["388:0:1" => 10, "264:0:1" => 15, "0:0:0" => 65]; // 0 = air
I don't think you're helpful with that. Everyone knows that this is supposed to be there, and OP probably won't understand what you intend to communicate.
How do I use this but instead of blockbreak event it'll be everytime I touch the chest with a key and jt gives custom renamed ITems
Use interactevent; check if touching chest and item in hand is equal to key; and if it is give what you wanted to.