Solved Splitting players into two teams

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

Hexivoid

Member
Oct 22, 2017
35
7
8
Skript Version: 2.2-dev26f (latest one that works with addons without errors)
Skript Author: bensku
Server Version: 1.8.9 Spigot (We dislike 1.9+ PvP)



I think the title is explanatory enough, but how exactly could I split up players into two teams through a loop all players loop? I'd rather not use a random integer or a chance since teams have a chance of not being either, and I also tried anything I could think of with booleans (which didn't work out). If anyone can help me, thanks! :emoji_slight_smile:


(I imagined something like this would work. I really wish someone would make an addon supporting goto effects.)
code_language.skript:
set {whichteam} to true:

loop all players:
    set {whichteam} to true: 
    if {whichteam} is true: 
        broadcast "team one %loop-player%"       
        set {whichteam} to false
    else if {whichteam} is false: 
        broadcast "team two %loop-player%" 
        set {whichteam} to true
 
Skript Version: 2.2-dev26f (latest one that works with addons without errors)
Skript Author: bensku
Server Version: 1.8.9 Spigot (We dislike 1.9+ PvP)



I think the title is explanatory enough, but how exactly could I split up players into two teams through a loop all players loop? I'd rather not use a random integer or a chance since teams have a chance of not being either, and I also tried anything I could think of with booleans (which didn't work out). If anyone can help me, thanks! :emoji_slight_smile:


(I imagined something like this would work. I really wish someone would make an addon supporting goto effects.)
code_language.skript:
set {whichteam} to true:

loop all players:
    set {whichteam} to true:
    if {whichteam} is true:
        broadcast "team one %loop-player%"    
        set {whichteam} to false
    else if {whichteam} is false:
        broadcast "team two %loop-player%"
        set {whichteam} to true
I have a code for this already that you can use^-^ it requires Skquery.
It first checks to see if the number of players is an even number, and if so, it adds half to two teams depending on the remainder of the player count. So odds to one team, evens to another.
code_language.skript:
command /split:
    trigger:
        set {_a} to 1
        set {_count} to number of all players
        set {_evencheck} to {_count} mod 2
        if {_evencheck} is equal to 0:
            loop players:
                if {_a} mod 2 = 1:
                    add loop-player to {team1::*}
                if {_a} mod 2 = 0:
                    add loop-player to {team2::*}
                add 1 to {_a}
 
  • Like
Reactions: Hexivoid
I have a code for this already that you can use^-^ it requires Skquery.
It first checks to see if the number of players is an even number, and if so, it adds half to two teams depending on the remainder of the player count. So odds to one team, evens to another.
code_language.skript:
command /split:
    trigger:
        set {_a} to 1
        set {_count} to number of all players
        set {_evencheck} to {_count} mod 2
        if {_evencheck} is equal to 0:
            loop players:
                if {_a} mod 2 = 1:
                    add loop-player to {team1::*}
                if {_a} mod 2 = 0:
                    add loop-player to {team2::*}
                add 1 to {_a}
Well that's very helpful- thanks! I'll try it out :emoji_slight_smile:
[doublepost=1517172027,1517171626][/doublepost]Huh, I was looking for a modulus expression earlier today to use, didn't realize capitalization counts- tried "%" and "Mod" ;l
Someone needs to put modulus in the Docs.
[doublepost=1517179234][/doublepost]Ayy, that code works! Thanks!

One more thing though- I only want players out of a queue I have to be split into teams. I already have a boolean "{queue.%player%}" being true or false for each player- How would I only have those players in the queue be added into teams? I've already tried looping them within each other along with if statements with no success :emoji_frowning: Thanks again!
[doublepost=1517179527][/doublepost]Here's what I tried:

code_language.skript:
loop all players:
    set {queplayers} to "0" parsed as integer
    if {queue.%loop-player%} is true: 
        add one two {queueplayers}
        set {_a} to 1
        set {_count} to {queueplayers}
        set {_evencheck} to {_count} mod 2
        if {_evencheck} is equal to 0:   
            if {_a} mod 2 = 1:
                add loop-player to {blueteam::*}
            if {_a} mod 2 = 0:
                add loop-player to {redteam::*}
            add 1 to {_a}

I'm fairly new to loops and arrays, thanks for trying to help!
[doublepost=1517266326][/doublepost]Nevermind- I altered my code a bit and got it working! (Not sure why it works, but it does- so I won't question it!)
 
Status
Not open for further replies.