Senior Member
Join Date: Nov 2014
Location: Brazil
|
11-13-2017
, 09:38
Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
|
#23
|
Quote:
Originally Posted by Byte
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_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init)
{
char buffermsg[64];
PbReadString(msg, "name", buffermsg, sizeof(buffermsg));
if (StrEqual(buffermsg, "team", true)) {
int client = players[0];
if (g_IsFirstTeamSelection[client]) {
g_IsFirstTeamSelection[client] = false;
RequestFrame(UserMessage_VGUIMenu_NextFrame, client);
}
}
return Plugin_Continue;
}
void UserMessage_VGUIMenu_NextFrame(int client)
{
if (IsClientInGame(client)) {
//Change client team to spectator to remove VGUIMenu
ChangeClientTeam(client, CS_TEAM_SPECTATOR);
CreateTimer(0.1, Timer_ShowTeamMenu, client);
}
}
public void OnClientConnected(int client)
{
g_IsFirstTeamSelection[client] = true;
}
public Action Timer_ShowTeamMenu(Handle Timer, int 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", clients, 1);
if (GetUserMessageType() == UM_Protobuf) {
PbSetString(bf, "name", "team");
PbSetBool(bf, "show", true);
}
else {
BfWriteString(bf, "team"); // panel name
BfWriteByte(bf, 1); // bShow
BfWriteByte(bf, 0); // 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"), TeamMenuHook, true);
}
public Action TeamMenuHook(UserMsg msg_id, Protobuf msg, const int[] players, int playersNum, bool reliable, bool init)
{
char buffermsg[64];
PbReadString(msg, "name", buffermsg, sizeof(buffermsg));
PrintToServer("%s", buffermsg);
return Plugin_Continue;
}
|
|