View Single Post
joao7yt
Senior Member
Join Date: Nov 2014
Location: Brazil
Old 11-13-2017 , 09:38   Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
Reply With Quote #23

Quote:
Originally Posted by Byte View Post
This post ended up helping me do something.
This is kinda crappy but...I hook the VGUIMenu, if its the first appearance, I move the client to spectator to get rid of the menu, then I show a new team menu one 0.1 seconds later.

The difference is the new menu doesn't have the countdown of mp_force_pick_time seconds. Also I want people to see the menu just without a countdown.

Some questions:
  • Is there a better way to block the first occurance of the usermessage?
  • Is there a way to handle which team a user joins normally if mp_force_pick_time reaches 0
  • Yes I know I could have just set mp_force_pick_time to a really high value

PHP Code:
public Action UserMessage_VGUIMenu(UserMsg msg_idProtobuf msg, const int[] playersint playersNumbool reliablebool init)
{
  
char buffermsg[64];
  
  
PbReadString(msg"name"buffermsgsizeof(buffermsg));
  
  if (
StrEqual(buffermsg"team"true)) {
    
int client players[0];
    
    if (
g_IsFirstTeamSelection[client]) {
      
g_IsFirstTeamSelection[client] = false;
      
RequestFrame(UserMessage_VGUIMenu_NextFrameclient);
    }
  }
  
  return 
Plugin_Continue;
}

void UserMessage_VGUIMenu_NextFrame(int client)
{
  if (
IsClientInGame(client)) {
    
//Change client team to spectator to remove VGUIMenu
    
ChangeClientTeam(clientCS_TEAM_SPECTATOR);
    
CreateTimer(0.1Timer_ShowTeamMenuclient);
  }
}

public 
void OnClientConnected(int client)
{
  
g_IsFirstTeamSelection[client] = true;
}

public 
Action Timer_ShowTeamMenu(Handle Timerint client)
{
  if (
IsClientInGame(client))
    
UTIL_TeamMenu(client);
}

// This helper procedure will re-display the team join menu
// and is equivalent to what ClientCommand(client, "chooseteam") did in the past
void UTIL_TeamMenu(int client)
{
    
int clients[1];
    
Handle bf;
    
clients[0] = client;
    
bf StartMessage("VGUIMenu"clients1);
    
    if (
GetUserMessageType() == UM_Protobuf) {
        
PbSetString(bf"name""team");
        
PbSetBool(bf"show"true);
    }
    else {
        
BfWriteString(bf"team"); // panel name
        
BfWriteByte(bf1); // bShow
        
BfWriteByte(bf0); // count
    
}
    
    
EndMessage();

  • You can suppress the team menu from showing when the player connects using sv_disable_show_team_select_menu 1. but that will disable it and people won't be able to press M. idk if you can force it showing using "PbSetBool(bf, "show", true);" tho...
  • You can use mp_force_assign_teams, but if you need to hook it and actually choose it, you need to see if some usermessage is called when the teammenu countdown ends, if so, just hook it. Use the follwing and watch your console.

PHP Code:
#pragma semicolon 1
#include <sourcemod>

public void OnPluginStart()
{
    
HookUserMessage(GetUserMessageId("VGUIMenu"), TeamMenuHooktrue);
}

public 
Action TeamMenuHook(UserMsg msg_idProtobuf msg, const int[] playersint playersNumbool reliablebool init)
{
    
char buffermsg[64];
    
    
PbReadString(msg"name"buffermsgsizeof(buffermsg));
     
    
PrintToServer("%s"buffermsg);
    
    return 
Plugin_Continue;

joao7yt is offline