Simple Circle Generator

Share scripts you wrote for Denizen-Bukkit here!
Post Reply
User avatar
Posts: 3
Joined: August 6th, 2016, 8:33 am

Simple Circle Generator

Post by Fortifier » June 22nd, 2020, 6:28 pm

This script generates a circle, and then plays an effect at each point on the circle.
Read the comments for info on definitions.

Code: Select all

- run CircleGenerator def:[Location](|Radius)(|Stepsize)(|Effect)(|Delay)
All definitions are optional except the starting location.

It creates the circle, then displays the points so the generation part can be taken and used elsewhere if you so desire.

Raw code:

Code: Select all

    type: task
    debug: false
    # Centre is the centre of the circle.
    # Radius is the size of the circle.
    # Step size is the distance between each point.
    # Effect is the type of effects to play.
    # Delay is the delay between creating each point.
    definitions: centre|radius|stepsize|effect|delay
        - if !<[centre].exists>:
            - narrate "<red>A centre point must be specified!"
            - stop
        # Start at 0.
        - define angle 0
        # Default the radius to 1 block.
        - if !<[radius].exists>:
            - define radius 1
        # Default the step size to 0.1 blocks.
        - if !<[stepsize].exists>:
            - define stepsize 0.1
        # Default the effect to a flame.
        - if !<[effect].exists>:
            - define effect flame
        # Select a random effect
        - if <[effect]> == random:
            - define effect <server.particle_types.random>
        # Instantly create if no delay is specified.
        - if !<[delay].exists>:
            - define delay 0
        - define points <list[]>

        # We want to step until the angle is 2 x pi (a full circle is 2 x pi radians.).
        - while <[angle].is[LESS].than[<util.pi.mul[2]>]>:
            # calculate X
            - define x <[radius].mul[<[angle].cos>]>
            # calculate Z (for some stupid reason Y is up and down).
            - define z <[radius].mul[<[angle].sin>]>
            # Add our step size to the total angle.
            - define angle:+:<[stepsize]>
            # Add the point to our list.
            - define points:->:<[centre].add[<[x]>,0,<[z]>]>

        # Delay each step if specified in our run.
        - if <[delay]> != 0:
            # Playeffect at each point individually.
            - foreach <[points]> as:point:
                - playeffect effect:<[effect]> at:<[point]> offset:0 quantity:2
                # Deley between each point.
                - wait <[delay]>t
            - stop
        # If delay is 0 (instant), we create the circle in one hit.
        - playeffect at:<[points]> effect:<[effect]> offset:0 quantity:2


User avatar
Site Admin
Site Admin
Posts: 299
Joined: August 5th, 2016, 7:27 pm
Location: Los Angeles, California, USA

Re: Simple Circle Generator

Post by mcmonkey » June 23rd, 2020, 1:59 am

Are you not aware that the rotate_around_y tag exists? Cause it'd make this script a bit simpler.

... Also why are you forcing delay input to be ticks, instead of letting users input a duration?

Also, "random" is literally valid effect type input to the PlayEffect command, you don't need to custom-handle it.

Also, that while loop with a define inside is just an overcomplicated repeat knockoff.

Also, once you make use of rotate_around tags, you start to realize that you don't need a loop command at all and can instead literally just one-line it with a clever tag.
Something like: <util.list_numbers_to[<element[360].div[<[stepsize]>]>].parse_tag[<location[<[radius]>,0,0].rotate_around_y[<[parse_value].mul[<[stepsize]>].to_radians>]>]> (a bit long, but could be easily cleaned up by using a few defines).

Also, all of those - if !<[somedef].exists>: - define somedef somedefault are just overcomplicated fallbacks.

Also, what's with the stop command? That looks like you just need an else.

Here's a quick and easy 11 lines that does the same as your 40+ lines.

Code: Select all

    type: task
    definitions: center|radius|stepsize|effect|delay
         - define stepsize <[stepsize]||0.1>
        - define loc <location[<[radius]||1>,0,0]>
        - define stepmul <[stepsize].to_radians>
        - define points <util.list_numbers_to[<element[360].div[<[stepsize]>]>]>
        - define points <[points].parse_tag[<[center].add[<[loc].rotate_around_y[<[parse_value].mul[<[stepmul]>]>]>]>]>
        - if <[delay]||0> != 0:
            - foreach <[points]> as:point:
                - playeffect effect:<[effect]||flame> at:<[point]> offset:0 quantity:2
                - wait <[delay]>
        - else:
            - playeffect at:<[points]> effect:<[effect]||flame> offset:0 quantity:2
Denizen lead developer. On Discord as mcmonkey#6666.

Posts: 18
Joined: January 29th, 2020, 4:40 pm

Re: Simple Circle Generator

Post by Berufeng » June 23rd, 2020, 10:32 am

mcmonkey wrote:
June 23rd, 2020, 1:59 am
Here's a quick and easy 11 lines that does the same as your 40+ lines.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest