Raised This Month: $12 Target: $400
 3% 

Kick Players When player with flag join


Post New Thread Reply   
 
Thread Tools Display Modes
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-28-2018 , 00:34   Re: Kick Players When player with flag join
Reply With Quote #11

Ok, maybe FakeClientCommandEx and KickClient functions worked same time.
So I added timer, to delay FakeClientCommand.

second versio
__________________
Do not Private Message @me
Bacardi is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 10-28-2018 , 03:46   Re: Kick Players When player with flag join
Reply With Quote #12

Just try OnClientPostAdminCheck
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 10-28-2018 , 07:03   Re: Kick Players When player with flag join
Reply With Quote #13

Well that worked, but it didnt changed me for him, it kicked the player, but I needed to choose the team
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-28-2018 , 07:17   Re: Kick Players When player with flag join
Reply With Quote #14

Ok, nice to hear. You could try increase timer delay 0.1 to 0.6 if that helps.

Or maybe we need look to hide team menu, and perhaps use cs_switchteam...
Now I don't have time to look

*edit
Hey. in CSGO, there is event "jointeam_failed". I try re-code my sample

*edit edit
Hey, here different plugin versio of this.
- follow event "jointeam_failed"
- not look jointeam command.
PHP Code:
/*
Server event "jointeam_failed", Tick 44284:
- "userid" = "2"
- "reason" = "2"

Server event "jointeam_failed", Tick 44435:
- "userid" = "2"
- "reason" = "3"

Server event "jointeam_failed", Tick 44709:
- "userid" = "2"
- "reason" = "1"

*/



public void OnPluginStart()
{
    
HookEventEx("jointeam_failed"jointeam_failed);
}


public 
void jointeam_failed(Event event, const char[] namebool dontBroadcast)
{

    
int client GetClientOfUserId(event.GetInt("userid"));

    if(
client == || !IsClientInGame(client) || IsFakeClient(client) || GetClientTeam(client) > 1) return;


    
// reason:
    // 1 = Random team join - both team full;
    // 2 = Terrorist team join - team full;
    // 3 = Counter-Terrorist team join - team full;

    
if(event.GetInt("reason") != 1) return;

    if(!
CheckCommandAccess(client"vip"ADMFLAG_RESERVATION)) return;



    
int count;
    
int[] players = new int[MaxClients+1];

    for(
int i 1<= MaxClientsi++)
    {
        if(
client == || !IsClientInGame(i) || IsFakeClient(i) || GetClientTeam(i) < || IsClientInKickQueue(i)) continue;

        
players[count] = i;
        
count++;
        
    }

    
// no free slots and no humans. Do nothing. No spawnpoints on map?
    
if(count == 0) return;

    
// get random target
    
int target players[GetRandomInt(0count-1)];

    
// Is target in admin cache
    
AdminId target_adminid GetUserAdmin(target);

    if(
target_adminid != INVALID_ADMIN_ID)
    {

        
AdminId client_adminid GetUserAdmin(client);

        
// You can't target this admin!
        
if(!CanAdminTarget(client_adminidtarget_adminid))
        {
            
PrintHintText(client"[SM] Couldn't kick %N\nPlease, try jointeam random again."target);
            return;
        }

        
// You can't target this vip!
        // Use this code if you not want vip to kick another vip

        //if(CheckCommandAccess(target, "vip", ADMFLAG_RESERVATION))
        //{
        //    PrintHintText(client, "<font color='#FF6A00'>[SM]</font> Couldn't kick %N\nPlease, try jointeam random again.", target);
        //    return;
        //}
    
}


    
LogAction(clienttarget"Jointeam kick - Player %L kicked from server to make room for player %L"targetclient);
    
KickClient(target"[SM] You have kicked from server to make room for VIP/admins. Sorry");

    
CreateTimer(0.6delayGetClientUserId(client));



}

public 
Action delay(Handle timerint userid)
{
    
int client GetClientOfUserId(userid);

    if(
client != && IsClientInGame(client) && GetClientTeam(client) < 2FakeClientCommandEx(client"jointeam 0 1");

    return 
Plugin_Continue;

__________________
Do not Private Message @me

Last edited by Bacardi; 10-28-2018 at 08:41.
Bacardi is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 10-28-2018 , 09:44   Re: Kick Players When player with flag join
Reply With Quote #15

Depending on the game i would just use player_first_spawn event so it only ever fires when someone actually connects for the first time...in in L4D2 i know that event works. If u wanted to you could also rank players by how long they've been on the server and the one who was on for the least amount of time u could kick...
MasterMind420 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-28-2018 , 10:44   Re: Kick Players When player with flag join
Reply With Quote #16

I just assume (by his code), what OP try to do is, admin from spectator team -> can join in team even both team is full (not enough spawnpoint example.)
And to either cs:s or csgo game :/

Last edited by Bacardi; 10-28-2018 at 10:44.
Bacardi is offline
ilyasa48
AlliedModders Donor
Join Date: Feb 2018
Location: de_mirage
Old 05-09-2019 , 08:37   Re: Kick Players When player with flag join
Reply With Quote #17

Quote:
Originally Posted by Bacardi View Post
Ok, nice to hear. You could try increase timer delay 0.1 to 0.6 if that helps.

Or maybe we need look to hide team menu, and perhaps use cs_switchteam...
Now I don't have time to look

*edit
Hey. in CSGO, there is event "jointeam_failed". I try re-code my sample

*edit edit
Hey, here different plugin versio of this.
- follow event "jointeam_failed"
- not look jointeam command.
PHP Code:
/*
Server event "jointeam_failed", Tick 44284:
- "userid" = "2"
- "reason" = "2"

Server event "jointeam_failed", Tick 44435:
- "userid" = "2"
- "reason" = "3"

Server event "jointeam_failed", Tick 44709:
- "userid" = "2"
- "reason" = "1"

*/



public void OnPluginStart()
{
    
HookEventEx("jointeam_failed"jointeam_failed);
}


public 
void jointeam_failed(Event event, const char[] namebool dontBroadcast)
{

    
int client GetClientOfUserId(event.GetInt("userid"));

    if(
client == || !IsClientInGame(client) || IsFakeClient(client) || GetClientTeam(client) > 1) return;


    
// reason:
    // 1 = Random team join - both team full;
    // 2 = Terrorist team join - team full;
    // 3 = Counter-Terrorist team join - team full;

    
if(event.GetInt("reason") != 1) return;

    if(!
CheckCommandAccess(client"vip"ADMFLAG_RESERVATION)) return;



    
int count;
    
int[] players = new int[MaxClients+1];

    for(
int i 1<= MaxClientsi++)
    {
        if(
client == || !IsClientInGame(i) || IsFakeClient(i) || GetClientTeam(i) < || IsClientInKickQueue(i)) continue;

        
players[count] = i;
        
count++;
        
    }

    
// no free slots and no humans. Do nothing. No spawnpoints on map?
    
if(count == 0) return;

    
// get random target
    
int target players[GetRandomInt(0count-1)];

    
// Is target in admin cache
    
AdminId target_adminid GetUserAdmin(target);

    if(
target_adminid != INVALID_ADMIN_ID)
    {

        
AdminId client_adminid GetUserAdmin(client);

        
// You can't target this admin!
        
if(!CanAdminTarget(client_adminidtarget_adminid))
        {
            
PrintHintText(client"[SM] Couldn't kick %N\nPlease, try jointeam random again."target);
            return;
        }

        
// You can't target this vip!
        // Use this code if you not want vip to kick another vip

        //if(CheckCommandAccess(target, "vip", ADMFLAG_RESERVATION))
        //{
        //    PrintHintText(client, "<font color='#FF6A00'>[SM]</font> Couldn't kick %N\nPlease, try jointeam random again.", target);
        //    return;
        //}
    
}


    
LogAction(clienttarget"Jointeam kick - Player %L kicked from server to make room for player %L"targetclient);
    
KickClient(target"[SM] You have kicked from server to make room for VIP/admins. Sorry");

    
CreateTimer(0.6delayGetClientUserId(client));



}

public 
Action delay(Handle timerint userid)
{
    
int client GetClientOfUserId(userid);

    if(
client != && IsClientInGame(client) && GetClientTeam(client) < 2FakeClientCommandEx(client"jointeam 0 1");

    return 
Plugin_Continue;

its not work, could you fix this?

thanks before
ilyasa48 is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 05-11-2019 , 18:57   Re: Kick Players When player with flag join
Reply With Quote #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.
eyal282 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:18.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode