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

Help with editing this code

Discussion in 'Development' started by Kabluinc, Oct 22, 2017.

  1. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    Hi,

    Currently for a blockParty minigame, this code below is used to reset the floor and set the block colors of the floor. At the moment this piece of code sets a certain block color with size 3x3.

    PHP:
    public function resetFloor(){
            
    $colorcount 0;
            
    $blocks 0;
            
    $y $this->data['arena']['floor_y'];
            
    $level =  $this->plugin->getServer()->getLevelByName($this->data['arena']['arena_world']);
            for(
    $x min($this->data['arena']['first_corner_x'], $this->data['arena']['second_corner_x']); $x <= max($this->data['arena']['first_corner_x'], $this->data['arena']['second_corner_x']); $x += 3){
                for(
    $z min($this->data['arena']['first_corner_z'], $this->data['arena']['second_corner_z']); $z <= max($this->data['arena']['first_corner_z'], $this->data['arena']['second_corner_z']); $z += 3){
                    
    $blocks++;
                    
    $color rand(015);
                    if(
    $colorcount === && $blocks === 15 || $colorcount <= && $blocks === 40){
                        
    $color $this->currentColor;
                    }
                    
    $block Block::get($this->getBlock(), $color);
                    if(
    $block->getDamage() === $this->currentColor){
                        
    $colorcount++;
                    }
                    
    $level->setBlock(new Position($x$y$z$level), $blockfalsetrue);
                    
    $level->setBlock(new Position($x$y$z+1$level), $blockfalsetrue);
                    
    $level->setBlock(new Position($x$y$z+2$level), $blockfalsetrue);
                    
    $level->setBlock(new Position($x+1$y$z$level), $blockfalsetrue);
                    
    $level->setBlock(new Position($x+1$y$z+1$level), $blockfalsetrue);
                    
    $level->setBlock(new Position($x+1$y$z+2$level), $blockfalsetrue);
                    
    $level->setBlock(new Position($x+2$y$z$level), $blockfalsetrue);
                    
    $level->setBlock(new Position($x+2$y$z+1$level), $blockfalsetrue);
                    
    $level->setBlock(new Position($x+2$y$z+2$level), $blockfalsetrue);
                }
            }
        }
    However, I would like it so that it only sets the color blocks as 1x1 not 3x3. How can I achieve this thru editing the code above? Any help would be very appreciated :)
     
  2. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    remove all of these:
    PHP:
    $level->setBlock(new Position($x$y$z+1$level), $blockfalsetrue);
    $level->setBlock(new Position($x$y$z+2$level), $blockfalsetrue);
    $level->setBlock(new Position($x+1$y$z$level), $blockfalsetrue);
    $level->setBlock(new Position($x+1$y$z+1$level), $blockfalsetrue);
    $level->setBlock(new Position($x+1$y$z+2$level), $blockfalsetrue);
    $level->setBlock(new Position($x+2$y$z$level), $blockfalsetrue);
    $level->setBlock(new Position($x+2$y$z+1$level), $blockfalsetrue);
    $level->setBlock(new Position($x+2$y$z+2$level), $blockfalsetrue);
     
    Last edited: Oct 22, 2017
    Kabluinc likes this.
  3. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    After removing those and only leaving these 2 lines

    PHP:
     $level->setBlock(new Position($x$y$z$level), $blockfalsetrue);
     
    $level->setBlock(new Position($x$y$z+1$level), $blockfalsetrue);
    This is the result:

    https://www.imgur.com/a/zn3hU
     
  4. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    Anyone have any idea how to do this? :)
     
  5. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Just leave this line:
    PHP:
    $level->setBlock(new Position($x$y$z$level), $blockfalsetrue);
    The additions and subtractions to the $x and $z are what make it 3x3. If you really want it to be 1x1 without any chance of any blocks going next to one another, I'd check the blocks around it to see if they match the color about to be set, and if so, change the color.
     
    jasonwynn10 and Kabluinc like this.
  6. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    Tysm
     
  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.