Продвинуть сервер

Initial release 1.0.0

Browse Source
1.0.0 - Initial release.
Daemon666 committed commit d7e8eeae8c7fa078acbaceb62d97dbd72bea7420
4 changed files with 210 additions and 0 deletions
+3 -0 CHANGELOG.md A
@@ -0,0 +1,3 @@
1 +## 1.0.0 (2026-04-01)
2 +
3 +1.0.0 - Initial release.
+1 -0 README.md A
@@ -0,0 +1 @@
1 +<p><strong>CSB Team Balance</strong> fixes lopsided teams automatically. At the end of every round it compares the team sizes and, if the gap is larger than <code>csb_balance_maxdiff</code>, moves just enough players from the bigger team to the smaller one to even things out.</p><h2>How it works</h2><p>The plugin counts the two teams on the <code>Round_End</code> log event and moves <code>diff / 2</code> players with <code>cs_set_user_team</code>. Because the switch happens between rounds, the moved players simply respawn on their new team next round &mdash; no mid-round death, no scoreboard mess. By default the <strong>lowest-scoring</strong> players are moved so the strongest players stay put; switch <code>csb_balance_skill</code> on to rank by frags minus deaths instead of raw score.</p><h2>Features</h2><ul><li>Runs at round end, so moves are clean and never mid-firefight.</li><li>Moves the weakest players first (score or skill based).</li><li>Configurable maximum allowed team-size difference.</li><li>Optionally skips <code>ADMIN_IMMUNITY</code> players (<code>csb_balance_immunity</code>).</li><li>Announces how many players were moved.</li></ul><p>Inspired by <em>Auto Team Balance</em> by Johnny got his gun; this is an independent GPL re-implementation.</p><h2>Installation</h2><ol><li>Compile and copy <code>csb_team_balance.amxx</code> into <code>addons/amxmodx/plugins/</code>.</li><li>Turn off the stock <code>mp_autoteambalance</code> to avoid the two fighting.</li><li>Add it to <code>plugins.ini</code> and change the map.</li></ol>
+160 -0 addons/amxmodx/scripting/csb_team_balance.sma A
@@ -0,0 +1,160 @@
1 +/*
2 + * CSB Team Balance
3 + * Copyright (C) 2026 counter-strike-boost.com
4 + *
5 + * At the end of every round this compares the two team sizes and, if the
6 + * difference is larger than a cvar, moves the required number of players from
7 + * the bigger team to the smaller one. By default it moves the lowest-scoring
8 + * players so the strongest players are left where they are; an optional
9 + * skill mode uses frags minus deaths instead of the scoreboard score.
10 + *
11 + * Inspired by "Auto Team Balance" by Johnny got his gun. This is an
12 + * independent GPL re-implementation; no original code is reused.
13 + *
14 + * This program is free software: you can redistribute it and/or modify it
15 + * under the terms of the GNU General Public License as published by the Free
16 + * Software Foundation, either version 3 of the License, or (at your option)
17 + * any later version. It is distributed in the hope that it will be useful,
18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
20 + * Public License for more details: <https://www.gnu.org/licenses/>.
21 + */
22 +
23 +#include <amxmodx>
24 +#include <cstrike>
25 +
26 +new const PLUGIN[] = "CSB Team Balance"
27 +new const VERSION[] = "1.0.0"
28 +new const AUTHOR[] = "counter-strike-boost.com"
29 +
30 +new g_pEnabled, g_pMaxDiff, g_pSkill, g_pImmunity
31 +
32 +public plugin_init()
33 +{
34 + register_plugin(PLUGIN, VERSION, AUTHOR)
35 +
36 + g_pEnabled = register_cvar("csb_balance_enabled", "1")
37 + g_pMaxDiff = register_cvar("csb_balance_maxdiff", "2")
38 + g_pSkill = register_cvar("csb_balance_skill", "0")
39 + g_pImmunity = register_cvar("csb_balance_immunity", "1")
40 +
41 + register_logevent("evRoundEnd", 2, "1=Round_End")
42 +}
43 +
44 +public evRoundEnd()
45 +{
46 + if (!get_pcvar_num(g_pEnabled))
47 + return
48 +
49 + balance()
50 +}
51 +
52 +balance()
53 +{
54 + new tPlayers[32], tNum = 0
55 + new ctPlayers[32], ctNum = 0
56 +
57 + new players[32], num, pid
58 + get_players(players, num, "ch")
59 +
60 + for (new i = 0; i < num; i++)
61 + {
62 + pid = players[i]
63 +
64 + switch (cs_get_user_team(pid))
65 + {
66 + case CS_TEAM_T: tPlayers[tNum++] = pid
67 + case CS_TEAM_CT: ctPlayers[ctNum++] = pid
68 + }
69 + }
70 +
71 + new diff = tNum - ctNum
72 + new absdiff = diff < 0 ? -diff : diff
73 +
74 + if (absdiff <= get_pcvar_num(g_pMaxDiff))
75 + return
76 +
77 + new toMove = absdiff / 2
78 +
79 + if (toMove < 1)
80 + return
81 +
82 + new CsTeams:destTeam
83 + new moveList[32], moveCount
84 +
85 + if (diff > 0)
86 + {
87 + /* T is bigger */
88 + moveCount = tNum
89 + for (new i = 0; i < tNum; i++)
90 + moveList[i] = tPlayers[i]
91 + destTeam = CS_TEAM_CT
92 + }
93 + else
94 + {
95 + moveCount = ctNum
96 + for (new i = 0; i < ctNum; i++)
97 + moveList[i] = ctPlayers[i]
98 + destTeam = CS_TEAM_T
99 + }
100 +
101 + sortByScoreAsc(moveList, moveCount)
102 +
103 + new moved = 0
104 +
105 + for (new i = 0; i < moveCount && moved < toMove; i++)
106 + {
107 + pid = moveList[i]
108 +
109 + if (get_pcvar_num(g_pImmunity) && (get_user_flags(pid) & ADMIN_IMMUNITY))
110 + continue
111 +
112 + switchPlayer(pid, destTeam)
113 + moved++
114 + }
115 +
116 + if (moved > 0)
117 + client_print_color(0, print_team_default, "^x04[CSB]^x01 Team Balance: moved^x04 %d^x01 player%s to even the teams.",
118 + moved, moved == 1 ? "" : "s")
119 +}
120 +
121 +switchPlayer(id, CsTeams:team)
122 +{
123 + /* Round has ended, so players are switched now and will respawn on the
124 + new team at the start of the next round - no forced death needed. */
125 + cs_set_user_team(id, team)
126 +
127 + new name[32]
128 + get_user_name(id, name, charsmax(name))
129 + log_amx("[CSB Team Balance] moved %s to %s", name, team == CS_TEAM_T ? "TERRORIST" : "CT")
130 +}
131 +
132 +sortByScoreAsc(list[], count)
133 +{
134 + /* simple selection sort - lists are at most 16 per team */
135 + for (new i = 0; i < count - 1; i++)
136 + {
137 + new min = i
138 +
139 + for (new j = i + 1; j < count; j++)
140 + {
141 + if (scoreOf(list[j]) < scoreOf(list[min]))
142 + min = j
143 + }
144 +
145 + if (min != i)
146 + {
147 + new tmp = list[i]
148 + list[i] = list[min]
149 + list[min] = tmp
150 + }
151 + }
152 +}
153 +
154 +scoreOf(id)
155 +{
156 + if (get_pcvar_num(g_pSkill))
157 + return get_user_frags(id) - cs_get_user_deaths(id)
158 +
159 + return get_user_frags(id)
160 +}
+46 -0 csb.json A
@@ -0,0 +1,46 @@
1 +{
2 + "name": "CSB Team Balance",
3 + "category": "admin",
4 + "tags": "balance, teams, autoteam",
5 + "image": "",
6 + "original_author": "Johnny got his gun (Auto Team Balance)",
7 + "original_url": "",
8 + "license": "GPL-3.0",
9 + "title": "CSB Team Balance",
10 + "short_desc": "Evens the teams at round end by moving the lowest-scoring players, with an optional skill mode.",
11 + "version": "1.0.0",
12 + "amxx_min": "1.9",
13 + "amxx_compile_default": "1.9",
14 + "rehlds_ok": true,
15 + "hlds_ok": true,
16 + "regamedll_required": false,
17 + "metamod_flavor": "any",
18 + "reapi_required": false,
19 + "modules": "cstrike",
20 + "install_notes": "1. Put csb_team_balance.amxx in addons/amxmodx/plugins/\n2. Add it to plugins.ini\n3. Set mp_autoteambalance 0 so the stock balancer does not fight it\n4. Change map",
21 + "known_conflicts": "The stock mp_autoteambalance and other team-balance plugins - run only one balancer.",
22 + "cvars": [
23 + {
24 + "name": "csb_balance_enabled",
25 + "default": "1",
26 + "description": "Enable or disable auto team balancing."
27 + },
28 + {
29 + "name": "csb_balance_maxdiff",
30 + "default": "2",
31 + "description": "Team-size gap that triggers a balance."
32 + },
33 + {
34 + "name": "csb_balance_skill",
35 + "default": "0",
36 + "description": "0 = move by score, 1 = move by frags minus deaths."
37 + },
38 + {
39 + "name": "csb_balance_immunity",
40 + "default": "1",
41 + "description": "Skip players with ADMIN_IMMUNITY."
42 + }
43 + ],
44 + "commands": [],
45 + "main": "addons/amxmodx/scripting/csb_team_balance.sma"
46 +}
0 47