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
PHP: <?phpnamespace 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 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)); } elseif($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)); } elseif($drop <= 500) /* 2,5% Apple*/ { $player->sendMessage("§7• >drOP:Trafiłeś na jabłko§b(+160xp)"); $player->getInventory()->addItem(Item::get(260, 0, 1)); } elseif($drop<=1075) /* 10% Wood */ { $player->sendMessage("§7• >drOP:Trafiłes na drewno§b(+20xp)"); $player->getInventory()->addItem(Item::get(17, 0, 1)); } elseif($drop<=2100) /*5% Tnt */ { $player->sendMessage("§7• >drOP:Trafiłes na tnt§b(+40xp)"); $player->getInventory()->addItem(Item::get(46, 0, 1)); } elseif($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)); } elseif($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)); } }}
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?
em i trying to get percentage chance to drop diamonds to the player which breaked stone but i've seen that errors
still dont dropping tnt , coal , gapples and still dont sending Message Code: error of sending message :
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.
public function onBreak(BlockBreakEvent $drop){ $player = $drop->getPlayer(); $block = $drop->getBlock(); $gracz = $drop->getPlayer()->getName();
PHP: <?phpnamespace 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\Blockuse 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(); 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(264, 0, 3)); } 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)); } 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(14, 0, 1)); } elseif($drop => 275 && $drop <= 500) /* 2,5% Apple*/ { $player->sendMessage("§7• >drOP:Trafiłeś na jabłko§b(+160xp)"); $player->getInventory()->addItem(Item::get(260, 0, 1)); } 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)); } 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)); } 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)); } 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, 0, 1)(322, 1, 1)); } }}
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(264, 0, 3)]); }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(14, 0, 1)]); }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(260, 0, 1)]); }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(17, 0, 1)]); }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(46, 0, 1)]); }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(16, 0, 4)]); }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(322, 0, 1),Item::get(322, 1, 1)]); } }