Help with making code more compact

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

    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.

Fatboys

Member
Mar 8, 2017
23
1
0
So I created a queuing system where a player can join a queue and once the queue is full, or 30 seconds has passed in the queue, the game will start and the list of players in the queue will be transferred over into a number and an arena will be set. And the way I'm checking the amount of players left in game is with my {game1} variable. Each {game} variable correspond with {arena} variable. {arena2} = {arena2} and so on..

code_language.skript:
command /queue [<text="check">]:
    usage: You can either use &c/queue join &for &c/queue leave
    trigger:
        if arg-1 is "check":
            send "&cThere are &e%{queue}%/16 &cplayers in the queue!" to player
        if arg-1 is "join":
            if {game1::%player%} or {game2::%player%} or {game3::%player%} or {game4::%player%} or {game5::%player%} is 0:
                if {arena1} or {arena2} or {arena3} or {arena4} or {arena5} is 0:
                    if {queue} >= 16:
                        send "&cThe queue is full!" to player
                    else:
                        if "%{players::*}%" contains "%player%":
                            send "&cYou are already in the queue!" to player
                        else:
                            add "%player%" to {players::*}
                            set {queue} to size of {players::*}
                            send "&a%player% &chas joined the queue! &a(%{queue}%/16)" to all players in world "world2"
                else:
                    send "&cThere are no available arenas!" to player               
            else:
                send "&cYou are already in a game!" to player
        if arg-1 is "start":
            if executor is console:
                if {queue} >= 1:
                    if {arena1} and {arena2} and {arena3} and {arena4} and {arena5} is 1:
                        broadcast "&cAll arenas are full!"
                    else:
                        load world "Wasteland"
                        send "&3The match will begin in 30 seconds!" to all players in world "world2"
                        send "&3Teleporting players..." to all players in world "world2"
                        if {arena1} is 0:
                            set {game1} to {queue}
                            delete {queue}
                            set {arena1} to 1
                            send "&aPlayers can now join the queue for the next game." to all players in world "world2"
                            execute console command "/starttimer"
                            loop {players::*}:
                                clear loop-value parsed as player's inventory
                                set {_loc} to random element out of {loc1::*}
                                set {_loop-player} to loop-value parsed as player
                                teleport {_loop-player} to {_loc}
                                execute console command "givepython %loop-value parsed as player%"
                                give {_loop-player} 64 steak
                                set {game1::%{_loop-player}%} to 1
                                wait 2 seconds       
                            delete {players::*}

I know it's alot of code to read through but I'm in desperate need of making this more compact and optimal because I do not want to be repeating code.
 
Change {arena%number%} and {game%number%} to {arena::%number%} and {game::%number%}. Then you can loop through {arena::*} and {game::*} instead of copying/pasting whenever you create a new game/arena.
 
Change {arena%number%} and {game%number%} to {arena::%number%} and {game::%number%}. Then you can loop through {arena::*} and {game::*} instead of copying/pasting whenever you create a new game/arena.
Yeah I tried doing that, but I could never get it to work. I dont do so well with Skript so this is the best of my abilities.
 
Status
Not open for further replies.