# Loop chunks

Discussion in 'Skript' started by sandor_1234, Jun 18, 2017.

Not open for further replies.
1. ### sandor_1234 Active Member

Joined:
Jan 26, 2017
Messages:
165
5
How can i get the chunks in the radius x of the player?
Like:
Code (Skript):
1. loop chunks in radius 4:

#1
2. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,184
231
Try loop-chunk?

#2
3. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,184
231
The first part won't work:
The second part probably will work fine.

#3
4. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,184
231

Code (Skript):
1. loop chunks in radius 4 around player:
You need to specify where the chunks will be looped.

#4
5. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,184
231
Nope, already tried that and it doesn't matter in this case .

Can't understand this loop: 'loop chunks in radius 4 around player' (fflagg.sk, line 14: loop chunks in radius 4 around player:')
--- Double Post Merged, Jun 18, 2017, Original Post Date: Jun 18, 2017 ---
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
--- Double Post Merged, Jun 20, 2017 ---
Bump

#5
6. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,184
231
I made a function which returns a list of chunks.

Code (Text):
1.
3.     set {_pos} to {_center}
4.     set z-coordinate of {_pos} to z-coordinate of {_center} - 16 * {_radius}
5.     loop 2 * {_radius} + 1 times:
6.         set x-coordinate of {_pos} to x-coordinate of {_center} - 16 * {_radius}
7.         loop 2 * {_radius} + 1 times:
8.             add chunk at {_pos} to {_chunks::*}
9.             add 16 to x-coordinate of {_pos}
10.         add 16 to z-coordinate of {_pos}
11.     return {_chunks::*}
12.
Usage:
Code (Text):
1.
2. set {_chunks::*} to chunks_in_radius(player, 4)
3.

#6
• Useful x 1
7. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,184
231
Could you explain me how it works?
Does it just add / remove 16 from the coords to get the chunks around it?

#7
8. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,184
231
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.

#8
Not open for further replies.