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

Stone drop plugin

Discussion in 'Plugin Help' started by Juqxi, Feb 17, 2017.

  1. Juqxi

    Juqxi Spider Jockey

    Messages:
    33
    Code of the plugin:
    Code:
    <?php
    
    namespace drop;
    
    use pocketmine\plugin\PluginBase as P;
    use pocketmine\event\Listener as L;
    use pocketmine\utils\TextFormat;
    use pocketmine\utils\MainLogger;
    use pocketmine\block\Air;
    use pocketmine\entity\Effect;
    use pocketmine\event\block\BlockBreakEvent;
    use pocketmine\level\sound\PopSound as Pop;
    use pocketmine\level\particle\LavaParticle as Lava;
    use pocketmine\block\Block;
    use pocketmine\math\Vector3;
    use pocketmine\item\Item;
    use pocketmine\event\player\PlayerExperienceChangeEvent;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    
    class Main extends P implements L{
      
        public function onEnable(){
            $this->getServer()->getPluginManager()->registerEvents($this,$this);
            $this->saveDefaultConfig();
            $this->getServer()->getLogger()->info(TextFormat::GREEN."Drop: true");
        }
    
      
        public function onBreak(BlockBreakEvent $e){
            $player = $e->getPlayer();
            $block = $e->getBlock();
            $gracz = $e->getPlayer()->getName();
            $drop = mt_rand(1,1000);
            if($e->getBlock()->getId() == 1){
                
               if($drop <= 50){ /* 5 % Diamonds */
               $player->sendMessage("§7• >drOP:Trafiłeś na 3 Diamenty §b(+80xp)");
               $player->getInventory()->addItem(Item::get(264, 0, 3));
            }
                elseif($drop <= 150) /* 10% Iron Ore */ {
                $player->sendMessage("§7• >drOP:Trafiłeś na rudę żelaza§b(+40xp");
                $player->getInventory()->addItem(Item::get(15, 0, 1));
                }
                else if($drop <= 275) /* 7,5% Golden Ore */ {
                $player->sendMessage("§7• >drOP:trafiłeś na rudę złota§b(+40xp)");
                $player->getInventory()->addItem(Item::get(14, 0, 1));
                }
                else if($drop <= 500) /* 2,5% Apple*/ {
                $player->sendMessage("§7• >drOP:Trafiłeś na jabłko§b(+160xp)");
                $player->getInventory()->addItem(Item::get(260, 0, 1));
                }
                else if($drop<=1075) /* 10% Wood */ {
                $player->sendMessage("§7• >drOP:Trafiłes na drewno§b(+20xp)");
                $player->getInventory()->addItem(Item::get(17, 0, 1));
                }
                else if($drop<=2100) /*5% Tnt */ {
                $player->sendMessage("§7• >drOP:Trafiłes na tnt§b(+40xp)");
                $player->getInventory()->addItem(Item::get(46, 0, 1));
                }
                else if($drop<=4190) /* 4% Coal */ {
                $player->sendMessage("§7• >drOP:Trafiłes na 4 sztuki węgla§b(+20xp");
                $player->getInventory()->addItem(Item::get(16, 0, 4));
                }
                else if($drop<=8350) /* 1% Gapple*/ {
                $player->sendMessage("§7• >drOP:Trafiłes na §eRefila i §6Koxa §b(+1725xp");
                $player->getInvetory()->addItem(Item::get(322, 0, 1)(322, 1, 1));
                }
                else {
                }
              
                
            }
    }
    }  
    
    Error:
    Code:
    player on breaking stone gives i.e diamonds but dont send message : Trafiłes na diamenty
     
    Another Error:
    Code:
    dont drops all items which i want help ( tnt , coal , gapples )
    
    Console Error:
    Code:
    none
    
     
  2. dragonflex

    dragonflex Spider Jockey

    Messages:
    44
    PHP:
    <?php

    namespace drop;

    use 
    pocketmine\plugin\PluginBase as P;
    use 
    pocketmine\event\Listener as L;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\MainLogger;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    class 
    Main extends implements L{
     
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            
    $this->saveDefaultConfig();
            
    $this->getServer()->getLogger()->info(TextFormat::GREEN."Drop: true");
        }

     
        public function 
    onBreak(BlockBreakEvent $e){
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
            
    $gracz $e->getPlayer()->getName();
            
    $drop mt_rand(1,1000);
            if(
    $e->getBlock()->getId() == 1){
              
               if(
    $drop <= 50){ /* 5 % Diamonds */
               
    $player->sendMessage("§7• >drOP:Trafiłeś na 3 Diamenty §b(+80xp)");
               
    $player->getInventory()->addItem(Item::get(26403));
            }
                elseif(
    $drop <= 150/* 10% Iron Ore */ {
                
    $player->sendMessage("§7• >drOP:Trafiłeś na rudę żelaza§b(+40xp");
                
    $player->getInventory()->addItem(Item::get(1501));
                }
                elseif(
    $drop <= 275/* 7,5% Golden Ore */ {
                
    $player->sendMessage("§7• >drOP:trafiłeś na rudę złota§b(+40xp)");
                
    $player->getInventory()->addItem(Item::get(1401));
                }
                elseif(
    $drop <= 500/* 2,5% Apple*/ {
                
    $player->sendMessage("§7• >drOP:Trafiłeś na jabłko§b(+160xp)");
                
    $player->getInventory()->addItem(Item::get(26001));
                }
                elseif(
    $drop<=1075/* 10% Wood */ {
                
    $player->sendMessage("§7• >drOP:Trafiłes na drewno§b(+20xp)");
                
    $player->getInventory()->addItem(Item::get(1701));
                }
                elseif(
    $drop<=2100/*5% Tnt */ {
                
    $player->sendMessage("§7• >drOP:Trafiłes na tnt§b(+40xp)");
                
    $player->getInventory()->addItem(Item::get(4601));
                }
                elseif(
    $drop<=4190/* 4% Coal */ {
                
    $player->sendMessage("§7• >drOP:Trafiłes na 4 sztuki węgla§b(+20xp");
                
    $player->getInventory()->addItem(Item::get(1604));
                }
                elseif(
    $drop<=8350/* 1% Gapple*/ {
                
    $player->sendMessage("§7• >drOP:Trafiłes na §eRefila i §6Koxa §b(+1725xp");
                
    $player->getInvetory()->addItem(Item::get(32201)(32211));          
                }
          }
    }
     
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I don't understand what you're saying, can you please rephrase it?

    What i've seen from your code is that you're trying to randomize the drops? or the blocks you've broke?
     
  4. Juqxi

    Juqxi Spider Jockey

    Messages:
    33
    em i trying to get percentage chance to drop diamonds to the player which breaked stone but i've seen that errors
     
  5. Juqxi

    Juqxi Spider Jockey

    Messages:
    33
    still dont dropping tnt , coal , gapples and still dont sending Message
    Code:
     error of sending message :
     
  6. Juqxi

    Juqxi Spider Jockey

    Messages:
    33
    WARNING IMPORTANT"
    The send message error seems like that
    [​IMG]
     
  7. MyNET

    MyNET Silverfish

    Messages:
    24
    PHP:
    $gracz $e->getPlayer()->getName();
    is this useful? since you register that code but you not use it , that mean $gracz useless
    Remind me if i'm wrong.
     
  8. SzanelGirl

    SzanelGirl Spider Jockey

    Messages:
    28
    GitHub:
    SzanelGirl
    public function onBreak(BlockBreakEvent $drop){
    $player = $drop->getPlayer();
    $block = $drop->getBlock();
    $gracz = $drop->getPlayer()->getName();
     
  9. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
    PHP:
    <?php

    namespace drop;

    use 
    pocketmine\plugin\PluginBase as P;
    use 
    pocketmine\event\Listener as L;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\MainLogger;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\block\Block
    use pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;

    class 
    Main extends implements L{
     
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            
    $this->saveDefaultConfig();
            
    $this->getServer()->getLogger()->info(TextFormat::GREEN."Drop: true");
        }

     
        public function 
    onBreak(BlockBreakEvent $e){
            
    $player $e->getPlayer();
            
    $block $e->getBlock();

            if(
    $block->getId() == Block::STONE){
               
    $drop mt_rand(1,1000);
               if(
    $drop <= 50){ /* 5 % Diamonds */
               
    $player->sendMessage("§7• >drOP:Trafiłeś na 3 Diamenty §b(+80xp)");
               
    $player->getInventory()->addItem(Item::get(26403));
            }
                elseif(
    $drop => 50 && $drop <= 150/* 10% Iron Ore */ {
                
    $player->sendMessage("§7• >drOP:Trafiłeś na rudę żelaza§b(+40xp");
                
    $player->getInventory()->addItem(Item::get(1501));
                }
                elseif(
    $drop => 150 && $drop <= 275/* 7,5% Golden Ore */ {
                
    $player->sendMessage("§7• >drOP:trafiłeś na rudę złota§b(+40xp)");
                
    $player->getInventory()->addItem(Item::get(1401));
                }
                elseif(
    $drop => 275 && $drop <= 500/* 2,5% Apple*/ {
                
    $player->sendMessage("§7• >drOP:Trafiłeś na jabłko§b(+160xp)");
                
    $player->getInventory()->addItem(Item::get(26001));
                }
                elseif(
    $drop => 500 && $drop <= 1075/* 10% Wood */ {
                
    $player->sendMessage("§7• >drOP:Trafiłes na drewno§b(+20xp)");
                
    $player->getInventory()->addItem(Item::get(1701));
                }
                elseif(
    $drop => 1075 && $drop <= 2100/*5% Tnt */ {
                
    $player->sendMessage("§7• >drOP:Trafiłes na tnt§b(+40xp)");
                
    $player->getInventory()->addItem(Item::get(4601));
                }
                elseif(
    $drop => 2100 && $drop <= 4190/* 4% Coal */ {
                
    $player->sendMessage("§7• >drOP:Trafiłes na 4 sztuki węgla§b(+20xp");
                
    $player->getInventory()->addItem(Item::get(1604));
                }
                elseif(
    $drop => 4190 && $drop <= 8350/* 1% Gapple*/ {
                
    $player->sendMessage("§7• >drOP:Trafiłes na §eRefila i §6Koxa §b(+1725xp");
                
    $player->getInvetory()->addItem(Item::get(32201)(32211));       
                }
          }
    }
     
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    If you are trying to set the block's item drops, then you can use this:
    PHP:
    public function onBreak(BlockBreakEvent $e){
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
            if(
    $block->getId() == Block::STONE){
                
    $chance mt_rand(1,10000); //added one more 0
                
    if($drop <= 50){ /* 5 % Diamonds */
                    
    $player->sendMessage("§7• >drOP:Trafiłeś na 3 Diamenty §b(+80xp)");
                   
    //$player->getInventory()->addItem(Item::get(264, 0, 3));
                   
    $block->setDrops([Item::get(26403)]);
                }elseif(
    $drop => 50 && $drop <= 150/* 10% Iron Ore */ {
                    
    $player->sendMessage("§7• >drOP:Trafiłeś na rudę żelaza§b(+40xp");
                    
    //$player->getInventory()->addItem(Item::get(15, 0, 1));
                    
    $block->setDrops([Item::get(15,0,1)]);
                }elseif(
    $drop => 150 && $drop <= 275/* 75% Golden Ore */ {
                    
    $player->sendMessage("§7• >drOP:trafiłeś na rudę złota§b(+40xp)");
                    
    //$player->getInventory()->addItem(Item::get(14, 0, 1));
                    
    $block->setDrops([Item::get(1401)]);
                }elseif(
    $drop => 275 && $drop <= 500/* 25% Apple*/ {
                    
    $player->sendMessage("§7• >drOP:Trafiłeś na jabłko§b(+160xp)");
                    
    //$player->getInventory()->addItem(Item::get(260, 0, 1));
                    
    $block->setDrops([Item::get(26001)]);
                }elseif(
    $drop => 500 && $drop <= 1075/* 10% Wood */ {
                    
    $player->sendMessage("§7• >drOP:Trafiłes na drewno§b(+20xp)");
                    
    //$player->getInventory()->addItem(Item::get(17, 0, 1));
                    
    $block->setDrops([Item::get(1701)]);
                }elseif(
    $drop => 1075 && $drop <= 2100/*5% Tnt */ {
                    
    $player->sendMessage("§7• >drOP:Trafiłes na tnt§b(+40xp)");
                    
    //$player->getInventory()->addItem(Item::get(46, 0, 1));
                    
    $block->setDrops([Item::get(4601)]);
                }elseif(
    $drop => 2100 && $drop <= 4190/* 4% Coal */ {
                    
    $player->sendMessage("§7• >drOP:Trafiłes na 4 sztuki węgla§b(+20xp");
                   
    //$player->getInventory()->addItem(Item::get(16, 0, 4));
                    
    $block->setDrops([Item::get(1604)]);
                }elseif(
    $drop => 4190 && $drop <= 8350/* 1% Gapple*/ {
                    
    $player->sendMessage("§7• >drOP:Trafiłes na §eRefila i §6Koxa §b(+1725xp");
                    
    //$player->getInvetory()->addItem(Item::get(322, 1, 1));      
                    
    $block->setDrops([Item::get(32201),Item::get(32211)]);
                }
          }
     
    corytortoise likes this.
  11. SzanelGirl

    SzanelGirl Spider Jockey

    Messages:
    28
    GitHub:
    SzanelGirl
  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.