1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

FFA Anyone?

Discussion in 'Requests' started by jackitch, Jul 19, 2014.

  1. jackitch

    jackitch :(){ :|: & };: Global Moderator Donator Tester
    1. SharSharShar - [SHARK]

    Messages:
    249
    I'm looking for a hand to write a small section of code (and possibly help me finish the mod if you're up to it).

    Basically I'm stuck on trying to get players assigned to a suitable team for a 1 player per team gamemode.

    What I'm trying to accomplish:

    -get the number of teams
    -get the number of players on each team
    -get the lowest team number that has no players
    -if there is only one team that already has one player, add a new team with the lowest possible team number
    (ex: if team 2 exists add team 0 ex2: if team 0 exists add team 1)
    -return "team" where team = the lowest team number with 0 players
    -on respawn, assign the player to the same team number
    -on nextmap, assign the player to a new team (for variety)

    Example:

    4 players are playing.

    Blue (team 0), red (team 1), green (team 2), and purple (team 3) respectively.

    If blue and green both leave, and another player joins, I want him to be assigned to blue team, not green or orange.

    Here is the section of code from Shiprekt that I was looking at. It's all greek to me, I've been piecemealing things together from the beginning. I've been burning a lot of time copy-pasting when I'm pretty sure I could have finished a long time ago if I just swallowed my pride and asked for help...

    Code:
    Random _teamrandom(0x7ea177);
    
    s32 getRandomMinimumTeam(CRules@ this, const int higherThan = -1)
    {
        const int teamsCount = this.getTeamsNum();
        int[] playersperteam;
        for(int i = 0; i < teamsCount; i++)
            playersperteam.push_back(0);
    
        //gather the per team player counts
        const int playersCount = getPlayersCount();
        for(int i = 0; i < playersCount; i++)
        {
            CPlayer@ p = getPlayer(i);
            s32 pteam = p.getTeamNum();
            if(pteam >= 0 && pteam < teamsCount)
            {
                playersperteam[pteam]++;
            }
        }
    
        //calc the minimum player count
        int minplayers = 1000;
        for(int i = 0; i < teamsCount; i++)
        {
            if (playersperteam[i] < higherThan)
                playersperteam[i] = 1000;
            minplayers = Maths::Min(playersperteam[i], minplayers);
        }
    
        //choose a random team with minimum player count
        s32 team;
        do {
            team = _teamrandom.NextRanged(teamsCount);
        } while(playersperteam[team] > minplayers);
    
        return team;
    }
    

    If you're interested in helping, you can post here or PM me. If you've played the earlier versions of this mode, you'll know why I want to finish it so badly. It's effing fun!

    3cdbdfa0e9ac62b75d0ac0e3ab456f84540e08974b.png 3cdbdfa0e9d07579826fb29d14485d2e9aa983a329.png 3cdbdfa0e94ec126c18b594455ec24227523a81601.png 3cdbdfa0e9818cae09fd03c976dcd9c7b79ae39c89.png

    Thanks in advance,

    :heart: jackitch
     
    Horse_That_Goes_Ni likes this.
  2. Horse_That_Goes_Ni

    Horse_That_Goes_Ni Your favorite Persian Staff Alumni Donator

    Messages:
    233
    Telling mak about this, hopefully he's up for it.:thumbs_up: @makmoud98
     
    makmoud98 likes this.