Looping too many blocks crashes server

  • 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.
Aug 8, 2021
37
0
6
21
I am creating a mini-game using skript. Bad news, I am trying to loop blocks in radius 180+ around a block and my server crashes because of the skript checking for many blocks
Code:
on command /test:
    permission:op
    trigger:
        set {test} to 184
        set {test2} to {test} -2
        loop blocks in radius {test} around {center}:
            if the distance between the loop-block and {center} is less than {test2}:

                show wax on at loop-block

test2 is just doing the outside of the sphere to show particles on just the outside
can I make a sphere outside with particles that does not check for millions of blocks?

Thankyou to all that help.
 
Code:
command /test:
    trigger:
        set {_center} to location of player
        set {_radius} to 180 #radius of sphere in blocks
        set {_density} to 250 # density (higher value -> more particles -> more performance impact)

        set {_density} to {_radius}/{_density}
        set {_i} to 0
        while ({_i} <= 180):
            set {_shift} to sin({_i}) * {_radius}
            set {_y} to cos({_i}) * {_radius}
            set {_a} to 0
            while ({_a} < 180): 
                set {_x} to cos({_a}) * {_shift}
                set {_z} to sin({_a}) * {_shift}
                show wax on at ({_center} ~ vector({_x},{_y},{_z}))
                show wax on at ({_center} ~ vector(0-{_x},{_y},0-{_z}))
                add {_density} to {_a}
            add {_density} to {_i}
For optimize you can save locations before sending particles, if center is known before
replace lines 16, 17 with
Code:
     add 1 to {_index}
     set {spheres::mysphere::%{_index}%} to ({_center} ~ vector({_x},{_y},{_z}))
     add 1 to {_index}
     set {spheres::mysphere::%{_index}%} to ({_center} ~ vector(0-{_x},{_y},0-{_z}))
then simply run code when need show precalculated sphere
Code:
loop {spheres::mysphere::*}:
    show wax on at loop-value
 
  • Like
Reactions: Islam1705
Even without this code
Code:
loop {spheres::mysphere::*}:
    show wax on at loop-value

Or line 16 or 17

The server still crashes even with low density
[doublepost=1662490351,1662490316][/doublepost]I'm not sure why it crashes after running that command.
 
idk, I test my code on 1.19.2, with Skript 2.6.3, its crashes only if put high density with low radius or high density with high radius, with values what I set in code - no lags.
 
What should I do? I want to show a closing in spawn like from MCC battlebox without using the worldborder because it goes across the whole world
 
Var 1: World border can be send per player as packet. This is implemented in Skbee addon for example.
Var 2: Using complex addon for work with particle system, as SkDragon, updated fork link
Var 3: Learn some basics and explore code what I send before, because it's works, idk what problem with your's server/client software
 
Status
Not open for further replies.