#include <sourcemod>
#include <sdktools>
#include <clientprefs>
#define TEAM_TERRORIST 2
#define TEAM_CT 3
// 全局变量
bool g_bGameStarted = false;
// 插件初始化函数
public void OnPluginStart()
{
// 注册热身和比赛开始监听
HookEvent("round_start", OnRoundStart, EventHookMode_Post);
HookEvent("game_newmap", OnGameNewMap, EventHookMode_Post);
HookEvent("player_team", OnPlayerChangeTeam, EventHookMode_Post);
// 启动时检查当前状态
g_bGameStarted = false;
}
// 监听新地图开始时重置比赛状态
public void OnGameNewMap(Event event, const char[] name, bool dontBroadcast)
{
g_bGameStarted = false; // 游戏还没有开始
}
// 监听回合开始
public void OnRoundStart(Event event, const char[] name, bool dontBroadcast)
{
g_bGameStarted = false; // 设置为热身阶段
}
// 监听玩家切换队伍
public void OnPlayerChangeTeam(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
// 如果比赛已经开始,禁止切换队伍
if (g_bGameStarted && client != 0)
{
int currentTeam = GetClientTeam(client);
// 如果玩家试图切换到敌队,回退其操作
if (currentTeam == TEAM_TERRORIST)
{
PrintToChat(client, "比赛开始后无法切换到反恐队。");
ForcePlayerChangeTeam(client, TEAM_TERRORIST);
}
else if (currentTeam == TEAM_CT)
{
PrintToChat(client, "比赛开始后无法切换到恐怖分子队。");
ForcePlayerChangeTeam(client, TEAM_CT);
}
}
else
{
// 在热身阶段允许切换队伍
PrintToChat(client, "您可以自由切换队伍。");
}
}
// 监听游戏开始时的事件
public void OnGameStart(Event event, const char[] name, bool dontBroadcast)
{
// 比赛开始时禁止换队
g_bGameStarted = true;
PrintToChatAll("比赛已开始,禁止手动换队!");
}