Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: RCON Command to Shuffle Teams

  1. #1

    Default RCON Command to Shuffle Teams

    I'm trying to build an rcon command to shuffle the teams randomly, but I don't really know where to begin. I'd guess you'll want to get the number of people on allies + the number of people on axis, then assign every player a random int between 0 and the total number of allies + axis -1, then send odd numbers to allies and even number to axis, or the first half to one team and the second half to the other.... Just a bit over my head. If there's anyone who can give me pointers, I'd really appreciate it!

  2. #2

    Default

    move everyone to spectator, then use auto_join_team


    teamswitchdelay 0;
    for (local.i = 1; local.i <= $player.size; local.i++) {
    local.player = $player[local.i];
    local.player spectator;
    }
    wait 1;
    for (local.i = 1; local.i <= $player.size; local.i++) {
    local.player = $player[local.i];
    local.player auto_join_team;
    //local.player primarydmweapon sniper;
    waitframe;
    }


    you can uncomment local.player primarydmweapon sniper if you want everyone to spawn fast without having to select a weapon first, but it will auto choose the sniper rifle.

  3. #3
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    auto_join_team is not random, it simply uses the good old team balance algorithm afaik. What splatter suggests is actually good in terms of random shuffling. I'd just make sure no 2 players have the same index and it should work perfectly.

  4. #4

    Default

    auto_join_team might not be perfect but it still do the job in his way, i mean, is not like you will use it more than once per map.
    i used that method years ago for my clan, and i can tell you, when you use it it really feels like a random shuffle.

    anyways, here is something better :)


    main:
    teamswitchdelay 0;
    for (local.i = 1; local.i <= $player.size; local.i++) {
    local.player = $player[local.i];
    local.player spectator;
    }
    wait 1
    for (local.i = 1; local.i <= $player.size; local.i++) {
    local.array[local.i] = local.i;
    }

    local.array = waitthread Shuffle local.array local.array[1] local.array.size;

    for (local.i = 1; local.i <= local.array.size; local.i++) {
    local.player = $player[local.array[local.i]];
    if (local.i % 2)
    local.player join_team allies;
    else
    local.player join_team axis;
    //local.player primarydmweapon sniper;
    //local.player respawn;
    }
    end;

    Shuffle local.array local.lower local.upper:
    local.bounds = local.lower::local.upper;
    for (local.i = local.bounds[2]; local.bounds[1] <= local.i; local.i--) {
    local.swapIdx = randomint(abs(local.i)) + local.bounds[1];
    local.tmp = local.array[local.i];
    local.array[local.i] = local.array[local.swapIdx];
    local.array[local.swapIdx] = local.tmp;
    }
    end local.array;


    The Shuffle part is a modified version of the Shuffle script from Sor's framework.

  5. #5

    Default

    This one is very simple:


    main:

    //move all players to spectator
    $player join_team spectator


    for (local.i = 1; local.i <= $player.size; local.i++)
    {
    local.player = $player[local.i];

    if(local.player == NULL)
    end

    local.number = randomint(2) + 1

    if(local.number == 1)
    {
    local.player join_team allies
    }
    else
    {
    local.player join_team axis
    }
    }



    end

  6. #6

    Default

    Poor guy wanted pointers to learn something, not complete solution.
    Github - Steam - .Crimewavez#5285

  7. #7
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    Quote Originally Posted by Criminal View Post
    Poor guy wanted pointers to learn something, not complete solution.
    That rarely happens lol.
    @Zappa, auto_join_team is random until the first player has joined a team, after that behavior is defined and predictable. You can, however, call auto_join_team while looping players randomly, that'd do the job better.

  8. #8

    Default

    i know auto_join_team makes you join the side with fewer players, but still, if you run the script only one time you will get players sorted "randomly", no matter if is predefined or predictable, if you use it only one time you will get the "feeling" of randomness.
    if you run it two or more times you will probably get the same result again or everyone switched to the opposite team, i think.
    and you're right, shuffling the players array is a better way to do it


    @DoubleKill that won't work, using just randomint doesn't assure you that the players will be distributed evenly.

  9. #9

    Default

    Yo, zappa, does Morpheus interpreter care about ";"?

    Also if you could explain what this line do, because I'm not so sure that I can go to other languages for explanation.

    local.bounds = local.lower::local.upper;
    Last edited by Criminal; February 10th, 2019 at 11:26 AM.
    Github - Steam - .Crimewavez#5285

  10. #10

    Default

    You can use it to include several instructions on one line, but you don't need it if you don't. E.g:

     local.player give local.item; local.player use local.item


    Just some people prefer to use it because of other languages.

    That line just adds local.lower and local.upper to an array (starting at index 1).

    e.g.
    local.array = "hey"::$someentity::12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •