1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

LuckyBlocks

Discussion in 'Development' started by Jonas, Apr 11, 2017.

  1. Jonas

    Jonas Baby Zombie

    Messages:
    192
    How can i make this drops Random?
    PHP:
        public function onBreak(BlockBreakEvent $event) {
            
    $player $event->getPlayer();
            
    $block $event->getBlock();
            if (
    $block->getId() === Block::SPONGE) {
                
    $drops = array();
                
    $drops[] = new Item(27601);
                
    $drops[] = new Item(27701);
                
    $drops[] = new Item(27801);
                
    $drops[] = new Item(4016);
                
    $event->setDrops($drops);
     
  2. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    hello, my code is not short but maybe it can help you !
    PHP:
      public function onBreak(BlockBreakEvent $event) {
         
            if(
    $event->getBlock()->getId() == 19) {
                
    $player $event->getPlayer();
                
    $rdm rand(17);
                
    $player->getLevel()->addSound((new \pocketmine\level\sound\AnvilFallSound($player)), [$player]);
                
    $this->dropItems($event$player$rdm);
            }
        }
       
        public function 
    dropItems($event$player$rdm){
            switch(
    $rdm){
                case 
    "1":
                    
    $drop1 = array(Item::get(26701));
                    
    $event->setDrops($drop1);
                break;
                case 
    "2":
                    
    $drop1 = array(Item::get(261,01),Item::get(262,0,16));
                    
    $event->setDrops($drop1);
                break;
                case 
    "3":
                    
    $drop1 = array(Item::get(322,0,6),Item::get(272,0,1));
                    
    $event->setDrops($drop1);
                break;
                case 
    "4":
                    
    $drop1 = array(Item::get(307,0,1),Item::get(208,0,1));
                    
    $event->setDrops($drop1);
                break;
                case 
    "5":
                    
    $drop1 = array(Item::get(306,0,1),Item::get(2090,1));
                    
    $event->setDrops($drop1);
                break;
                case 
    "6":
                    
    $drop1 = array(Item::get(311,0,1));
                    
    $event->setDrops($drop1);
                break;
                case 
    "7":
                    
    $drop1 = array(Item::get(332,0,8));
                    
    $event->setDrops($drop1);
                break;
                default:
                break;
            }
        }
     
  3. Jonas

    Jonas Baby Zombie

    Messages:
    192
    Thank you. It helps me :)
     
  4. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    You're welcome :)
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.