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.

FireRoz

Active Member
May 28, 2020
133
6
18
hi, I know this is a stupid request and is not a frequently used in Skript. Though, I am trying to make it that when I vanish, my name tag will change to [V] FireRoz The problem is, if you do /vanish <other player>, it won't do it as I didn't define arguments.
Here's my code
Code:
on join:
  player has permission "sv.see"
  set player's nametag to "&7[V] %player%"
  set {v.%player%} to true
 
on command "/v" or "/vanish":
  if {v.%player%} is not set:
    set {v.%player%} to true
    set player's nametag to "&7[V] %player%"
    stop trigger
    stop
    
  if {v.%player%} is set:
    set {v.%player%} to false
    clear {v.%player%}
    reset player's nametag
    stop
    
on command "/vanish on" or "/v on":
  set {v.%player%} to true
  set player's nametag to "&7[V] %player%"
 
on command "/v off" or "/vanish off":
  set {v.%player%} to false
  reset player's nametag

Thank you for your time.
 
for your command, try using arg-1 instead of player im quite confused and I dont see

Code:
command /v:
    blah blah arg-1 blah
 
for your command, try using arg-1 instead of player im quite confused and I dont see

Code:
command /v:
    blah blah arg-1 blah
when I use "on command" it says
'"test to' is not a type.
and i want it to execute a command that already exists in supervanish, not create a new command.
thank you for your time
 
You have to make custom command arguments parser and overload the command like so:
Code:
on join:
  player has permission "sv.see"
  set player's nametag to "&7[V] %player%"
  set {v.%player%} to true
 
on command "/v" or "/vanish":
  #Parse command arguments
  set {_command} to full command
  set {_args::*} to {_command} split at " "
  set {_player_arg} to "%{_args::2}%" parsed as player
 
  #Command overloading
  set {_player} to player
  if {_player_arg} is set:
    set {_player} to {_player_arg}

  #Use `{_player}` instead of `player`
  if {v.%{_player}%} is not set:
    set {v.%{_player}%} to true
    set player's nametag to "&7[V] %player%"
    stop trigger
    stop
  
  if {v.%{_player}%} is set:
    set {v.%{_player}%} to false
    clear {v.%{_player}%}
    reset player's nametag
    stop
  
on command "/vanish on" or "/v on":
  set {v.%player%} to true
  set player's nametag to "&7[V] %player%"
 
on command "/v off" or "/vanish off":
  set {v.%player%} to false
  reset player's nametag
 
You have to make custom command arguments parser and overload the command like so:
Code:
on join:
  player has permission "sv.see"
  set player's nametag to "&7[V] %player%"
  set {v.%player%} to true
 
on command "/v" or "/vanish":
  #Parse command arguments
  set {_command} to full command
  set {_args::*} to {_command} split at " "
  set {_player_arg} to "%{_args::2}%" parsed as player
 
  #Command overloading
  set {_player} to player
  if {_player_arg} is set:
    set {_player} to {_player_arg}

  #Use `{_player}` instead of `player`
  if {v.%{_player}%} is not set:
    set {v.%{_player}%} to true
    set player's nametag to "&7[V] %player%"
    stop trigger
    stop
 
  if {v.%{_player}%} is set:
    set {v.%{_player}%} to false
    clear {v.%{_player}%}
    reset player's nametag
    stop
 
on command "/vanish on" or "/v on":
  set {v.%player%} to true
  set player's nametag to "&7[V] %player%"
 
on command "/v off" or "/vanish off":
  set {v.%player%} to false
  reset player's nametag

Great, but the syntax is "command /v:" and not "on command /v:".
 
Great, but the syntax is "command /v:" and not "on command /v:".
Look what @FireRoz said:
i want it to execute a command that already exists in supervanish, not create a new command.

think what he's trying to do is to overwrite an existing command, and not creating a new command, so on command "/v": should be correct
https://skriptlang.github.io/Skript/events.html#command
Yes, this is exactly what he requested.
 
Status
Not open for further replies.