I have a problem with the plugin that blocks the change of teams and automatically adds players.
the problem is that the player can not buy a weapon
PHP Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#pragma newdecls required
#pragma semicolon 1
ConVar cvTeamchangelimit;
ConVar cvExcludespec;
Handle hTeam;
int iTeamchangecount[MAXPLAYERS+1];
public Plugin myinfo =
{
name = "Team Change Regulator",
author = "allienmods ",
description = "Regulates team change.",
version = "1.0",
url = "https://forums.alliedmods.net/showthread.php?t=306013"
};
public void OnPluginStart()
{
hTeam = CreateConVar("sm_join_team", "1", "Do not edit this");
cvTeamchangelimit = CreateConVar("sm_teamchange_limit", "1", "Sets how many times a player may switch between teams. Default = 1");
cvExcludespec = CreateConVar("sm_teamchange_excludespec", "1", "Should we exclude counting team changes to spectators? 0 = Disable");
AddCommandListener(cmdListener_Changeteam, "jointeam");
HookEvent("player_connect_full", vEvent_OnFullConnect, EventHookMode_Post);
}
public void vEvent_OnFullConnect(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (client != 0 && IsClientInGame(client) && !IsFakeClient(client) && !bIsAdminRoot(client))
{
CreateTimer(0.5, tAssignTeam, client);
}
}
public void OnClientPutInServer(int client)
{
if (!IsFakeClient(client) && IsClientInGame(client))
{
iTeamchangecount[client] = 0;
}
}
public Action tAssignTeam(Handle timer, any client)
{
if (IsClientInGame(client))
{
int iCvar = GetConVarInt(hTeam);
switch (iCvar)
{
case 0:
{
return Plugin_Handled;
}
case 1:
{
int iRed;
int iBlue;
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i))
{
continue;
}
int iTeam = GetClientTeam(i);
if (iTeam == CS_TEAM_T)
{
iRed++;
}
else if (iTeam == CS_TEAM_CT)
{
iBlue++;
}
}
if (iRed > iBlue)
{
ChangeClientTeam(client, 3);
}
else if (iRed < iBlue || iRed == iBlue)
{
ChangeClientTeam(client, 2);
}
}
case 2:
{
ChangeClientTeam(client, 2);
}
case 3:
{
ChangeClientTeam(client, 3);
}
}
}
return Plugin_Continue;
}
public Action cmdListener_Changeteam(int client, const char[] command, int args)
{
if (bIsAdminRoot(client))
{
return Plugin_Continue;
}
if (iTeamchangecount[client] == cvTeamchangelimit.IntValue)
{
PrintToChat(client, "[TeamManager] Nie mozesz ponownie zmienic teamu!!!");
PrintCenterText(client, "<font color='#FF0000'><b>[TeamManager]</font> <font color='#FFFFFF'>Nie mozesz ponownie zmienic teamu!!!</font>");
return Plugin_Handled;
}
char arg1[3];
GetCmdArg(1, arg1, sizeof(arg1));
int target_team = StringToInt(arg1);
int current_team = GetClientTeam(client);
if (target_team == current_team)
{
return Plugin_Handled;
}
else if ((target_team > 1 && cvExcludespec.IntValue >= 1) || cvExcludespec.IntValue < 1)
{
iTeamchangecount[client]++;
}
return Plugin_Handled;
}
bool bIsAdminRoot(int client)
{
return (CheckCommandAccess(client, "team_change_admin", ADMFLAG_ROOT, false));
}