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

Kick Players When player with flag join


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TrullSin
Senior Member
Join Date: Jun 2018
Old 10-26-2018 , 17:45   Kick Players When player with flag join
Reply With Quote #1

Hi,

For any reason this is not working, any ideas why?

PHP Code:
#include <sourcemod>  
#include <sdktools>  
#include <cstrike>  

public OnPluginStart()  
{  
    
AddCommandListener(Command_JoinTeam"jointeam");  
}  

public 
Action:Command_JoinTeam(client, const String:command[], args)  
{  
    new 
players GetClientCount(true);  
    new 
playersInTeams 1;  
    new 
kickYes 1;  
      
    
//Player needs to be a spectator  
    
if(GetClientTeam(client) != CS_TEAM_CT || GetClientTeam(client) != CS_TEAM_T)  
    {  
        
//Player needs to have an admin flag  
        
if(GetUserAdmin(client) != INVALID_ADMIN_ID)  
        {  
            
//Count the amount of players in both teams  
            
for(new 1<= playersx++)  
            {  
                if(!
IsClientInGame(x)) continue;  

                if(
GetClientTeam(x) == CS_TEAM_T || GetClientTeam(x) == CS_TEAM_CT)  
                {  
                    
playersInTeams += 1;  
                }  
            }  
              
            
//Find a player with no admin flags  
            
for(new 1<= playersi++)  
            {  
                if(!
IsClientInGame(i)) continue;  
                if (
GetClientTeam(i) == CS_TEAM_CT || GetClientTeam(i) == CS_TEAM_T)  
                {  
                    if(
GetUserAdmin(i) == INVALID_ADMIN_ID && kickYes == && playersInTeams 19)  
                    {  
                        
//Get the about-to-be-kicked player's team  
                        
new teamToJoin GetClientTeam(i);  
                          
                        
//Not sure if this is the best way to inform the kicked player - or if it even works...  
                        
PrintToConsole(i"[SM] You got kicked because Admin/VIP joined from spectate and teams are full.");  
                         
                        
KickClient(i"You have been kicked because Admin/VIP joined from spectate and teams are full."); 
                          
                        
kickYes 0;  
                          
                        
ChangeClientTeam(clientteamToJoin);  
                    }  
                }  
            }  
        }  
    }  


Last edited by TrullSin; 10-26-2018 at 17:45.
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-26-2018 , 18:09   Re: Kick Players When player with flag join
Reply With Quote #2

Why people still play with admin flags in code... use CheckCommandAccess :/
__________________
Do not Private Message @me
Bacardi is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-27-2018 , 10:02   Re: Kick Players When player with flag join
Reply With Quote #3

I don't have server with players to test this code.

So here, if you like.
- player who have admin flag "a" (reservation) or have access to so called command "vip", can try join full teams from spectators.
- you can override "vip" to another admin flag(s) from admin_overrides.cfg without editing plugin code.

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[] commandint args)
{


    
// In this code, bypass only no-team and spectator
    
if(client == || !IsClientInGame(client) || IsFakeClient(client) || GetClientTeam(client) > 1) return Plugin_Continue;



    
char buffer[2];
    
GetCmdArg(1buffersizeof(buffer));
    
int jointeam_value StringToInt(buffer);

    
// Random jointeam "0", no free slots and have access
    
if(jointeam_value != || numTSlotsFree != 0  || numCTSlotsFree != || !CheckCommandAccess(client"vip"ADMFLAG_RESERVATION)) return Plugin_Continue;



    
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 Plugin_Continue;

    
// 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 
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(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");

    
FakeClientCommandEx(client"jointeam 0 1");



    return 
Plugin_Continue;
}

// update free slots variables
public void switch_team(Event event, const char[] namebool dontBroadcast)
{
    
numTSlotsFree event.GetInt("numTSlotsFree");
    
numCTSlotsFree event.GetInt("numCTSlotsFree");

__________________
Do not Private Message @me

Last edited by Bacardi; 10-27-2018 at 10:03.
Bacardi is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 10-27-2018 , 15:14   Re: Kick Players When player with flag join
Reply With Quote #4

It doesent work, server is full I try to join and nothing happens..
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-27-2018 , 15:32   Re: Kick Players When player with flag join
Reply With Quote #5

I forgot mention, it should work when you are in spec team and you jointeam random. Don't choose team.

I could try look again when I have time.
Bacardi is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 10-27-2018 , 15:55   Re: Kick Players When player with flag join
Reply With Quote #6

I try to join random team and dont work either
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-27-2018 , 16:34   Re: Kick Players When player with flag join
Reply With Quote #7

Could you check sourcemod logs and errors
__________________
Do not Private Message @me
Bacardi is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 10-27-2018 , 17:00   Re: Kick Players When player with flag join
Reply With Quote #8

The thing is that, i get no sourcemod logs errors or anything..
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-27-2018 , 17:48   Re: Kick Players When player with flag join
Reply With Quote #9

Ok. Could you re-check that you are running SM on server?

rcon plugin_print
rcon meta list
rcon sm plugins list
__________________
Do not Private Message @me
Bacardi is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 10-27-2018 , 18:46   Re: Kick Players When player with flag join
Reply With Quote #10

I put the plugin in the server, then i did this: sm plugins load reservedtest and the console said: blablabla load successfully, I have the latest stable sourcemod and metamod.
TrullSin is offline
Reply



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 21:56.


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