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

Solved Random Block in Loop Radius

Discussion in 'Skript' started by FL3PHi, Jul 7, 2017.

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

    FL3PHi Member

    Joined:
    Jul 7, 2017
    Messages:
    3
    Likes Received:
    0
    Hey!

    I've been trying to make a skript, but I ran into a problem that I can't solve.
    (Been using skript for about 2 weeks)

    How could I loop blocks in radius 5 of player and then select a random block from the looped blocks
    and I used "on any movement:" from SkQuery, but I'd like to change that just to movement, not mouse movement aswell, but I have no idea how.

    I tried (Didn't work):

    Code (Skript):
    1. on any movement:
    2.     loop all blocks in radius 3 around player:
    3.         set {block} to random loop-block
    4.         if {variable.%player%} is set:
    5.             make {variable.%player%} pathfind to {block} with speed 1.25
    I would appreciate any sort of help <3
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    157
    Code (Skript):
    1. loop blocks in radius 5 around player:
    2.     add loop-block to {_blocks::*}
    3. set {_block} to random element of {_blocks::*}
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    157
    Wouldn't that mean, that it would constantly add blocks to the variable and then they would stay in there? I need them to be cleared every move to the new blocks around player
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    157
    It's a local variable so it gets deleted after the event or you can use a normal variable and just delete it every time
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    157
    Thank you <3
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    157
    That's not very efficient because skript loops aren't great. Not to mention it's over complex. A much better solution is
    Code (Skript):
    1. a random element out of blocks in radius 5 of player
     
Thread Status:
Not open for further replies.
Loading...