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

Solved SPAWN BLOCKS AROUND A PLAYER

Discussion in 'Development' started by Vaxrp, Nov 13, 2017.

  1. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    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.
     
  2. svile

    svile Spider

    Messages:
    14
    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.
     
    Muqsit likes this.
  3. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    Check how piggyce does his
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Please show proof of a previous attempt
     
    NakiFx likes this.
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Better way is sending No AI flag to player
     
  6. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    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
     
  7. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    did you check piggyce
     
  8. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    please stop spam for nothing
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    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(1337);
    $level->setBlock($pos$blockfalsefalse);
    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.
     
    OnTheVerge and Vaxrp like this.
  10. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    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
     
  11. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    Excuse me.
    PiggyCE has a CE rhat does this exact thing! Check.the code!
     
  12. Hipster

    Hipster Zombie

    Messages:
    214
    setImmobile
     
  13. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    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
     
    Remarkabless likes this.
  14. Hipster

    Hipster Zombie

    Messages:
    214
    i mean to freeze you can just use setImmobile(true)
     
    MadeBali56 likes this.
  15. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    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(020);//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.
     
    Vaxrp likes this.
  16. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    I'd like to add a couple things :D

    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] = ...
     
    kenygamer, Muqsit and Vaxrp like this.
  17. Hipster

    Hipster Zombie

    Messages:
    214
    But he just wants a freeze plugin so why not just setImmobile(true) the player.
     
  18. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    because op requested to set block so here we go
     
    EdwardHamHam, Vaxrp and jasonwynn10 like this.
  19. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You really should read the comments before commenting, you are copy-pasting what @Sandertv has already said. You're not smart.
     
  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.