AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Prevent class change in TF2 (https://forums.alliedmods.net/showthread.php?t=294394)

cidra 02-26-2017 05:35

Prevent class change in TF2
 
Yes, i don't know how, i typed "class" instead of "team" in the topic title, i'm sleeping i guess. Sorry!


Hi all. I'm trying to make something simple in Sourcemod that simply prevent a client from switching team when it's reached the limit.


Code:

public OnPluginStart()
{
        HookEvent("player_team",Event_PlayerTeam);
}

public Event_PlayerTeam(Handle:event,  const String:name[], bool:dontBroadcast)
{
        new iClient = GetClientOfUserId(GetEventInt(event, "userid")),
                        oldTeam  = GetClientTeam(iClient),
                        newTeam = GetEventInt(event, "team");
                       
        if (fullTeam(newTeam))
        {
                PrintToChat(iClient, "Full team.");
                TF2_SetPlayerClass(iClient, TFClass_Unknown);
                ChangeClientTeam(iClient, 1);
        }
}

bool:fullTeam(iTeam)
{
        if(iTeam < 2)
                return false;
       
        else if(GetTeamClientCount(iTeam) >= 2)
        {
                return true;
        }
        return false;
}

Plugin is compiled without errors. I run it in my server but when there are (for example) 2 players on team RED and i try to switch to RED team this appears in chat:


cidra has joined team RED
Full team.
cidra has joined team SPECTATORS

This should be normal, but actually my client stays on RED team, not on SPEC.


At the beginning i tried to set the client's team to the old one. Now i also tried to simply switch to spectator team but with the same results (Here the reason why oldTeam is never used)

What could be the problem? Thanks in advance for you availability.

Chaosxk 02-26-2017 15:46

Re: Prevent class change in TF2
 
You can block the player from joining team instead.

Code:

public void OnPluginStart()
{
        AddCommandListener(Hook_JoinTeam, "jointeam");
}

public Action Hook_JoinTeam(int client, const char[] command, int argc)
{
        return Plugin_Handled;
}

Should probably "return Plugin_Continue;" when player is in spectate mode.

cidra 02-28-2017 10:16

Re: Prevent class change in TF2
 
Quote:

Originally Posted by Chaosxk (Post 2498899)
You can block the player from joining team instead.

Code:

public void OnPluginStart()
{
        AddCommandListener(Hook_JoinTeam, "jointeam");
}

public Action Hook_JoinTeam(int client, const char[] command, int argc)
{
        return Plugin_Handled;
}

Should probably "return Plugin_Continue;" when player is in spectate mode.

Is there no way to do that with HookEvent? Using AddComandListener what should i do in case someone types jointeam auto? (Or simply, selects "auto" in the team select menu)

WildCard65 02-28-2017 11:39

Re: Prevent class change in TF2
 
Snippet blocks all usage of jointeam no matter args

cidra 02-28-2017 13:43

Re: Prevent class change in TF2
 
Quote:

Originally Posted by WildCard65 (Post 2499421)
Snippet blocks all usage of jointeam no matter args

I know, but if i add some controls before return Plugin_Handled; it should block the usage of the command only in specific circumstances, am i right? So what if someone select "auto-select team" (So basically types jointeam auto in console)?
Just asking: why can't i use HookEvent to prevent team changes while i can do that to prevent class changes? :shock:

sdz 02-28-2017 15:37

Re: Prevent class change in TF2
 
Quote:

Originally Posted by cidra (Post 2499481)
I know, but if i add some controls before return Plugin_Handled; it should block the usage of the command only in specific circumstances, am i right? So what if someone select "auto-select team" (So basically types jointeam auto in console)?
Just asking: why can't i use HookEvent to prevent team changes while i can do that to prevent class changes? :shock:

Something people overlook way too often is that a command listener does work similar to a command in the idea that it can read arguments that are sent. Arguements do get sent in jointeam. teamid is usually one of these.
Using this obtuse information, we could further implement a case-by-case basis on how hard we want to bone people.

Soooo, something like this is what I use in one of my plugins. Clearly a modifimidicated version of jointeam. If this doesn't help you at all, then well sorry for wasting your time lol.
You'll see something like "teamJoinAuth" in the code. I use GetRandomInt to generate that at plugin start. Ideally a pseudo anti-bypass or something.

PHP Code:

public Action:joinListener(client, const String:command[], args)
{
    if(
g_bLive)
    {
        
CPrintToChat(client"%s You are currently unable to switch teams."CHATTAG);
        return 
Plugin_Handled;
    }

    if(!
g_bSwitch[client])
    {
        
decl String:sTeam[32];
        
GetCmdArg(1sTeamsizeof(sTeam));
        new 
newTeam StringToInt(sTeam);

        if(
args == 1)
        {
            new 
Handle:dataPack CreateDataPack();
            
WritePackCell(dataPackGetClientUserId(client));
            
WritePackCell(dataPacknewTeam);
            
g_bSwitch[client] = true;

            
CreateTimer(5.0teamJoindataPack);
            
CPrintToChat(client"%s Waiting five seconds to join another team..."CHATTAG);
            return 
Plugin_Handled;
        }    
        else if(
args == 2//Jointeam function
        
{
            
decl String:sAuth[32];
            
GetCmdArg(2sAuthsizeof(sAuth));
            if(
StringToInt(sAuth) == teamJoinAuth)
            {
                
g_bSwitch[client] = false;
                return 
Plugin_Changed;
            }
            else return 
Plugin_Handled;
        }
    }

    return 
Plugin_Handled;
}

public 
Action:teamJoin(Handle:timerHandle:dataPack)
{
    
ResetPack(dataPack);
    new 
client GetClientOfUserId(ReadPackCell(dataPack));
    new 
team ReadPackCell(dataPack);

    
ChangeClientTeam(clientteam);
    if(
IsPlayerAlive(client)) ForcePlayerSuicide(client);
    
ClientCommand(client"jointeam %i %i"teamteamJoinAuth);

    
decl String:teamFmt[16];
    switch(
team)
    {
        case 
01teamFmt "Spectator";
        case 
TEAM_COMBINEteamFmt "Blue";
        case 
TEAM_REBELteamFmt "Red";
    }

    
CPrintToChatAll("%s {white}%N{default} has joined team: {white}%s{default}."CHATTAGclientteamFmt);
    
g_bSwitch[client] = false;
    return 
Plugin_Handled;



WildCard65 02-28-2017 15:41

Re: Prevent class change in TF2
 
Quote:

Originally Posted by cidra (Post 2499481)
Just asking: why can't i use HookEvent to prevent team changes while i can do that to prevent class changes? :shock:

The hook is fired AFTER the command has done it's job and switched the client's team.

Powerlord 02-28-2017 17:54

Re: Prevent class change in TF2
 
If you're doing this by hooking commands, you're going to need to handle autoteam as well (which is the same as clicking on the Auto door in the team selection screen).


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

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