#pragma semicolon 1
#pragma newdecls required
#include <sdktools_entinput>
#include <sdktools_functions>
#include <sdktools_gamerules>
static const char g_WeaponClasses[][] = {"weapon_nova", "weapon_xm1014", "weapon_mag7", "weapon_sawedoff", "weapon_usp_silencer", "weapon_hkp2000", "weapon_glock", "weapon_elite", "weapon_p250", "weapon_fiveseven", "weapon_tec9", "weapon_deagle", "weapon_ssg08", "weapon_awp", "weapon_ak47", "weapon_m4a1", "weapon_m4a1_silencer", "weapon_m249", "weapon_negev", "weapon_mp9", "weapon_mac10", "weapon_mp7", "weapon_ump45", "weapon_p90", "weapon_bizon", "weapon_famas", "weapon_galilar", "weapon_aug", "weapon_sg556", "weapon_scar20", "weapon_g3sg1"};
static const int BOUNDS[][] = {{4, 8}, {9, 11}, {0, 3}, {12, 12}, {4, (sizeof(g_WeaponClasses) - 1)}};
bool
bCounting;
int
iOffset,
iCounter;
public void OnPluginStart()
{
if(GetEngineVersion() != Engine_CSGO) SetFailState("Plugin for CS:GO only!");
iOffset = FindSendPropInfo("CTeamplayRoundBasedRulesProxy", "m_bSwitchedTeamsThisRound");
HookEvent("round_start", ERS);
HookEvent("round_announce_last_round_half", Event_Half, EventHookMode_PostNoCopy);
}
public void OnMapStart()
{
bCounting = false;
iCounter = 0;
}
public void ERS(Event event, const char[] name, bool bdb)
{
if(bCounting) iCounter++;
else iCounter = GameRules_GetProp("m_totalRoundsPlayed");
if(IsSwitched())
{
iCounter = 0;
bCounting = true;
PrintToServer("\nTeams switched this round!\n");
}
for(int i = 1, type = iCounter > 4 ? 4 : iCounter; i <= MaxClients; i++)
if(IsClientInGame(i) && (!IsFakeClient(i) || !IsClientReplay(i) && !IsClientSourceTV(i)) && IsPlayerAlive(i))
{
ClearSlot(i, 0);
ClearSlot(i, 1);
GivePlayerItem(i, g_WeaponClasses[GetRandomInt(BOUNDS[type][0], BOUNDS[type][1])]);
}
}
public void Event_Half(Event event, const char[] name, bool bdb)
{
iCounter = 0;
bCounting = true;
PrintToServer("\nLast round half!\n");
}
stock bool IsSwitched()
{
if(iOffset < 1)
return false;
int ent = FindEntityByClassname(MaxClients+1, "cs_gamerules");
if(ent == -1)
return false;
return !!GetEntData(ent, iOffset);
}
stock bool ClearSlot(int client, int slot)
{
int ent;
return (ent = GetPlayerWeaponSlot(client, slot)) != -1 && RemovePlayerItem(client, ent)
&& AcceptEntityInput(ent, "KillHierarchy");
}