Hi, can u guys help me, with canceling breaking snow with shovel and gaining snowballs? I want to disable this function. I might have some idea, but first, i would like to hear your advices and maybe see examples of code.
Something like this? Players cannot break snow with shovels: PHP: public function onBreak(BlockBreakEvent $event) { $block = $event->getBlock(); $blockhold = $event->getItem(); if($blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) { if($block->getId() === 78 || $block->getId() === 80) { $event->setCancelled(); } }}
PHP: namespace NoSnowballs;use pocketmine\plugin\PluginBase as PluginBase;use pocketmine\event\Listener as Listener;use pocketmine\utils\TextFormat;use pocketmine\event\block\BlockBreakEvent;use pocketmine\block\Block;use pocketmine\block\Air;use pocketmine\block\Snow;use pocketmine\math\Vector3;use pocketmine\item\Item;class Main extends PluginBase implements Listener{ $this->getServer()->getPluginManager()->registerEvents($this,$this); $this->getServer()->getLogger()->info(TextFormat::GREEN . "Bezsniezek"); }public function onBreak(BlockBreakEvent $event) { $block = $event->getBlock(); $blockhold = $event->getItem(); if($blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) { if($block->getId() === 78 || $block->getId() === 80) { $event->setCancelled(); } }}[\PHP] Now i get this error: ParseError: "syntax error, unexpected variable (T_VARIABLE), expecting function (T_FUNCTION)" (EXCEPTION) in "myzip:///SnowballsCancel.zip#SnowballsCancel/src/NoSnowballs/Main" at line 17
Use its: PHP: namespace NoSnowballs;use pocketmine\plugin\PluginBase as PluginBase;use pocketmine\event\Listener as Listener;use pocketmine\utils\TextFormat;use pocketmine\event\block\BlockBreakEvent;use pocketmine\block\Block;use pocketmine\block\Air;use pocketmine\block\Snow;use pocketmine\math\Vector3;use pocketmine\item\Item;class Main extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this,$this); $this->getServer()->getLogger()->info(TextFormat::GREEN . "Bezsniezek"); }public function onBreak(BlockBreakEvent $event) { $block = $event->getBlock(); $blockhold = $event->getItem(); if($blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) { if($block->getId() === 78 || $block->getId() === 80) { $event->setCancelled(); } } }}} If you want the snow to break, but do not drop the snowballs, use this: PHP: public function onBreak(BlockBreakEvent $event) { $block = $event->getBlock(); $blockhold = $event->getItem(); if($blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) { if($block->getId() === 78 || $block->getId() === 80) { $event->setCancelled(); $event->setDrops([]); } } }
ParseError: "syntax error, unexpected '{'" (EXCEPTION) in "myzip:///SnowballsCancel.zip#SnowballsCancel/src/NoSnowballs/Main" at line 16
There's an extra bracket Try this: PHP: <?phpnamespace NoSnowballs;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\utils\TextFormat;use pocketmine\event\block\BlockBreakEvent;class Main extends PluginBase implements Listener{ public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getServer()->getLogger()->info(TextFormat::GREEN . "Bezsniezek"); } public function onBreak(BlockBreakEvent $event) { $block = $event->getBlock(); $blockhold = $event->getItem(); if ($blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) { if ($block->getId() === 78 || $block->getId() === 80) { $event->setCancelled(); } } }}
Syntax errors are entirely unrelated to PocketMine. I suggest you search on sites like StackOverflow for those. You'll likely get a better explanation.
Ehh thats strange.. It should work, but still: ParseError: "syntax error, unexpected '{'" (EXCEPTION) in "myzip:///SnowballsCancel.zip#SnowballsCancel/src/NoSnowballs/Main" at line 11
also remove this "$this->getServer()->getLogger()->info(TextFormat::GREEN . "Bezsniezek");" line because it's pointless
Entire thing? U mean code...? PHP: <?phpnamespace NoSnowballs;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\utils\TextFormat;use pocketmine\event\block\BlockBreakEvent;class Main extends PluginBase implements Listener{ public function onEnable(); { $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onBreak(BlockBreakEvent $event) { $block = $event->getBlock(); $blockhold = $event->getItem(); if ($blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) { if ($block->getId() === 78 || $block->getId() === 80) { $event->setCancelled(); } } }}[\PHP
Here, should fix your useless syntax problems. PHP: use pocketmine\event\Listener;use pocketmine\utils\TextFormat;use pocketmine\event\block\BlockBreakEvent;use pocketmine\plugin\PluginBase;class Main extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onBreak(BlockBreakEvent $event){ $block = $event->getBlock(); $blockhold = $event->getItem(); if ($blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) { if ($block->getId() === 78 || $block->getId() === 80) { $event->setCancelled(); } } }}