Loop chunks

  • 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.

sandor_1234

Active Member
Jan 26, 2017
165
5
0
21
How can i get the chunks in the radius x of the player?
Like:
code_language.skript:
loop chunks in radius 4:
   add loop-value to {faction.land::}
 
Oh wait, I wasn't reading your code carefully.

code_language.skript:
loop chunks in radius 4 around player:
You need to specify where the chunks will be looped.
 
Oh wait, I wasn't reading your code carefully.

code_language.skript:
loop chunks in radius 4 around player:
You need to specify where the chunks will be looped.
Nope, already tried that and it doesn't matter in this case :emoji_frowning: .

Can't understand this loop: 'loop chunks in radius 4 around player' (fflagg.sk, line 14: loop chunks in radius 4 around player:')
[doublepost=1497812019,1497811521][/doublepost]I found this as a other way to loop chunks:
https://pastebin.com/ksFZgeYY
It was part of a faction skript which would show a /f map thingy.
Does some one understand how it works? xD
[doublepost=1497937579][/doublepost]Bump
 
I made a function which returns a list of chunks.

Code:
function chunks_in_radius(center: location, radius: number) :: chunks:
    set {_pos} to {_center}
    set z-coordinate of {_pos} to z-coordinate of {_center} - 16 * {_radius}
    loop 2 * {_radius} + 1 times:
        set x-coordinate of {_pos} to x-coordinate of {_center} - 16 * {_radius}
        loop 2 * {_radius} + 1 times:
            add chunk at {_pos} to {_chunks::*}
            add 16 to x-coordinate of {_pos}
        add 16 to z-coordinate of {_pos}
    return {_chunks::*}

Usage:
Code:
set {_chunks::*} to chunks_in_radius(player, 4)
 
I made a function which returns a list of chunks.

Code:
function chunks_in_radius(center: location, radius: number) :: chunks:
    set {_pos} to {_center}
    set z-coordinate of {_pos} to z-coordinate of {_center} - 16 * {_radius}
    loop 2 * {_radius} + 1 times:
        set x-coordinate of {_pos} to x-coordinate of {_center} - 16 * {_radius}
        loop 2 * {_radius} + 1 times:
            add chunk at {_pos} to {_chunks::*}
            add 16 to x-coordinate of {_pos}
        add 16 to z-coordinate of {_pos}
    return {_chunks::*}

Usage:
Code:
set {_chunks::*} to chunks_in_radius(player, 4)
Could you explain me how it works?
Does it just add / remove 16 from the coords to get the chunks around it?
 
Does it just add / remove 16 from the coords to get the chunks around it?

Yes. You give it the center location, then it subtracts the radius in both the x- and z-direction so you end up in a corner of your square. Then it loops only over the x-coordinates until it reaches the maximum. This is basically just a line. Then it resets the x-coordinate and adds 16 to the z-coordinate and loops over the x-coordinates again. This creates a second line next to the first one. This is repeated until it reaches the maximum z-coordinate.
 
Status
Not open for further replies.