Veteran Member
Join Date: Jan 2010
Location: mom's basement
10-28-2018
, 00:34
Re: Kick Players When player with flag join
#11
Ok, maybe FakeClientCommandEx and KickClient functions worked same time.
So I added timer, to delay FakeClientCommand.
second versio
PHP Code:
/*
Server event "switch_team", Tick 2966:
- "numPlayers" = "1"
- "numSpectators" = "0"
- "avg_rank" = "0"
- "numTSlotsFree" = "10"
- "numCTSlotsFree" = "9"
*/
int numTSlotsFree ;
int numCTSlotsFree ;
public void OnPluginStart ()
{
AddCommandListener ( jointeam , "jointeam" );
HookEventEx ( "switch_team" , switch_team );
}
public void OnMapStart ()
{
// While we wait "switch_team" event to update FreeSlots count, lets reset variables to avoid wierd bug.
numTSlotsFree = 15 ;
numCTSlotsFree = 15 ;
}
public Action jointeam ( int client , const char [] command , int args )
{
// In this code, bypass only no-team and spectator
if( client == 0 || ! IsClientInGame ( client ) || IsFakeClient ( client ) || GetClientTeam ( client ) > 1 ) return Plugin_Continue ;
char buffer [ 5 ];
GetCmdArg ( 1 , buffer , sizeof ( buffer ));
int jointeam_value = StringToInt ( buffer );
// Random jointeam "0", no free slots and have access
if( jointeam_value != 0 || numTSlotsFree != 0 || numCTSlotsFree != 0 || ! CheckCommandAccess ( client , "vip" , ADMFLAG_RESERVATION )) return Plugin_Continue ;
int count ;
int [] players = new int [ MaxClients + 1 ];
for( int i = 1 ; i <= MaxClients ; i ++)
{
if( client == i || ! IsClientInGame ( i ) || IsFakeClient ( i ) || GetClientTeam ( i ) < 2 || IsClientInKickQueue ( i )) continue;
players [ count ] = i ;
count ++;
}
// no free slots and no humans. Do nothing. No spawnpoints on map?
if( count == 0 ) return Plugin_Continue ;
// get random target
int target = players [ GetRandomInt ( 0 , count - 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_adminid , target_adminid ))
{
PrintHintText ( client , "[SM] Couldn't kick %N\nPlease, try jointeam random again." , target );
return Plugin_Continue ;
}
// 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 Plugin_Continue;
//}
}
LogAction ( client , target , "Jointeam kick - Player %L kicked from server to make room for player %L" , target , client );
KickClient ( target , "[SM] You have kicked from server to make room for VIP/admins. Sorry" );
CreateTimer ( 0.1 , delay , GetClientUserId ( client ));
return Plugin_Continue ;
}
public Action delay ( Handle timer , int userid )
{
int client = GetClientOfUserId ( userid );
if( client != 0 && IsClientInGame ( client ) && GetClientTeam ( client ) < 2 ) FakeClientCommandEx ( client , "jointeam 0 1" );
return Plugin_Continue ;
}
// update free slots variables
public void switch_team ( Event event , const char [] name , bool dontBroadcast )
{
numTSlotsFree = event . GetInt ( "numTSlotsFree" );
numCTSlotsFree = event . GetInt ( "numCTSlotsFree" );
}
__________________
Do not Private Message @me