[HELP] Loop blocks in cube radius

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

TimCom228

Member
Dec 26, 2019
31
0
6
24
I want to loop blocks in radius 16 blocks, like cube, but method:
loop blocks in radius 16 around %location% - does not fit me.
its loop blocks in sphere radius. Help me please =3
 
Try this function:
Code:
function blocksInCube(p: player, r: number) :: blocks:
    set {_loc1} to location of {_p}
    set {_loc2} to location of {_p}
 
    remove {_r} from x coord of {_loc1}
    remove {_r} from y coord of {_loc1}
    remove {_r} from z coord of {_loc1}
 
    add {_r} to x coord of {_loc2}
    add {_r} to y coord of {_loc2}
    add {_r} to z coord of {_loc2}
 
    return blocks within {_loc1} to {_loc2}
where `p` is player and `r` is radius (half length of the side of cube)

Usage:
Code:
command /cube <number>:
    trigger:
        loop blocksInCube(player, arg-1):
            set loop-block to air

EDIT: Correct syntax for looping blocks is:
Code:
blocks within pos1 to pos2

My bad, sorry, I corrected the function above. It should be working just fine now.
 
Last edited:
not give error, but its not work.
Note that my example usage code sets nearby blocks to air. That means nothing changes when you don't have any blocks around you. Try changing for example `air` to `stone` and try again. (You will get stuck inside the cube.)
The code should be working fine, I tested it several times.
 
Try values > 0. The equation for this is `2 * r + 1` (diameter + block which player stands on), so if you put there 0 the result would be 1 = single block on player location.
 
yes! its work:
Code:
 function blocksInCube(p: player) :: blocks:
    set {_loc1} to location of {_p}
    set {_loc2} to location of {_p}
    remove 3 from x coord of {_loc1}
    remove 3 from y coord of {_loc1}
    remove 3 from z coord of {_loc1}
    add 3 to x coord of {_loc2}
    add 3 to y coord of {_loc2}
    add 3 to z coord of {_loc2}
    return blocks within {_loc1} to {_loc2}
[doublepost=1608047435,1608047169][/doublepost]can you help me do this loop, but around event-block.
something like function blocksInCube(b: block)
 
Code:
function blocksInCube(b: block, r: number) :: blocks:
    set {_loc1} to location of {_b}
    set {_loc2} to location of {_b}
 
    remove {_r} from x coord of {_loc1}
    remove {_r} from y coord of {_loc1}
    remove {_r} from z coord of {_loc1}
 
    add {_r} to x coord of {_loc2}
    add {_r} to y coord of {_loc2}
    add {_r} to z coord of {_loc2}
 
    return blocks within {_loc1} to {_loc2}
 
Status
Not open for further replies.