Solved On Command event with functions?

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

Wynnevir

Well-Known Member
Jul 9, 2017
1,015
62
48
30
Elsewhere
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_language.skript:
on command "mute":
    if arguments are not set:
        stop
    set {_pl} to player-argument parsed as offline player
    set {_txt} to text-argument
    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!
 
Idk if theres a simpler solution but i messed around and this is what i came up with:
code_language.skript:
on command "mute":
    set {_full_command} to full command
    set {_command_args::*} to {_full_command} split at " "

    #get the player arg
    set {_player_arg} to {_command_args::2}

    #time is a bit trickier because you can either do /mute player 5 minutes or /mute player 5minutes
    set {_time_arg} to {_command_args::3}
    if {_command_args::4} is set:
        set {_time_arg} to "%{_command_args::3}% %{_command_args::4}%"


    broadcast "%{_player_arg}%"
    broadcast "%{_time_arg}%"
 
[doublepost=1499892383,1499890832][/doublepost]
Idk if theres a simpler solution but i messed around and this is what i came up with:
code_language.skript:
on command "mute":
    set {_full_command} to full command
    set {_command_args::*} to {_full_command} split at " "

    #get the player arg
    set {_player_arg} to {_command_args::2}

    #time is a bit trickier because you can either do /mute player 5 minutes or /mute player 5minutes
    set {_time_arg} to {_command_args::3}
    if {_command_args::4} is set:
        set {_time_arg} to "%{_command_args::3}% %{_command_args::4}%"


    broadcast "%{_player_arg}%"
    broadcast "%{_time_arg}%"
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_language.skript:
on command "mute":
    set {_full_command} to full command
    set {_command_args::*} to {_full_command} split at " "
    set {_player_arg} to "%{_command_args::2}%" parsed as offline player
#I didn't think I needed this one if the function didnt utilize it
    set {_time_arg} to {_command_args::3}
    set {_reason_arg} to "%{_command_args::4}%" parsed as text
    addNote({_player_arg}, player, {_reason_arg})
And now my dreams of preset on command note logging may be realized! <3 you da best
 
Oh you must not be using essentials for mutes because you cant give a reason with essentials mute. glad it worked out though
 
Oh you must not be using essentials for mutes because you cant give a reason with essentials mute. glad it worked out though

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
 
Status
Not open for further replies.