Solved Help with setting spawn intervals on command with arguments

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

Plav

Member
Dec 18, 2022
14
1
3
25
The other day got help with a skript that lets me activate and deactivate a item spawner with a command, but I want to take that even further, rather then just being able to activate and deactivate the spawner, I could set its intervial in the command. I want it so that the first argument would be the on/off, the second would be the number, and the third would be the time type (ticks, seconds, minutes, hours). the second and third arguments would be optional incase I just wanted to activate and deactivate the skript. so for example to turn it on I would do /berries on 3 t, and that would spawn a dirt every 3 ticks, or just /berries off. to turn it off, if possible can someone please edit the skript and send it back so it can do this.
Code:
command /berries:
    permission: berries.spawn
    trigger:
        if {berries.enabled} is true:
            set {berries.enabled} to false
            send "&cBerry spawner disabled" to player
        else:
            set {berries.enabled} to true
            send "&2Berry spawner enabled" to player
 
every minute:
    {berries.enabled} is true
    drop 1 sweet berries at location(4352.5,97,4137.5, world "world") without velocity
    drop 1 sweet berries at location(4352.5,97,4131.5, world "world") without velocity
    drop 1 sweet berries at location(4357.5,97,4131.5, world "world") without velocity
    drop 1 sweet berries at location(4357.5,97,4137.5, world "world") without velocity
    drop 1 sweet berries at location(4347.5,97,4131.5, world "world") without velocity
    drop 1 sweet berries at location(4342.5,97,4131.5, world "world") without velocity
    drop 1 sweet berries at location(4342.5,97,4137.5, world "world") without velocity
    drop 1 sweet berries at location(4347.5,97,4137.5, world "world") without velocity
 
we meet again :emoji_wink:
Code:
function DropBerries():
    drop 1 sweet berries at location(4352.5,97,4137.5, world "world") without velocity
    drop 1 sweet berries at location(4352.5,97,4131.5, world "world") without velocity
    drop 1 sweet berries at location(4357.5,97,4131.5, world "world") without velocity
    drop 1 sweet berries at location(4357.5,97,4137.5, world "world") without velocity
    drop 1 sweet berries at location(4347.5,97,4131.5, world "world") without velocity
    drop 1 sweet berries at location(4342.5,97,4131.5, world "world") without velocity
    drop 1 sweet berries at location(4342.5,97,4137.5, world "world") without velocity
    drop 1 sweet berries at location(4347.5,97,4137.5, world "world") without velocity

function Spawner():
    # check if spawner is active
    {berries.enabled} is true

    # wait interval set
    wait "%{berries.interval}% %{berries.intervalType}%" parsed as timespan

    # drop the berries
    DropBerries()

    # restart spawner
    Spawner()

# <required argument> [<optional argument>]
command /berries <text> [<text>] [<text>]:
    permission: berries.spawn
    usage: &cUsage: /berries <on/off> <interval> <interval type>
    trigger:

        # add valid interval types to a list
        add "ticks" to {intervaltypes::*}
        add "seconds" to {intervaltypes::*}
        add "minutes" to {intervaltypes::*}
        add "hours" to {intervaltypes::*}
        
        # check if arg-3 is a valid intervaltype
        if {intervaltypes::*} contains arg-3:
            set {berries.interval} to arg-2
            set {berries.intervalType} to arg-3
        
        # check if you didn't use a valid interval type
        else if arg-2 is set:
            send "&cInvalid argument! (intervalType)"
            send "&cUsage: /berries <on/off> <interval> <interval type>" to player
            send "&cExample: /berries on 5 minutes" to player
            stop
        
        # turn on spawner
        if arg-1 is "on":
            # check if spawner is already on
            if {berries.enabled} is true:
                send "&cSpawner already active!"
                stop

            set {berries.enabled} to true
            send "&2Berry spawner enabled" to player
            send "&2Interval set to &6%{berries.interval}% %{berries.intervalType}%"

        else if arg-1 is "off":
            set {berries.enabled} to false
            send "&cBerry spawner disabled" to player
        
        else:
            send "&cInvalid argument! (on/off)" to player
            send "&cUsage: /berries <on/off> <interval> <interval type>" to player
            send "&cExample: /berries on 1 minutes" to player
            stop
        
        # start the spawner
        Spawner()
 
Status
Not open for further replies.