Raised This Month: $32 Target: $400
 8% 

Solved [L4D2] Kick all clients except who issued the command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spinning Turte
Junior Member
Join Date: May 2019
Old 05-17-2019 , 04:30   [L4D2] Kick all clients except who issued the command
Reply With Quote #1

I'm trying to find a way to kick every player with a command except for me (who issued the command
This is what I have now, obviously, it is not complete and not work, I need to figure out and solve
PHP Code:
for(new 1<= MaxClientsi++)
        {
            new 
kick GetClientUserId(i);
            if(!
IsFakeClient(client)) 
            {
                if (!
client && !IsFakeClient(client))
                {
                
KickClient(i"An admin kicked you.");
                
PrintToChatAll("\x01The player \x03%s has been kicked.");
                
LogMessage("The player %s has been kicked.");
                }
            }
        } 

Last edited by Spinning Turte; 05-19-2019 at 07:48.
Spinning Turte is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 05-17-2019 , 05:14   Re: [L4D2] Kick all clients except who issued the command
Reply With Quote #2

upd. forgot to remove the client from target index.
PHP Code:
public void OnPluginStart() {
    
RegAdminCmd("sm_kickall"kickallADMFLAG_KICK);
}

public 
Action kickall(int clientint args) {
    for(
int i 1<= MaxClientsi++) {
        if(
IsClientInGame(i) && != client && !IsFakeClient(i)) {
            
KickClient(i"An admin kicked you");
            
LogMessage("Admin %N kicked all players"client);
         }
    }


Last edited by farawayf; 05-17-2019 at 05:24.
farawayf is offline
CrazyHackGUT
AlliedModders Donor
Join Date: Feb 2016
Location: Izhevsk, Russia
Old 05-17-2019 , 05:15   Re: [L4D2] Kick all clients except who issued the command
Reply With Quote #3

For what purposes you get user id?
You can use default command sm_kick with argument @!me. This kicks everyone, who you can target, without you. More details here.

Or, if you like write code...
Code:
for (new i = 1; i <= MaxClients; ++i)
{
	if (IsClientInGame(i) && !IsClientInKickQueue(i) && i != client) // client - user, who issued command.
	{
		KickClient(i, "An admin kicked you.");
		PrintToChatAll("\x01The player %N has been kicked.", i);
		LogMessage("The player %L has been kicked.", i);
	}
}
__________________
My english is very bad. I am live in Russia. Learning english language - very hard task for me...

Last edited by CrazyHackGUT; 05-17-2019 at 05:17. Reason: Added link on SourceMod wiki about client targeting
CrazyHackGUT is offline
Send a message via ICQ to CrazyHackGUT Send a message via Skype™ to CrazyHackGUT
Spinning Turte
Junior Member
Join Date: May 2019
Old 05-17-2019 , 06:25   Re: [L4D2] Kick all clients except who issued the command
Reply With Quote #4

Quote:
Originally Posted by CrazyHackGUT View Post
For what purposes you get user id?
Because It was a part of one old try and I forgot to remove it
Spinning Turte is offline
Spinning Turte
Junior Member
Join Date: May 2019
Old 05-17-2019 , 06:27   Re: [L4D2] Kick all clients except who issued the command
Reply With Quote #5

Quote:
Originally Posted by farawayf View Post
upd. forgot to remove the client from target index.
PHP Code:
public void OnPluginStart() {
    
RegAdminCmd("sm_kickall"kickallADMFLAG_KICK);
}

public 
Action kickall(int clientint args) {
    for(
int i 1<= MaxClientsi++) {
        if(
IsClientInGame(i) && != client && !IsFakeClient(i)) {
            
KickClient(i"An admin kicked you");
            
LogMessage("Admin %N kicked all players"client);
         }
    }

Thanks you, I tried for days

Edit can I also take the kicked player's name? (not really necessary for me. just to have it)

Last edited by Spinning Turte; 05-17-2019 at 07:01.
Spinning Turte is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 05-17-2019 , 08:20   Re: [L4D2] Kick all clients except who issued the command
Reply With Quote #6

Quote:
Originally Posted by Spinning Turte View Post
Edit can I also take the kicked player's name? (not really necessary for me. just to have it)
for print in chat ?
PHP Code:
if(IsClientInGame(i) && != client && !IsFakeClient(i)) {
    
PrintToChatAll("\x01The player %N has been kicked."i);
    
KickClient(i"An admin kicked you.");
}
LogMessage("Admin %N kicked all players."client);
return 
Plugin_Handled
another way
PHP Code:
char nicks[126];
Format(nickssizeof(nicks), "\x01The players has been kicked: ");
for(
int i 1<= MaxClientsi++) {
    if(
IsClientInGame(i) && != client && !IsFakeClient(i)) {
        
Format(nickssizeof(nicks), "%s,%N"nicksi);
        
KickClient(i"An admin kicked you.");
    }
}
LogMessage("Admin %N kicked all players."client);
PrintToChatAll("%s"nicks);
return 
Plugin_Handled

Last edited by farawayf; 05-17-2019 at 08:52.
farawayf is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 05-17-2019 , 08:25   Re: [L4D2] Kick all clients except who issued the command
Reply With Quote #7

Move
PHP Code:
LogMessage("Admin %N kicked all players."client); 
outside the for loop, otherwise it's gonna log for every kick.

Also need to return Plugin_Handled; at the end of the command otherwise it'll show up as unknown command when run

Last edited by CliptonHeist; 05-17-2019 at 08:31.
CliptonHeist is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 05-17-2019 , 08:50   Re: [L4D2] Kick all clients except who issued the command
Reply With Quote #8

Quote:
Originally Posted by CliptonHeist View Post
Move
PHP Code:
LogMessage("Admin %N kicked all players."client); 
outside the for loop, otherwise it's gonna log for every kick.

Also need to return Plugin_Handled; at the end of the command otherwise it'll show up as unknown command when run
Good to know. My bad, im a beginner.
farawayf 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 05:52.


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