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

setBlock() Jail

Discussion in 'Development' started by DanielYTK, Feb 11, 2017.

  1. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    In my code I teleport a player to 10 blocks above it, and there I need to create a cage to trap it, how do I do that?
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    setBlocks around him?
     
  3. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    I do not know, I just need to do this.
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    PHP:
    $X $player->getFloorX();
    $Y $player->getFloorY();
    $Z $player->getFloorZ();
    $size 3;
    for(
    $x $X $size;$x <= $X $size;$x++){
        for(
    $y=$Y $size;$y <= $Y $size;$y++){
            for(
    $z $Z $size;$z <= $Z+$size;$z++){
                if(!(
    $x === $X && $z === $Z && ($y === $Y || $y === $Y+1))){
                    
    $player->level->setBlockIdAt($x,$y,$z,7);
                }
             }
         }
    }
     
     
    Last edited: Feb 17, 2017
    Muqsit and Awzaw like this.
  5. DanielYTK

    DanielYTK Zombie

    Messages:
    227
  6. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Error in this code
    Code:
    [13:50:31] [Server thread/CRITICAL]: Error: "Call to a member function setBlockIdAt() on null" (EXCEPTION) in "/Admin/src/DanielYTK/Coder/code" at line 197
    
     
     
  7. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Replace $this on the bottom line with $player...
     
  8. DanielYTK

    DanielYTK Zombie

    Messages:
    227
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I think the player can glitch through the blocks easily. The block could spawn where the player is, so the player's body is half inside the block already.
    Once you've setBlockIdAt(), teleport the player in the middle of the boxed prison.
    PHP:
    $player->teleport($player->floor());
     
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Shouldnt it be
    PHP:
    && $y !== $Y && $y !== $Y+1
     
  11. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    The cage is not a cage, but a lot of blocks that were nothing!
     
  12. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    I tried this, just need to test
    PHP:
    $X $entity->getFloorX();
                    
    $Y $entity->getFloorY();
                    
    $Z $entity->getFloorZ();
                        
    $entity->getLevel()->setBlockIdAt($X -1,$Y,$Z,7); //Isso seta os blocos da cage
                        
    $entity->getLevel()->setBlockIdAt($X +1,$Y,$Z,7);
                        
    $entity->getLevel()->setBlockIdAt($X +1,$Y -1,$\,7);
                        
    $entity->getLevel()->setBlockIdAt($X -1,$Y +2,$Z,7);
                        
    $entity->getLevel()->setBlockIdAt($X -1,$Y +2,$Z -1,7);
                        
    $entity->getLevel()->setBlockIdAt($X -1,$Y +2,$Z +1,7);
     
     
  13. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    sorry for $\
     
  14. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    your code don't work, look: error.png
     
  15. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Hmmm... logic error XD
    replace the if statement with this
    PHP:
    if(!($x === $X && $z === $Z && ($y === $Y || $y === $Y+1))){
         
    $player->level->setBlockIdAt($x,$y,$z,7);
    }
     
  16. DanielYTK

    DanielYTK Zombie

    Messages:
    227
  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.