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

Team Join Hook/Event


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Michael Shoe Maker
Senior Member
Join Date: Apr 2016
Old 05-23-2016 , 15:49   Team Join Hook/Event
Reply With Quote #1

I'm using
PHP Code:
AddCommandListener(Listener_JoinTeam"jointeam"
to check if a team is joinable under certain conditions, however If the team is full as a result of a ratio I have to change the player back to their original team and this spams the chat a bit. Is there an event that handles team join so that you can stop the event and prevent any team changes?

If you don't know what i mean:
PHP Code:
public Action Listener_JoinTeam(int client, const char[] commandint args)
{
    if(
GetConVarInt(g_bcRatioEnabled))
    {
        
char sArg1[3];
        
GetCmdArg(1sArg1sizeof(sArg1));
        
int iArg1 StringToInt(sArg1);
        
        
int iTeamCountT GetTeamClientCount(2);
        
int iTeamCountCT GetTeamClientCount(3);
        
        if(
iArg1 == 3)
        {
            if((
iTeamCountT GetConVarInt(g_bcRatio)) > iTeamCountCT//ratio = 3
            
{
                
CPrintToChat(client"Joined");
            } else {
                
CPrintToChat(client"Full");
                
ChangeClientTeam(client2);
            }
        }
    }


Last edited by Michael Shoe Maker; 05-23-2016 at 15:49.
Michael Shoe Maker is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 05-23-2016 , 16:15   Re: Team Join Hook/Event
Reply With Quote #2

maybe use EventHook

https://wiki.alliedmods.net/Generic_...ts#player_team

PHP Code:
public void OnPluginStart()
{
    
HookEvent("player_team"EventPlayerTeam);
}

public 
Action EventPlayerTeam(Event event, const char[] namebool dontBroadcast)
{
    
// do stuff

__________________
coding & free software

Last edited by shanapu; 05-23-2016 at 16:16.
shanapu is offline
Michael Shoe Maker
Senior Member
Join Date: Apr 2016
Old 05-23-2016 , 16:54   Re: Team Join Hook/Event
Reply With Quote #3

Quote:
Originally Posted by shanapu View Post
maybe use EventHook

https://wiki.alliedmods.net/Generic_...ts#player_team

PHP Code:
public void OnPluginStart()
{
    
HookEvent("player_team"EventPlayerTeam);
}

public 
Action EventPlayerTeam(Event event, const char[] namebool dontBroadcast)
{
    
// do stuff

I'm on CS:GO, and this still prints the "join team message".
Michael Shoe Maker is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 05-23-2016 , 18:05   Re: Team Join Hook/Event
Reply With Quote #4

return Plugin_Handled;
__________________
Chaosxk is offline
sdz
Senior Member
Join Date: Feb 2012
Old 05-24-2016 , 09:27   Re: Team Join Hook/Event
Reply With Quote #5

This is from my own personal RP mod. I use this.


Returning Plugin_Handled will stop the printing.
PHP Code:
public Action:altJoin(Client, const String:command[], argc)
{
    if(!
IsClientInGame(Client) || argc 1
    {
        return 
Plugin_Handled;
    }
 
    
decl String:arg[8];
    
GetCmdArg(1argsizeof(arg));
    new 
teamJoin StringToInt(arg);
    new 
teamLeave GetClientTeam(Client);
 
    if(
teamLeave == teamJoin || IsFakeClient(Client))
    {
        return 
Plugin_Continue;
    } 
    else 
    {
        
// ignore switches between T/CT team
        
if((teamLeave == CS_TEAM_CT && teamJoin == CS_TEAM_T)
        || (
teamLeave == CS_TEAM_T  && teamJoin == CS_TEAM_CT))
        {
            return 
Plugin_Handled;
        }
    }
    return 
Plugin_Handled;


Last edited by sdz; 05-24-2016 at 09:28.
sdz is offline
Michael Shoe Maker
Senior Member
Join Date: Apr 2016
Old 05-24-2016 , 09:34   Re: Team Join Hook/Event
Reply With Quote #6

PHP Code:
public Action Event_TeamJoin(Event eventchar[] namebool dontBroadcast)
{
    if(
GetConVarInt(g_bcRatioEnabled))
    {
        
int client GetClientOfUserId(GetEventInt(event"userid"));
        
int newTeam GetEventInt(event"team");
        
        
int iTeamCountT GetTeamClientCount(2);
        
int iTeamCountCT GetTeamClientCount(3);
        
        if(
newTeam == 3)
        {
            if((
iTeamCountT GetConVarInt(g_bcRatio)) < iTeamCountCT)
            {
                
CPrintToChat(client"The counter-terroist team is full.");
                return 
Plugin_Handled;
            }
        }
    }
    return 
Plugin_Continue;

I tried this but it fails to prevent join message and still allows me to join CT. My little message does print though.

Last edited by Michael Shoe Maker; 05-24-2016 at 09:47.
Michael Shoe Maker is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 05-24-2016 , 13:31   Re: Team Join Hook/Event
Reply With Quote #7

Events are just notifications. You can block the notification with "Plugin_Handled" but you can't actually block the event.

What you can do is keep the event to block the chat messages AND AddCommandListener to "jointeam" and return "Plugin_Handled" to block them from switching teams.
__________________

Last edited by Chaosxk; 05-24-2016 at 13:35.
Chaosxk is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 05-24-2016 , 22:49   Re: Team Join Hook/Event
Reply With Quote #8

Quote:
Originally Posted by Michael Shoe Maker View Post
I'm using
PHP Code:
AddCommandListener(Listener_JoinTeam"jointeam"
to check if a team is joinable under certain conditions, however If the team is full as a result of a ratio I have to change the player back to their original team and this spams the chat a bit. Is there an event that handles team join so that you can stop the event and prevent any team changes?
Use what you already had, and hook player_team side by side with it, e.g.:

Code:
public void OnPluginStart()
{
    AddCommandListener(Listener_JoinTeam, "jointeam");
    HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre);
}

public Action Event_PlayerTeam(Event event, const char[] name, bool:dontBroadcast) 
{
    if(GetConVarInt(g_bcRatioEnabled))
    {
        SetEventBroadcast(event, true);
    }
    return Plugin_Continue;
}

public Action Listener_JoinTeam(int client, const char[] command, int args)
{
    if(GetConVarInt(g_bcRatioEnabled))
    {
        char sArg1[3];
        GetCmdArg(1, sArg1, sizeof(sArg1));
        int iArg1 = StringToInt(sArg1);
        
        int iTeamCountT = GetTeamClientCount(2);
        int iTeamCountCT = GetTeamClientCount(3);
        
        if(iArg1 == 3)
        {
            if((iTeamCountT / GetConVarInt(g_bcRatio)) > iTeamCountCT) //ratio = 3
            {
                CPrintToChat(client, "Joined");
            } else {
                CPrintToChat(client, "Full");
                ChangeClientTeam(client, 2);
            }
        }
    }
}
The "simplified" version of the player_team event would be like this:

Code:
public Action Event_PlayerTeam(Event event, const char[] name, bool:dontBroadcast) 
{
    SetEventBroadcast(event, true);
    return Plugin_Continue;
}
I have just included your if () {}, to check whether or not your plugin is currently enabled.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
Michael Shoe Maker
Senior Member
Join Date: Apr 2016
Old 05-26-2016 , 12:02   Re: Team Join Hook/Event
Reply With Quote #9

Quote:
Originally Posted by arne1288 View Post
Use what you already had, and hook player_team side by side with it, e.g.:

Code:
public void OnPluginStart()
{
    AddCommandListener(Listener_JoinTeam, "jointeam");
    HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre);
}

public Action Event_PlayerTeam(Event event, const char[] name, bool:dontBroadcast) 
{
    if(GetConVarInt(g_bcRatioEnabled))
    {
        SetEventBroadcast(event, true);
    }
    return Plugin_Continue;
}

public Action Listener_JoinTeam(int client, const char[] command, int args)
{
    if(GetConVarInt(g_bcRatioEnabled))
    {
        char sArg1[3];
        GetCmdArg(1, sArg1, sizeof(sArg1));
        int iArg1 = StringToInt(sArg1);
        
        int iTeamCountT = GetTeamClientCount(2);
        int iTeamCountCT = GetTeamClientCount(3);
        
        if(iArg1 == 3)
        {
            if((iTeamCountT / GetConVarInt(g_bcRatio)) > iTeamCountCT) //ratio = 3
            {
                CPrintToChat(client, "Joined");
            } else {
                CPrintToChat(client, "Full");
                ChangeClientTeam(client, 2);
            }
        }
    }
}
The "simplified" version of the player_team event would be like this:

Code:
public Action Event_PlayerTeam(Event event, const char[] name, bool:dontBroadcast) 
{
    SetEventBroadcast(event, true);
    return Plugin_Continue;
}
I have just included your if () {}, to check whether or not your plugin is currently enabled.
Thanks a lot mate, there's one problem still. Here's what I have at the moment:
PHP Code:
public Action Event_PlayerTeam(Event event, const char[] namebool:dontBroadcast
{
    if(
GetConVarInt(g_bcRatioEnabled))
    {
        
int iTeamCountT GetTeamClientCount(2);
        
int iTeamCountCT GetTeamClientCount(3);

        if(
iTeamCountT GetConVarInt(g_bcRatio) < iTeamCountCT)
        {
            
SetEventBroadcast(eventtrue);
        }
    }
    return 
Plugin_Continue;
}

public 
Action Listener_JoinTeam(int client, const char[] commandint args)
{
    if(
GetConVarInt(g_bcRatioEnabled))
    {
        
char sArg1[3];
        
GetCmdArg(1sArg1sizeof(sArg1));
        
int iArg1 StringToInt(sArg1);

        
int iTeamCountT GetTeamClientCount(2);
        
int iTeamCountCT GetTeamClientCount(3);

        if(
iArg1 == 3)
        {
            if(
iTeamCountT GetConVarInt(g_bcRatio) < iTeamCountCT)
            {
                
CPrintToChat(client"Full");
                
ChangeClientTeam(client2);
            }
        }
    }

All the checks work and I get the "Full" message when the team is full. However when I change to CT I die and switch to it anyway.
Michael Shoe Maker 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 14:00.


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