Veteran Member
|
05-11-2019
, 18:57
Re: Kick Players When player with flag join
|
#18
|
Code:
#include <sourcemod>
// RESERVE_MAX_PLAYERS should be equal to the maximum amount of players allowed in the server without reservation. If the player count is equal or greater than this number and a ADMFLAG_RESERVATION joins, kicking will occur.
#define RESERVE_MAX_PLAYERS 20
public OnClientPostAdminCheck(client)
{
if(!CheckCommandAccess(client, "sm_checkcommandaccess_reservation", ADMFLAG_RESERVATION, true))
return;
new TClients[MaxClients+1], CTClients[MaxClients+1], TCount, CTCount, PlayerCount;
new TCanBeKicked = false, CTCanBeKicked = false;
for(new i=1;i <= MaxClients;i++)
{
if(!IsClientInGame(i))
continue;
switch(GetClientTeam(i))
{
case CS_TEAM_T:
{
TClients[TCount++] = i;
if(!CheckCommandAccess(i, "sm_checkcommandaccess_reservation", ADMFLAG_RESERVATION))
TCanBeKicked = true;
}
case CS_TEAM_CT:
{
CTClients[CTCount++] = i;
if(!CheckCommandAccess(i, "sm_checkcommandaccess_reservation", ADMFLAG_RESERVATION))
CTCanBeKicked = true;
}
}
}
if(!TCanBeKicked && !CTCanBeKicked) // In this case, the entire server has reservation, nobody to kick lol.
return;
PlayerCount = TCount + CTCount;
if(PlayerCount < RESERVE_MAX_PLAYERS)
return;
new KickTarget;
if(TCount > CTCount || !CTCanBeKicked)
{
KickTarget = GetRandomPlayer(CS_TEAM_T);
KickClient(KickTarget, "You have been kicked due to reservation.");
ChangeClientTeam(client, CS_TEAM_T);
return;
}
if(TCount < CTCount || !TCanBeKicked)
{
KickTarget = GetRandomPlayer(CS_TEAM_CT);
KickClient(KickTarget, "You have been kicked due to reservation.");
ChangeClientTeam(client, CS_TEAM_CT);
return;
}
new TeamToKick = GetRandomInt(CS_TEAM_CT, CS_TEAM_T); // If this line gives an error, replace the locations of CS_TEAM_CT and CS_TEAM_T
KickTarget = GetRandomPlayer(TeamToKick);
KickClient(KickTarget, "You have been kicked due to reservation.");
ChangeClientTeam(client, TeamToKick);
}
stock GetRandomPlayer(Team)
{
new clients[MaxClients+1], Count;
for(new i=1;i <= MaxClients;i++)
{
if(!IsClientInGame(i))
continue;
else if(GetClientTeam(i) != Team)
continue;
else if(CheckCommandAccess(i, "sm_checkcommandaccess_reservation", ADMFLAG_RESERVATION))
continue;
clients[Count++] = i;
}
return clients[GetRandomInt(0, Count-1)];
}
Try this: not tested or even tried to compile.
Code:
#include <sourcemod>
#include <cstrike>
// RESERVE_MAX_PLAYERS should be equal to the maximum amount of players allowed in the server without reservation. If the player count is equal or greater than this number and a ADMFLAG_RESERVATION joins, kicking will occur.
#define RESERVE_MAX_PLAYERS 20
public OnPluginStart()
{
HookEvent("jointeam_failed", Event_JoinTeamFailed);
}
public Action:Event_JoinTeamFailed(Handle:hEvent, const String:Name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
if(!CheckCommandAccess(client, "sm_checkcommandaccess_reservation", ADMFLAG_RESERVATION, true))
return;
new TeamChosen = GetEventInt(hEvent, "reason");
if(TeamChosen == CS_TEAM_SPECTATOR)
TeamChosen = GetRandomInt(CS_TEAM_T, CS_TEAM_CT);
new TClients[MaxClients+1], CTClients[MaxClients+1], TCount, CTCount, PlayerCount;
new TCanBeKicked = false, CTCanBeKicked = false;
for(new i=1;i <= MaxClients;i++)
{
if(!IsClientInGame(i))
continue;
switch(GetClientTeam(i))
{
case CS_TEAM_T:
{
TClients[TCount++] = i;
if(!CheckCommandAccess(i, "sm_checkcommandaccess_reservation", ADMFLAG_RESERVATION))
TCanBeKicked = true;
}
case CS_TEAM_CT:
{
CTClients[CTCount++] = i;
if(!CheckCommandAccess(i, "sm_checkcommandaccess_reservation", ADMFLAG_RESERVATION))
CTCanBeKicked = true;
}
}
}
PlayerCount = TCount + CTCount;
if(PlayerCount < RESERVE_MAX_PLAYERS) // No need to kick.
return;
else if(!TCanBeKicked && !CTCanBeKicked) // In this case, the entire server has reservation, nobody to kick lol.
{
PrintToChat(client, "Tough luck - everybody in the server has reservation.");
return;
}
new KickTarget;
if(TeamChosen == CS_TEAM_T)
{
if(!TCanBeKicked)
{
PrintToChat(client, "Nobody in the terrorist team can be kicked.");
return;
}
KickTarget = GetRandomPlayer(CS_TEAM_T);
if(IsPlayerAlive(KickTarget))
ForcePlayerSuicide(KickTarget);
CS_SwitchTeam(KickTarget, CS_TEAM_SPECTATOR); // Since he's in spectator, we need no delay with certainty.
CS_SwitchTeam(client, CS_TEAM_T);
KickClient(KickTarget, "You have been kicked due to reservation.");
return;
}
else if(TeamChosen == CS_TEAM_CT)
{
if(!CTCanBeKicked)
{
PrintToChat(client, "Nobody in the CT team can be kicked.");
return;
}
KickTarget = GetRandomPlayer(CS_TEAM_CT);
if(IsPlayerAlive(KickTarget))
ForcePlayerSuicide(KickTarget);
CS_SwitchTeam(KickTarget, CS_TEAM_SPECTATOR); // Since he's in spectator, we need no delay with certainty.
CS_SwitchTeam(client, CS_TEAM_CT);
KickClient(KickTarget, "You have been kicked due to reservation.");
return;
}
}
stock GetRandomPlayer(Team)
{
new clients[MaxClients+1], Count;
for(new i=1;i <= MaxClients;i++)
{
if(!IsClientInGame(i))
continue;
else if(GetClientTeam(i) != Team)
continue;
else if(CheckCommandAccess(i, "sm_checkcommandaccess_reservation", ADMFLAG_RESERVATION))
continue;
clients[Count++] = i;
}
return clients[GetRandomInt(0, Count-1)];
}
__________________
I am available to make plugins for pay.
Discord: Eyal282#1334
Last edited by eyal282; 05-04-2021 at 11:56.
|
|