Promote server
Black Friday Ends in 50% off a Master Server place and the Client list, which comes with LIFETIME PREMIUM
01 Days 06 Hrs 37 Min 37 Sec
See the deals
csb-halftime-swap / addons / amxmodx / scripting / csb_halftime_swap.sma
147 lines 3.6 KiB Pawn Raw Permalink History
/*
 * CSB Halftime Swap
 * Copyright (C) 2026 counter-strike-boost.com
 *
 * At the configured round (for MR15 that is round 16) both teams change sides
 * with cs_set_user_team, the stored team scores are swapped and pushed to the
 * scoreboard, every player's money is reset to the half-time start value, and the
 * round restarts after a short HUD countdown. Per-player frags are left untouched
 * so individual stats carry across the swap.
 *
 * 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 <https://www.gnu.org/licenses/> for details.
 */

#include <amxmodx>
#include <cstrike>

new const PLUGIN[] = "CSB Halftime Swap"
new const VERSION[] = "1.0.0"
new const AUTHOR[]  = "counter-strike-boost.com"

new g_pEnabled, g_pRound, g_pMoney, g_pCountdown
new g_iRound
new g_iScoreT, g_iScoreCT
new bool:g_bSwapped
new g_iSync
new g_iTick

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)

    g_pEnabled   = register_cvar("csb_half_enabled", "1")
    g_pRound     = register_cvar("csb_half_round", "16")
    g_pMoney     = register_cvar("csb_half_money", "800")
    g_pCountdown = register_cvar("csb_half_countdown", "5")

    register_logevent("eventRoundStart", 2, "1=Round_Start")
    register_event("TeamScore", "eventTeamScore", "a")

    g_iSync = CreateHudSyncObj()
}

public eventTeamScore()
{
    new team[4], scoreStr[8]
    read_data(1, team, charsmax(team))
    read_data(2, scoreStr, charsmax(scoreStr))

    new score = str_to_num(scoreStr)

    if (team[0] == 'C' || team[0] == 'c')
        g_iScoreCT = score
    else
        g_iScoreT = score
}

public eventRoundStart()
{
    if (!get_pcvar_num(g_pEnabled))
        return

    g_iRound++

    if (!g_bSwapped && g_iRound == get_pcvar_num(g_pRound))
        doHalftime()
}

doHalftime()
{
    g_bSwapped = true

    /* swap every player's side */
    new players[32], num
    get_players(players, num, "c")

    new startMoney = get_pcvar_num(g_pMoney)

    for (new i = 0; i < num; i++)
    {
        new id = players[i]
        new CsTeams:t = cs_get_user_team(id)

        if (t == CS_TEAM_T)
            cs_set_user_team(id, CS_TEAM_CT)
        else if (t == CS_TEAM_CT)
            cs_set_user_team(id, CS_TEAM_T)

        cs_set_user_money(id, startMoney)
    }

    /* swap the stored scores and push them to the scoreboard */
    new tmp = g_iScoreT
    g_iScoreT = g_iScoreCT
    g_iScoreCT = tmp

    pushScores()

    client_print(0, print_chat, "^x04[CSB]^x01 ^x03HALFTIME^x01 - teams have switched sides. Money reset to $%d.", startMoney)

    /* HUD countdown then restart */
    g_iTick = get_pcvar_num(g_pCountdown)

    if (g_iTick < 1)
        g_iTick = 1

    countdownTick()
}

countdownTick()
{
    if (g_iTick <= 0)
    {
        server_cmd("sv_restart 1")
        return
    }

    set_hudmessage(255, 60, 60, -1.0, 0.35, 0, 0.0, 1.1, 0.0, 0.0, -1)
    ShowSyncHudMsg(0, g_iSync, "Second half starts in %d...", g_iTick)

    g_iTick--
    set_task(1.0, "taskCountdown")
}

public taskCountdown()
{
    countdownTick()
}

pushScores()
{
    new msgid = get_user_msgid("TeamScore")

    message_begin(MSG_ALL, msgid)
    write_string("TERRORIST")
    write_short(g_iScoreT)
    message_end()

    message_begin(MSG_ALL, msgid)
    write_string("CT")
    write_short(g_iScoreCT)
    message_end()
}