Using same code many times..?

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

IxtraDeath

Member
Feb 23, 2017
16
0
0
25
Hi,

I want to ask if it posibble to save a code in a function or variable to use it many times without typing the whole code everytime?

If it's functions. can someone tell me how?

i don't want to use the same code over and over (not full code):
code_language.skript:
        if {@PermissionEX} is true:
            if argument 1 is not set:
                send "&eSetrank:&7 Something is not right?"
                wait a tick
                send "&cUsage: /setrank <Player> <Rank>"
                stop
            if argument 2 is not set:
                send "&eSetrank:&e Something is not right?"
                send "&cUsage: /setrank <Player> <Rank>"
                stop
        if {@GroupManager} is true:
            if argument 1 is not set:
                send "&eSetrank:&7 Something is not right?"
                send "&cUsage: /setrank <Player> <Rank>"
                stop
            if argument 2 is not set:
                send "&eSetrank:&e Something is not right?"
                send "&cUsage: /setrank <Player> <Rank>"
                stop
        if {@zPermission} is true:
            if argument 1 is not set:
                send "&eSetrank:&7 Something is not right?"
                send "&cUsage: /setrank <Player> <Rank>"
                stop
            if argument 2 is not set:
                send "&eSetrank:&e Something is not right?"
                send "&cUsage: /setrank <Player> <Rank>"
                stop

Thanks in advance :emoji_slight_smile:
 
This is a bit shorter and shoud work fine

code_language.skript:
if "{@PermissionEX}{@GroupManager}{@zPermission}" contains "true":
    if arg-2 isn't set:
        send "&eSetrank:&e Something is not right?"
        send "&cUsage: /setrank <Player> <Rank>"
    else if arg-1 isn't set:
        send "&eSetrank:&7 Something is not right?"
        send "&cUsage: /setrank <Player> <Rank>"
   stop
 
code_language.skript:
if {@PermissionEX} is true or {@GroupManager} is true or {@zPermission} is true:
    if arg-2 isn't set:
        send "&eSetrank:&e Something is not right?"
        send "&cUsage: /setrank <Player> <Rank>"
    else if arg-1 isn't set:
        send "&eSetrank:&7 Something is not right?"
        send "&cUsage: /setrank <Player> <Rank>"
   stop

should work aswell and is less "dirty" than @Duetro's solution
 
code_language.skript:
if {@PermissionEX} is true or {@GroupManager} is true or {@zPermission} is true:
    if arg-2 isn't set:
        send "&eSetrank:&e Something is not right?"
        send "&cUsage: /setrank <Player> <Rank>"
    else if arg-1 isn't set:
        send "&eSetrank:&7 Something is not right?"
        send "&cUsage: /setrank <Player> <Rank>"
   stop

should work aswell and is less "dirty" than @Duetro's solution

how about else? (if arguments was set) It's same but diffrenet command for each

code_language.skript:
            else:
                wait 2 tick
                make console execute command "pex user %arg-1% group set %arg-2%"
                wait 1 tick
                if {@broadcastRankChange} is true:
                    broadcast "{@prefix} &6%arg-1%'s &erank has been changed to &6%arg-2%"
                message "&eSetrank: &7Success! &e%arg-1%&7 's rank was changed to &e%arg-2%&7."
                stop
 
Status
Not open for further replies.