AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with balance algorithm (https://forums.alliedmods.net/showthread.php?t=272010)

Phant 09-22-2015 08:08

Help with balance algorithm
 
I can't figure it out.
I set autojoin only for CT team (Team Join Management). And want make balance-plugin, which transfer some CT player to Terrorists. I want play: [T] 3 vs. 9 [CT], 2 vs. 6, 4 vs. 12, 9 vs. 24, etc. (33,3% Players for Terrorists, rest — 67% for CTs).

I make this code:
PHP Code:

public check_players()
{
    new 
players[32], plrsnumpltscts
    get_players
(playersplrsnum"h")
    for(new 
jj<plrsnumj++)
    {
        
pl players[j]
        new 
CsTeams:team
        team 
cs_get_user_team(pl)
        if(
team == CS_TEAM_T)
        {
            
ts++
        } else if(
team == CS_TEAM_CT) {
            
cts++
        }
    }
    
    new 
Float:ts_required_f
    ts_required_f 
cts get_pcvar_float(g_cvar_t_count_div)
    new 
ts_required floatround(ts_required_f)
    
    if(
ts <= ts_required)
    {
        
move_player(2// CT to T
    
} else {
        
move_player(1// T to CT
    
}
}

public 
move_player(team)
{
    new 
players[32], plrsnumpl
    
if(team == 1)
    {
        
get_players(playersplrsnum"he""TERRORIST")
    } else {
        
get_players(playersplrsnum"he""CT")
    }

    if(
team == 1)
    {
        
cs_set_user_team(players[plrsnum 1], CS_TEAM_CT)
    } else {
        
cs_set_user_team(players[plrsnum 1], CS_TEAM_T)
    }


But it's ugly and buggy. This code forever move "last" player to opposite team (9 vs. 23 — 8 vs. 24).
Maybe anyone have better solution?


All times are GMT -4. The time now is 22:14.

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