How to make Toggleable commands

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

SpawnRusher

Supporter
Jan 9, 2020
8
0
1
17
I couldn't find anything like this, probably due to me searching 1 thing, but let's get on with it.

When I say a "toggleable" command, I mean a command that is used to turn on/off something. Like the command /fly. If you are not in flight mode, you'll be put into flight mode. If you're in flight mode, you will be taken out of flight mode. Here's an easy way to make a toggleable command:
Code:
command /test:
  trigger:
    if {var} isn't set:
      set {var} to true
      # your code
    else:
      delete {var}
      # your code
Now you no longer need to have /commandon and /commandoff commands.

EDIT: Some of you may want to make these player-specific. It's very simple. Take your variable, in this case {var}, and add ::%player's uuid% after the name of the variable.
{var} --> {var::%player's uuid%}
 
command /toggle:
trigger:
if {var.%player%} is set:
delete {var.%player%}
else:
set {var.%player%} to true
 
Status
Not open for further replies.