AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   player team ratio balance (https://forums.alliedmods.net/showthread.php?t=107468)

drumzplaya13 10-27-2009 02:52

player team ratio balance
 
I would like a plugin which has a ratio of players that is 1:3 and once it reaches a 1:3 ratio, CT>T, teams lock so it always have a 1:3 ratio unless an odd number of people which the odd number go on T side , until someone on the CT team leaves or gets transferred to the other team. ex: 20 slot server. 1:3 ratio. 5 CT's, 15 T's, Team locks after this, but is able to be modified by an admin switching someone to each other team.

I know these have been made but I have yet to see an actual working on. I tried this one that I found, if someone can modify it so it doesnt automatically stop working in gameplay that would be fine too.


Code:

// This is not the same as Bmann_420's Teams Locker.

#include <amxmodx>

#define IsValidTeam(%1)    (Terrorists <= %1 <= CounterTerrorists)

enum
{
    Terrorists = 1,
    CounterTerrorists
};

new const TeamsNames[3][] =
{
    "", // None.
    "Terrorists",
    "Counter-Terrorists"
};

new bool:Locked[3]; // Locked[0] = None.
new PlayersNum[3]; // PlayersNum[0] = None.

public plugin_init()
{
    register_plugin("Team Locker", "1.0", "Dores");
   
    register_event("TeamInfo", "TeamInfo_Event", "a", "2&TERRORIST", "2&CT");
    register_clcmd("jointeam", "Cmd_JoinTeam");
}

public TeamInfo_Event()
{
    new TeamName[1], MovedTeam, id, OldTeam;
   
    read_data(2, TeamName, 1);
   
    MovedTeam = GetTeamByChar(TeamName[0]);
    if (IsValidTeam(MovedTeam))
    {
        PlayersNum[MovedTeam]++;
    }
   
    id = read_data(1);
   
    // the player's team data is only changed AFTER this event is called, and this is
    // a pre hook.
    OldTeam = get_user_team(id);
   
    if (IsValidTeam(OldTeam))
    {
        PlayersNum[OldTeam]--;
    }
   
    CheckTeams();
}

public Cmd_JoinTeam(id)
{
    new Arg[1], Team;
    read_argv(1, Arg, 1);
    Team = str_to_num(Arg);
   
    if (!IsValidTeam(Team))
    {
        return PLUGIN_CONTINUE;
    }
   
    if (Locked[Team])
    {
        client_print(id, print_center, "%s team is currently locked. Try again later.", TeamsNames[Team]);
        return PLUGIN_HANDLED;
    }
   
    return PLUGIN_CONTINUE;
}

CheckTeams()
{
    new CTNum = PlayersNum[CounterTerrorists];
    new TNum = PlayersNum[Terrorists];
    new diff;
   
    diff = abs(CTNum - TNum);
    if (diff > 1)
    {
        if(CTNum > TNum)
        {
            Locked[CounterTerrorists] = true;
        }
       
        else
        {
            Locked[Terrorists] = true;
        }
    }
   
    else
    {
        Locked[CounterTerrorists] = false;
        Locked[Terrorists] = false;
    }
}

GetTeamByChar(ch)
{
    switch(ch)
    {
        case 'T':
        {
            return 1;
        }
       
        case 'C':
        {
            return 2;
        }
    }
   
    return 0;
}

the code seems to work sometimes, but then other times, it just wont let anyone who joins the server on any team at all... if there are like 2 ct's and 5 t's it just lets no one on a team who just joined the server, but other times it works fine. So if someone could fix the code that would be splendid.


All times are GMT -4. The time now is 17:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.