Raised This Month: $51 Target: $400
 12% 

Can you fix the prison team balance plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
laenss
Member
Join Date: Feb 2017
Old 08-30-2018 , 10:20   Can you fix the prison team balance plugin?
Reply With Quote #1

There is no problem with the plugin used by the server

I wish I could set the number of people.

and

When selecting a team, please make sure that the user can not select automatic selection. This destroys the balance.

PHP Code:


#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>
#pragma semicolon 1

#define PREFIX "[\x05LANESS\x01]"

public OnPluginStart()
{
    
RegConsoleCmd("jointeam"Command_JoinTeam);
    
HookEvent("round_end"Event_RoundEnd);
}

public 
Action:Event_RoundEnd(Handle:event, const String:name[], bool:broadcast)
{
    new 
TerrorCounter;
    
Terror GetTeamClientCount(2);
    
Counter GetTeamClientCount(3);
    
    if(
Terror Counter >= 3)
    {
        if(
Counter Terror 1)
        {
            new 
maxselect 0;
            new 
selects[MaxClients 1];
            
            for(new 
1;<= MAXPLAYERSi++)
            {
                
maxselect 0;
                
                for(new 
1<= MaxClientsn++)
                {
                    if(
IsClientConnectedIngame(n) == true)
                    {
                        if(
GetClientTeam(n) == CS_TEAM_CT && !IsFakeClient(n))
                        {
                            
maxselect++;
                            
selects[maxselect] = n;
                        }
                    }
                }
        
                if(
maxselect != 0)
                {
                    new 
select selects[GetRandomInt(1maxselect)];
                    
                    
CS_SwitchTeam(selectCS_TEAM_T);
                    
PrintToChatAll("%s %N 님은 자동 팀설정에 의해 죄수팀이 되었습니다"PREFIXselect);
                    
                    
Terror GetTeamClientCount(2);
                    
Counter GetTeamClientCount(3);
                
                    if(!(
Counter Terror 1) || !(Terror Counter >= 3))
                    {
                        break;
                    }
                }
            }
        }
        else if(
Counter Terror)
        {            
            new 
maxselect 0;
            new 
selects[MaxClients 1];
        
            for(new 
1;<= MAXPLAYERSi++)
            {
                
maxselect 0;
                
                for(new 
1<= MaxClientsn++)
                {
                    if(
IsClientConnectedIngame(n) == true)
                    {
                        if(
GetClientTeam(n) == CS_TEAM_T && !IsFakeClient(n))
                        {
                            
maxselect++;
                            
selects[maxselect] = n;
                        }
                    }
                }
        
                if(
maxselect != 0)
                {
                    new 
select selects[GetRandomInt(1maxselect)];
                    
                    
CS_SwitchTeam(selectCS_TEAM_CT);
                    
PrintToChatAll("%s %N 님은 자동 팀설정에 의해 간수팀이 되었습니다"PREFIXselect);
                    
                    
Terror GetTeamClientCount(2);
                    
Counter GetTeamClientCount(3);
                
                    if(!(
Counter Terror) || !(Terror Counter >= 3))
                    {
                        break;
                    }
                }
            }
        }
    }
    return 
Plugin_Handled;
}

public 
Action:Command_JoinTeam(Clientargs)
{    
    
decl String:Team[8];
    
GetCmdArg(1Teamsizeof(Team));
    
    new 
ClientTeam GetClientTeam(Client);
    
    new 
TerrorCounter;
    
Terror GetTeamClientCount(CS_TEAM_T);
    
Counter GetTeamClientCount(CS_TEAM_CT);
    
    if(
StrEqual(Team"0"))
    {
        if(
ClientTeam == CS_TEAM_SPECTATOR || ClientTeam == CS_TEAM_NONE)
        {
            if(
Terror Counter 2)
            {
                if(
Counter == 0)
                {
                    
ChangeClientTeam(ClientCS_TEAM_CT);
                    
PrintToChat(Client"%s 현재 아무도 없으므로 대테러팀에 참가합니다"PREFIX);
                }
                else
                {
                    
ChangeClientTeam(ClientCS_TEAM_T);
                    
PrintToChat(Client"%s 대테러가 충분하므로 테러팀에 참가합니다"PREFIX);
                }
            }
            else
            {                
                if((
Counter 1) * <= Terror 1)
                {
                    
ChangeClientTeam(ClientCS_TEAM_CT);
                    
PrintToChat(Client"%s 테러가 충분하므로 대테러팀에 참가합니다"PREFIX);
                    
                }
                else
                {
                    
ChangeClientTeam(ClientCS_TEAM_T);
                    
PrintToChat(Client"%s 대테러가 충분하므로 테러팀에 참가합니다"PREFIX);
                    
                }
            }
        }
        else if(
ClientTeam == CS_TEAM_CT)
        {
            if((
Counter 1) * >= Terror 1)
            {
                
ChangeClientTeam(ClientCS_TEAM_T);
            }
            else
            {
                
PrintToChat(Client"%s 테러가 충분하므로 대테러팀에 참가합니다"PREFIX);
            }
            
        }
        else if(
ClientTeam == CS_TEAM_T)
        {
            if((
Counter 1) * Terror 1)
            {
                
ChangeClientTeam(ClientCS_TEAM_CT);
            }
            else
            {
                
PrintToChat(Client"%s 대테러가 충분하므로 테러팀에 참가합니다"PREFIX);
            }
        }
    }
    else if(
StrEqual(Team"2"))
    {
        if(
ClientTeam == CS_TEAM_SPECTATOR || ClientTeam == CS_TEAM_NONE)
        {
            if(
Terror Counter 2)
            {
                if(
Counter == 0)
                {
                    
ChangeClientTeam(ClientCS_TEAM_CT);
                }
                else
                {
                    
ChangeClientTeam(ClientCS_TEAM_T);
                    
PrintToChat(Client"%s 대테러팀에 인원이 충분하므로 테러 팀에 참가합니다"PREFIX);
                }
            }
            else
            {                
                if((
Counter 1) * <= Terror 1)
                {
                    
ChangeClientTeam(ClientCS_TEAM_CT);
                }
                else
                {
                    
ChangeClientTeam(ClientCS_TEAM_T);
                    
PrintToChat(Client"%s 대테러팀에 인원이 충분하므로 테러 팀에 참가합니다"PREFIX);
                }
            }
        }
        else if(
ClientTeam == CS_TEAM_CT)
        {
            if((
Counter 1) * >= Terror 1)
            {
                
ChangeClientTeam(ClientCS_TEAM_T);
            }
            else
            {
                
PrintToChat(Client"%s 테러팀에 인원이 충분하므로 대테러 팀에 참가합니다"PREFIX);
            }
        }
    }
    else if(
StrEqual(Team"3"))
    {
        if(
ClientTeam == CS_TEAM_SPECTATOR || ClientTeam == CS_TEAM_NONE)
        {
            if(
Terror Counter 2)
            {
                if(
Counter == 0)
                {
                    
ChangeClientTeam(ClientCS_TEAM_CT);
                }
                else
                {
                    
ChangeClientTeam(ClientCS_TEAM_T);
                    
PrintToChat(Client"%s 대테러팀에 인원이 충분하므로 테러 팀에 참가합니다"PREFIX);
                }
            }
            else
            {
                if((
Counter 1) * <= Terror 1)
                {
                    
ChangeClientTeam(ClientCS_TEAM_CT);
                }
                else
                {
                    
ChangeClientTeam(ClientCS_TEAM_T);
                    
PrintToChat(Client"%s 대테러팀에 인원이 충분하므로 테러 팀에 참가합니다"PREFIX);
                }
            }
        }
        else if(
ClientTeam == CS_TEAM_T)
        {
            if(
Terror Counter 2)
            {
                
ChangeClientTeam(ClientCS_TEAM_CT);
            }
            else
            {
                if((
Counter 1) * <= Terror 1)
                {
                    
ChangeClientTeam(ClientCS_TEAM_CT);
                }
                else
                {
                    
PrintToChat(Client"%s 대테러팀에 인원이 충분하므로 테러 팀에 참가합니다"PREFIX);
                }
            }
        }
    }
    else if(
StrEqual(Team"1"))
    {
        if(
GetClientTeam(Client) != CS_TEAM_SPECTATOR)
        {
            
ChangeClientTeam(ClientCS_TEAM_SPECTATOR);
        }
    }
    return 
Plugin_Handled;
}

bool:IsClientConnectedIngame(Client)
{
    if(
Client && Client <= MaxClients)
    {
        if(
IsClientInGame(Client))
        {
            return 
true;
        }
        else return 
false;
    }
    else return 
false;

laenss is offline
potatoz
AlliedModders Donor
Join Date: Nov 2016
Old 09-03-2018 , 10:43   Re: Can you fix the prison team balance plugin?
Reply With Quote #2

Try this, it's a modified version from my "Warden+"; While it is untested, it should (hopefully) work

I know it's not exactly what you asked but still, it does however block using auto-assing and includes convars for easy changing of ratio and prefix, you may also need to translate it considering it's in English in difference to the OP

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <cstrike>

#define VERSION "1.0" 

ConVar g_cvRatio,
    
g_cvPrefix;

public 
Plugin:myinfo =
{
    
name "teambalance",
    
author "potatoz",
    
description "jailbreak teambalance plugin",
    
version VERSION,
    
url ""
};

public 
OnPluginStart()
{    
    
g_cvRatio CreateConVar("sm_teambalance_ratio""3""How many T's that are required per CT");
    
g_cvPrefix CreateConVar("sm_teambalance_prefix""[\x06teambalance\x01]""Will be used as chat prefix for the teambalance plugin");
    
AutoExecConfig(true"teambalance");
    
    
HookEvent("round_start"Event_RoundStart);
    
AddCommandListener(Command_JoinTeam"jointeam");    
}

public 
Action Command_JoinTeam(int client, const char[] commandint args)
{
    if(!
IsValidClient(client) || IsFakeClient(client))
        return 
Plugin_Continue;
    
    
char PREFIX[64];
    
g_cvPrefix.GetString(PREFIXsizeof(PREFIX));
    
    
char teamstring[3];
    
GetCmdArg(1teamstringsizeof(teamstring));
    
int target_team StringToInt(teamstring);
    
int current_team GetClientTeam(client);

    
int CTs 0
        
Ts 0;

    for (
int i 1<= MaxClientsi++)
    {
        if(
IsValidClient(i))
        {
            if(
GetClientTeam(i) == CS_TEAM_CT
                
CTs++;
            else if (
GetClientTeam(i) == CS_TEAM_T)
                
Ts++;    
        }
    }
    
    
CTs++;
    
    if(
target_team == current_team)
        return 
Plugin_Handled;
    else if(
target_team == 0)
        return 
Plugin_Handled;
    else if(
target_team == CS_TEAM_CT)
    {
        if(
CTs <= 1) return Plugin_Continue;
    
        
float fNumPrisonersPerGuard float(Ts) / float(CTs);
        if(
fNumPrisonersPerGuard < (g_cvRatio.IntValue 1.0))
        {
            
PrintToChat(client" %s There is too many CTs at the moment, running 1:3 ratio"PREFIX);
            return 
Plugin_Handled;
        }
    
        
int i_guardsneeded RoundToCeil(fNumPrisonersPerGuard 3.0);
        if(
i_guardsneeded 1)
            
i_guardsneeded 1;

        if(
i_guardsneeded 0)
            return 
Plugin_Continue;
            
        
PrintToChat(client" %s There is too many CTs at the moment, running 1:3 ratio"PREFIX);
        return 
Plugin_Handled;
    }
    
    return 
Plugin_Continue;
}

public 
Action Event_RoundStart(Handle event, const char[] namebool dontBroadcast
{
    
int CTs 0
        
Ts 0;    
    
    for (
int i 1<= MaxClientsi++)
    {
        if(
IsValidClient(i))
        {
            if(
GetClientTeam(i) == CS_TEAM_CT)     
                
CTs++;
            else if(
GetClientTeam(i) == CS_TEAM_T)
                
Ts++;
        }
    }
    
    
Ts++;
    
    if(
CTs <= 1)
    {} else if(
CTs <= RoundToFloor(float(Ts) / (g_cvRatio.IntValue 1.0)))
    {} else 
SwitchRandomCT();
}

public 
Action RespawnPlayer(Handle timerint client)
{
    if(!
IsPlayerAlive(client))
        
CS_RespawnPlayer(client);
}

public 
void SwitchRandomCT()
{    
    
char PREFIX[64];
    
g_cvPrefix.GetString(PREFIXsizeof(PREFIX));

    
int i_numclients,
        
i_clients[MAXPLAYERS+1];
    
    for(
int i=1i<=MaxClientsi++)
        if(
IsValidClient(i) && GetClientTeam(i) == CS_TEAM_CT)
            
i_clients[i_numclients++] = i;
        
    if(
i_numclients != 0)
    {
        
int randomclient i_clients[GetRandomInt(0i_numclients-1)];
        if(
IsValidClient(randomclient) && GetClientTeam(randomclient) == CS_TEAM_CT)
        {
            
CreateTimer(0.2RespawnPlayerrandomclient);
            
PrintToChatAll(" %s %N has been randomly switched to balance out the teams"PREFIXrandomclient);
            
ChangeClientTeam(randomclientCS_TEAM_T);
        }
    }
    
    
int CTs 0
        
Ts 0;
    
    for (
int i 1<= MaxClientsi++)
    {
        if(
IsValidClient(i))
        {
            if(
GetClientTeam(i) == CS_TEAM_CT
                
CTs++;
            else if (
GetClientTeam(i) == CS_TEAM_T)
                
Ts++;    
        }
    }
    
    
Ts++;
    
    if(
CTs <= 1)
    {} else if(
CTs <= RoundToFloor(float(Ts) / (g_cvRatio.IntValue 1.0)))
    {} else 
SwitchRandomCT();
}

bool IsValidClient(int client)
{
    return (
client <= MaxClients && IsClientInGame(client));

Attached Files
File Type: sp Get Plugin or Get Source (teambalance.sp - 115 views - 3.7 KB)
__________________
potatoz is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 09-04-2018 , 13:21   Re: Can you fix the prison team balance plugin?
Reply With Quote #3

https://github.com/splewis/csgo-reta...ing/retakes.sp

PHP Code:

public Action Event_PlayerConnectFull(Handle event, const char[] namebool dontBroadcast) {
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
SetEntPropFloat(clientProp_Send"m_fForceTeam"3600.0);

This code delays mp_force_pick_time. Or you can assign a default team when the player joins the server.
Ilusion9 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:59.


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