I want to create a freeze plugin but feel like cancelling the movement is buggy so I was thinking maybe I can make one where it gets the players location and spawns blocks around the player on command. Can anyone help me spawn the blocks around the player and how I can get th elocations of where to place the blocks thanks.
You can simply set the immobile flag using https://github.com/pmmp/PocketMine-...46c2717/src/pocketmine/entity/Entity.php#L654 But it's client side so i recommend cancelling the MoveEvent anyway.
I can create the freeze plugin I have made it before but, I want to basically know how to spawn blocks around a player. I dont just want to use the spawn blocks around player for the freeze I have other stuff in mind. I just dont know what I can use to spawn the blocks around and how
If you want to just set blocks at specific coordinates, you can use Level->setBlock(). You can get a player's level through Player->getLevel(). Here's an example of Level::setBlock() usage: PHP: /** @var Level $level */$block = Block::get(Block::IRON_BARS);$pos = new Vector3(1, 33, 7);$level->setBlock($pos, $block, false, false); The first parameter is the position at which you want to set the block. The second parameter is the Block instance of the block you want to set. The third parameter is deprecated, so it doesn't really matter. The fourth parameter handles whether to update neighbouring blocks (for example, placing a block aside of cactus causes cactus to update and break). If you're calling setBlock() multiple times, you may want to set it to false for performance.
okay, but if Im trying to place the blocks according to the players location, would it be like $player->getLocation->setBlock() But how would it place them according to the players location if they move around. Like say place it 2 above the head 3 sideways 0 downwards of the player Basically creating a sphere around the player. Thats the part I dont get
invalid see: also just get the user's XYZ, each -1/+1 set a block array = [X=>p.x,Y=>p.y,Z=>p.z] foreach array as key => pos level.setblock(clone(p).set{key}(pos+1),block) level.setblock(clone(p).set{key}(pos-1),block) consider copying off world edit plugins that draw cuboids
You can get player's XYZ by: PHP: $x = $player->x;$y = $player->y;$z = $player->z Or just: PHP: list($x, $y, $z) = [$player->x, $player->y, $player->z]; \pocketmine\block\Block requires it's x, y and z to be integers. BUT, $x, $y and $z are floats so you'll need to convert them to int by rounding. PHP: $x = round($x);$y = round($y);$z = round($z); Actually, there's a short-hand. PHP: $pos = $player->round();//this is the position of the player's feet. if you set//the block at this position, the block will be set at//the player's feet. The position right above player's head would be: PHP: $abovePlayer = $pos->add(0, 2, 0);//adding 2 to $pos->y You can use $player->getLevel()->setBlock($abovePlayer, $block, false, false) Arithmetic logic should assist you for the rest of the positions.
I'd like to add a couple things round(value) doesn't convert a value to an int, just a rounded float. Make sure to (int) typecast it. For the list($x, $y, $z) = ... you can also use the shorthand that's available as of PHP 7.1, [$x, $y, $z] = ...
You really should read the comments before commenting, you are copy-pasting what @Sandertv has already said. You're not smart.