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.

Solved On Command event with functions?

Discussion in 'Skript' started by Wynnevir, Jul 12, 2017.

Tags:
Thread Status:
Not open for further replies.
  1. Wynnevir

    Wynnevir Well-Known Member

    Joined:
    Jul 9, 2017
    Messages:
    1,016
    Likes Received:
    62
    Using 2.2 Dev 29.
    I've been beating my head against a wall for a while here trying to call a function in an On Command event.
    Is it even possible if arguments can't be used in an On Command event?
    If so, what I want to accomplish is when a command is used, like /mute or /jail etc, it executes a function that logs a note. so something like this:
    Code (Skript):
    1. on command "mute":
    2.     if arguments are not set:
    3.         stop
    4.     set {_pl} to player-argument parsed as offline player
    5.     set {_txt} to text-argument
    6.     addNote(player, player, text)
    This, of course, produces the error that arguments can't be used in an On Command event. I can get the function to call properly from within a custom command by setting those arguments, but it'd really stink to have to remake all the mute and jail commands.
    Any advice? Thanks so much!

     
  2. Best Answer:
    Post #3 by ShaneBee, Jul 12, 2017
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    Idk if theres a simpler solution but i messed around and this is what i came up with:
    Code (Skript):
    1. on command "mute":
    2.     set {_full_command} to full command
    3.     set {_command_args::*} to {_full_command} split at " "
    4.  
    5.     #get the player arg
    6.     set {_player_arg} to {_command_args::2}
    7.  
    8.     #time is a bit trickier because you can either do /mute player 5 minutes or /mute player 5minutes
    9.     set {_time_arg} to {_command_args::3}
    10.     if {_command_args::4} is set:
    11.         set {_time_arg} to "%{_command_args::3}% %{_command_args::4}%"
    12.  
    13.  
    14.     broadcast "%{_player_arg}%"
    15.     broadcast "%{_time_arg}%"
     
    • Winner Winner x 1
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    --- Double Post Merged, Jul 12, 2017, Original Post Date: Jul 12, 2017 ---
    Figured it out! so first I was a dope and sent over {_command_args::2} instead of {_player_arg}. derp.
    But it only works if you put the prior in percents and parenthesis and then parse it, it seems.
    So this right here ended up being the format that worked:
    Code (Skript):
    1. on command "mute":
    2.     set {_full_command} to full command
    3.     set {_command_args::*} to {_full_command} split at " "
    4.     set {_player_arg} to "%{_command_args::2}%" parsed as offline player
    5. #I didn't think I needed this one if the function didnt utilize it
    6.     set {_time_arg} to {_command_args::3}
    7.     set {_reason_arg} to "%{_command_args::4}%" parsed as text
    8.     addNote({_player_arg}, player, {_reason_arg})
    And now my dreams of preset on command note logging may be realized! <3 you da best
     
  5. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    Oh you must not be using essentials for mutes because you cant give a reason with essentials mute. glad it worked out though
     
  6. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    I am using Essentials:emoji_slight_smile: It won't display a "reason" in chat like it does for kicks or jails but with the way you showed me here to set the arguments to a list index variable thing it will still take my additional reason argument for the note add function
     
Thread Status:
Not open for further replies.

Share This Page

Loading...