AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Kick Players When player with flag join (https://forums.alliedmods.net/showthread.php?t=311634)

TrullSin 10-26-2018 17:45

Kick Players When player with flag join
 
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);  
                    }  
                }  
            }  
        }  
    }  



Bacardi 10-26-2018 18:09

Re: Kick Players When player with flag join
 
Why people still play with admin flags in code... use CheckCommandAccess :/

Bacardi 10-27-2018 10:02

Re: Kick Players When player with flag join
 
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");



TrullSin 10-27-2018 15:14

Re: Kick Players When player with flag join
 
It doesent work, server is full I try to join and nothing happens..

Bacardi 10-27-2018 15:32

Re: Kick Players When player with flag join
 
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.

TrullSin 10-27-2018 15:55

Re: Kick Players When player with flag join
 
I try to join random team and dont work either

Bacardi 10-27-2018 16:34

Re: Kick Players When player with flag join
 
Could you check sourcemod logs and errors

TrullSin 10-27-2018 17:00

Re: Kick Players When player with flag join
 
The thing is that, i get no sourcemod logs errors or anything..

Bacardi 10-27-2018 17:48

Re: Kick Players When player with flag join
 
Ok. Could you re-check that you are running SM on server?

rcon plugin_print
rcon meta list
rcon sm plugins list

TrullSin 10-27-2018 18:46

Re: Kick Players When player with flag join
 
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.


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

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