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.

Make arrows head in a random direction

Discussion in 'Skript' started by MasterHunter2003, Aug 5, 2017.

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

    Joined:
    Jan 28, 2017
    Messages:
    23
    Likes Received:
    1
    Question: How can I make 100 arrows go to a random location
    Code (Skript):
    1.  
    2. on leftclick with diamond:
    3.     make player shoot a fireball
    4.     set {_proj} to last spawned projectile
    5.     wait 5 ticks
    6.     loop all entities:
    7.         if "%loop-entity-1%" = "fireball":
    8.             send "%loop-entity-1%"
    9.             set {_loc} to location of loop-entity-1
    10.             delete loop-entity-1
    11.             spawn a armor stand at {_loc}
    12.             loop all blocks in radius 15 around {_loc}:
    13.                 add location of loop-block to {random.location.loop.blocks.meteor::*}
    14.             loop all players:
    15.                 loop 100 times:
    16.                     set {_number} to a random number between -180 and 180
    17.                     set {_loc2} to a random element out of {random.location.loop.blocks.meteor::*}
    18.                     change yaw of {_loc2} to {_number}
    19.                     make last spawned armor stand shoot an arrow at speed 1 direction from {_loc} to {_loc2}
    20.                     set {hit.%last spawned projectile%} to true
    21.                     delete last spawned armor stand
    --- Double Post Merged, Aug 5, 2017, Original Post Date: Aug 5, 2017 ---
    Anyone? I really need this.
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    229
    wait 24 hours before bumping
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    229
    Oh okay, oops.
    --- Double Post Merged, Aug 6, 2017, Original Post Date: Aug 5, 2017 ---
    Bump.
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    229
    You can make a simple chance system, and set some custom variables, then pull a random variable to determine the direction of the arrow(s), and just simply push the last spawned projectile in the randomly pulled direction.
    I could attempt to make this, let me know if you need an example!
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    229
    I'd appreciate it if you could send me an example.
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    229
    I never really mess with these kinds of things, so this is in a way, way out of my skript knowledge area, but in theory, in my head at least, this could work with tweaks here and there. Enjoy? xD
    Code (Skript):
    1. on leftclick with diamond:
    2.     make player shoot a fireball
    3.     set {_proj} to last spawned projectile
    4.     wait 5 ticks
    5.     loop all entities:
    6.         if "%loop-entity-1%" = "fireball":
    7.             send "%loop-entity-1%"
    8.             set {_loc} to location of loop-entity-1
    9.             delete loop-entity-1
    10.         set {chance} to a random integer between 1 and 6:
    11.             if {chance} is 1:
    12.                 set {dir} to "up"
    13.             if {chance} is 2:
    14.                 set {dir} to "down"
    15.             if {chance} is 3:
    16.                 set {dir} to "north"
    17.             if {chance} is 4:
    18.                 set {dir} to "south"
    19.             if {chance} is 5:
    20.                 set {dir} to "east"
    21.             if {chance} is 6:
    22.                 set {dir} to "west"
    23.         spawn an arrow at {_loc}:
    24.             push last spawned projectile {dir} with force 5.0
    25.            
    Not saying this will work but this is my idea on a roughdraft of code. (the simple variable system and using it to determine which direction the arrow will be pushed)
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    229
    1. Don't use global variables because what's the point of saving them.
    2. There's a much shorter way of doing this. Your code is just too unnecessarily long.

    The code I provided below is an example of how you can push an arrow at a random location.
    Code (Skript):
    1. add north, south, east, west, northwest, northeast, southwest and southeast to {_directions::*}
    2. spawn an arrow above {_loc} # you have to define the {_loc} variable
    3. set {_push} to a random element out of {_directions::*}
    4. push last spawned arrow {_push} at speed 1
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    229
    Thanks for the uh code refining but as I said, it wasn't something I'm good at xP
     
Thread Status:
Not open for further replies.

Share This Page

Loading...