Raised This Month: $ Target: $400
 0% 

Prevent class change in TF2


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 02-26-2017 , 05:35   Prevent class change in TF2
Reply With Quote #1

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.

Last edited by cidra; 02-26-2017 at 06:05.
cidra is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 02-26-2017 , 15:46   Re: Prevent class change in TF2
Reply With Quote #2

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.
__________________
Chaosxk is offline
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 02-28-2017 , 10:16   Re: Prevent class change in TF2
Reply With Quote #3

Quote:
Originally Posted by Chaosxk View Post
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)
cidra is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 02-28-2017 , 11:39   Re: Prevent class change in TF2
Reply With Quote #4

Snippet blocks all usage of jointeam no matter args
__________________
WildCard65 is offline
cidra
Junior Member
Join Date: Jun 2016
Location: Italy
Old 02-28-2017 , 13:43   Re: Prevent class change in TF2
Reply With Quote #5

Quote:
Originally Posted by WildCard65 View Post
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?
cidra is offline
sdz
Senior Member
Join Date: Feb 2012
Old 02-28-2017 , 15:37   Re: Prevent class change in TF2
Reply With Quote #6

Quote:
Originally Posted by cidra View Post
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?
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;


Last edited by sdz; 02-28-2017 at 15:40.
sdz is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 02-28-2017 , 15:41   Re: Prevent class change in TF2
Reply With Quote #7

Quote:
Originally Posted by cidra View Post
Just asking: why can't i use HookEvent to prevent team changes while i can do that to prevent class changes?
The hook is fired AFTER the command has done it's job and switched the client's team.
__________________
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-28-2017 , 17:54   Re: Prevent class change in TF2
Reply With Quote #8

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).
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 21:34.


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