/*
* CSB Swap Teams
* Copyright (C) 2026 counter-strike-boost.com
*
* amx_swapteams swaps every player between the two teams with cs_set_user_team
* and respawns the alive ones through Ham_CS_RoundRespawn. The team scoreboard
* totals (tracked from the round-win audio) are swapped too and re-sent via the
* TeamScore message, so the score follows the players instead of the side.
*
* Inspired by the Swap Teams plugin from AMX Mod X (AMX Mod X Development
* Team). Independent GPL re-implementation; no original code reused.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version. It is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See for details.
*/
#include
#include
#include
#include
new const PLUGIN[] = "CSB Swap Teams"
new const VERSION[] = "1.0.0"
new const AUTHOR[] = "counter-strike-boost.com"
new g_iScoreT, g_iScoreCT
new g_msgTeamScore
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_concmd("amx_swapteams", "cmdSwap", ADMIN_LEVEL_A, "- swap all players between the two teams")
register_event("SendAudio", "evWin", "a")
register_event("TextMsg", "evRestart", "a", "2Game_C")
g_msgTeamScore = get_user_msgid("TeamScore")
}
public evWin()
{
new audio[48]
read_data(2, audio, charsmax(audio))
if (containi(audio, "terwin") != -1)
g_iScoreT++
else if (containi(audio, "ctwin") != -1)
g_iScoreCT++
}
public evRestart()
{
/* new game / score reset detected -> clear our mirrors */
g_iScoreT = 0
g_iScoreCT = 0
}
sendTeamScore(const team[], score)
{
message_begin(MSG_ALL, g_msgTeamScore)
write_string(team)
write_short(score)
message_end()
}
public cmdSwap(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
new players[32], num, pid, swapped = 0
get_players(players, num)
for (new i = 0; i < num; i++)
{
pid = players[i]
new CsTeams:team = cs_get_user_team(pid)
if (team == CS_TEAM_T)
{
cs_set_user_team(pid, CS_TEAM_CT)
swapped++
}
else if (team == CS_TEAM_CT)
{
cs_set_user_team(pid, CS_TEAM_T)
swapped++
}
else
{
continue
}
if (is_user_alive(pid))
ExecuteHamB(Ham_CS_RoundRespawn, pid)
}
/* the score should follow the players, so swap the mirrored totals */
new tmp = g_iScoreT
g_iScoreT = g_iScoreCT
g_iScoreCT = tmp
sendTeamScore("TERRORIST", g_iScoreT)
sendTeamScore("CT", g_iScoreCT)
new aname[32]
if (id)
get_user_name(id, aname, charsmax(aname))
else
copy(aname, charsmax(aname), "CONSOLE")
client_print(0, print_chat, "[CSB] %s swapped the teams (%d players).", aname, swapped)
log_amx("[CSB Swap] %s swapped the teams (%d players)", aname, swapped)
return PLUGIN_HANDLED
}