I need help with skript 2.2

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

BettingCamp

New Member
Oct 20, 2023
8
1
3
19
So I made a skript but it's not working.


code_language.skript:
on command "/lp user * parent set owner":
    trigger:
        set {_playerName} to arg-1
        cancel event
        if {_playerName} is set:
            set {_player} to player named {_playerName}
            if {_player} is online:
                execute console command "/lp user {_playerName} parent set default"
                send "{_player} &cYou cannot set your parent to 'owner'. Changing to default rank."

so basically, when a player runs command 'lp user [playername] parent set owner'. the console sets the player to default rank, but its not working.

can anyone fix it..
 
There's a few things going on here.

1.) "on command %string%" doesn't have a "trigger:" section, because you're not registering a new command; you're creating behavior when a preexisting command is run.

2.) I don't believe you can use expressions like arg-1, arg-2, or refer to arguments in general (or at least it's never worked for me) in an "on command %string%" event. Every situation I've used "on command %string%" requires me to refer to "the full command", which is a string, and I have to get arguments by splitting it.

3.) You need %'s to wrap around variable names within strings, otherwise it'll literally type "{_playerName}" instead of the player stored in that variable. Same goes for {_player}.

4.) Wildcard characters aren't a thing in Skript, I don't think. I've been using Skript for about 4 years, and I haven't seen anyone been able to use * like that. There's a chance it works (most languages have some form of that), but I'd be more comfortable doing 'on command "/lp user"' and splitting the full command to get its args, especially because it's not ambiguous as to whether Skript parses the * as a wildcard or as a literal *.

I'll follow up with code in a moment. Just wanted to send this off so you get a response immediately.
 
There's a few things going on here.

1.) "on command %string%" doesn't have a "trigger:" section, because you're not registering a new command; you're creating behavior when a preexisting command is run.

2.) I don't believe you can use expressions like arg-1, arg-2, or refer to arguments in general (or at least it's never worked for me) in an "on command %string%" event. Every situation I've used "on command %string%" requires me to refer to "the full command", which is a string, and I have to get arguments by splitting it.

3.) You need %'s to wrap around variable names within strings, otherwise it'll literally type "{_playerName}" instead of the player stored in that variable. Same goes for {_player}.

4.) Wildcard characters aren't a thing in Skript, I don't think. I've been using Skript for about 4 years, and I haven't seen anyone been able to use * like that. There's a chance it works (most languages have some form of that), but I'd be more comfortable doing 'on command "/lp user"' and splitting the full command to get its args, especially because it's not ambiguous as to whether Skript parses the * as a wildcard or as a literal *.

I'll follow up with code in a moment. Just wanted to send this off so you get a response immediately.
Here you go:
code_language.skript:
on command "/lp user":
  if the full command contains "parent set owner":
    set {_arg::*} to split the full command at " " # sets each element to each word, basically
    set {_playerName} to {_arg::3} # this would be at "/lp user >>> HERE <<<"
    cancel event
    if {_playerName} is set:
      loop all players: # im less comfortable with 'player named %string%'. that just hasn't worked for me. this is a worthy alternative
        if name of loop-player is {_playerName}: # this also only works if they're online
          execute console command "/lp user %{_playerName}% parent set default"
          send "&cYou cannot set your parent to 'owner'. Changing to default rank." to loop-player
It's been a while since I've used such a low Skript version. It was a fun exercise.

My only concern with this is that it works, even when the player that ran the command isn't the same player put in the command, so practically anyone (with permission or not) can run /lp user %player% parent set owner and inflict default rank upon anyone. Here's a fix though:

code_language.skript:
on command "/lp user":
  if the full command contains "parent set owner":
    set {_arg::*} to split the full command at " " # sets each element to each word, basically
    set {_playerName} to {_arg::3} # this would be at "/lp user >>> HERE <<<"
    cancel event
    if {_playerName} is set:
      loop all players: # im less comfortable with 'player named %string%'. that just hasn't worked for me. this is a worthy alternative
        if name of loop-player is {_playerName}: # this also only works if they're online
          if loop-player is player:
            send "&cYou cannot set your parent to 'owner'. Changing to default rank"
            execute console command "/lp user %{_playerName}% parent set default"
          else:
            send "&cYou cannot set someones parent to 'owner'."

Let me know if anything works or doesn't work. Hope this helped.