1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Looping too many blocks crashes server

Discussion in 'Skript' started by ApplePenChicken, Sep 6, 2022.

Thread Status:
Not open for further replies.
  1. ApplePenChicken

    Joined:
    Aug 8, 2021
    Messages:
    30
    Likes Received:
    0
    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 (Text):
    1. on command /test:
    2.     permission:op
    3.     trigger:
    4.         set {test} to 184
    5.         set {test2} to {test} -2
    6.         loop blocks in radius {test} around {center}:
    7.             if the distance between the loop-block and {center} is less than {test2}:
    8.  
    9.                 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.
     
  2. lotzy

    lotzy Active Member

    Joined:
    Mar 15, 2022
    Messages:
    139
    Likes Received:
    22
    Code (Text):
    1. command /test:
    2.     trigger:
    3.         set {_center} to location of player
    4.         set {_radius} to 180 #radius of sphere in blocks
    5.         set {_density} to 250 # density (higher value -> more particles -> more performance impact)
    6.  
    7.         set {_density} to {_radius}/{_density}
    8.         set {_i} to 0
    9.         while ({_i} <= 180):
    10.             set {_shift} to sin({_i}) * {_radius}
    11.             set {_y} to cos({_i}) * {_radius}
    12.             set {_a} to 0
    13.             while ({_a} < 180):
    14.                 set {_x} to cos({_a}) * {_shift}
    15.                 set {_z} to sin({_a}) * {_shift}
    16.                 show wax on at ({_center} ~ vector({_x},{_y},{_z}))
    17.                 show wax on at ({_center} ~ vector(0-{_x},{_y},0-{_z}))
    18.                 add {_density} to {_a}
    19.             add {_density} to {_i}
    For optimize you can save locations before sending particles, if center is known before
    replace lines 16, 17 with
    Code (Text):
    1.      add 1 to {_index}
    2.      set {spheres::mysphere::%{_index}%} to ({_center} ~ vector({_x},{_y},{_z}))
    3.      add 1 to {_index}
    4.      set {spheres::mysphere::%{_index}%} to ({_center} ~ vector(0-{_x},{_y},0-{_z}))
    then simply run code when need show precalculated sphere
    Code (Text):
    1. loop {spheres::mysphere::*}:
    2.     show wax on at loop-value
     
  3. ApplePenChicken

    Joined:
    Aug 8, 2021
    Messages:
    30
    Likes Received:
    0
    Even without this code
    Code (Text):
    1. loop {spheres::mysphere::*}:
    2.     show wax on at loop-value
    Or line 16 or 17

    The server still crashes even with low density
    --- Double Post Merged, Sep 6, 2022, Original Post Date: Sep 6, 2022 ---
    I'm not sure why it crashes after running that command.
     
  4. lotzy

    lotzy Active Member

    Joined:
    Mar 15, 2022
    Messages:
    139
    Likes Received:
    22
    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.
     
  5. ApplePenChicken

    Joined:
    Aug 8, 2021
    Messages:
    30
    Likes Received:
    0
    oh
    --- Double Post Merged, Sep 6, 2022, Original Post Date: Sep 6, 2022 ---
    Because with your settings, I still got timed out.
     
  6. lotzy

    lotzy Active Member

    Joined:
    Mar 15, 2022
    Messages:
    139
    Likes Received:
    22
    But timed out without crash isn't code problem, your's client cant perform all particle packets
     
  7. ApplePenChicken

    Joined:
    Aug 8, 2021
    Messages:
    30
    Likes Received:
    0
    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
     
  8. lotzy

    lotzy Active Member

    Joined:
    Mar 15, 2022
    Messages:
    139
    Likes Received:
    22
    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
     
Thread Status:
Not open for further replies.

Share This Page

Loading...