AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [CS:GO] Final and fancy solution for putting a player in a team on connect (https://forums.alliedmods.net/showthread.php?t=300549)

joao7yt 08-20-2017 22:00

[CS:GO] Final and fancy solution for putting a player in a team on connect
 
As the Panorama doesn't have a Continue Screen, it's now possible to use the "player_connect_full" HookEvent:

PHP Code:

public void OnPluginStart()
{
    
HookEvent("player_connect_full"Event_PlayerConnectFull);
}

public 
Action Event_PlayerConnectFull(Handle event, const char[] namebool dontBroadcast)
{
    
RequestFrame(SetClientTeamGetEventInt(event"userid"));
}

public 
void SetClientTeam(int userid)
{
    
int client GetClientOfUserId(userid);
    
    
//Do stuff here
    //Now you can check if the client is valid and then put it in a team using CS_SwitchTeam or ChangeClientTeam.


Scaleform legacy:
Spoiler

th7nder 08-22-2017 05:37

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Finally! Thank you very much <3

joao7yt 08-22-2017 05:52

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by th7nder (Post 2543519)
Finally! Thank you very much <3

Yw, hope everyone with plugins that put players into a team on join see this, this will make everyone's life easier.

th7nder 08-22-2017 07:51

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
This plugins has one bug, it returns Plugin_Handled on every VGUI, you should return Plugin_Handled only if this is VGUI for teams, but overall idea is the best! <3

joao7yt 08-22-2017 07:59

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by th7nder (Post 2543544)
This plugins has one bug, it returns Plugin_Handled on every VGUI, you should return Plugin_Handled only if this is VGUI for teams, but overall idea is the best! <3

You are right, fixed

joao7yt 08-22-2017 16:09

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Note: for some reason "return Plugin_Handled;" is necessary after doing a "ChangeClientTeam", otherwise the server crashes. I'm saying it because I tried doing "PbSetBool(msg, "show", false);" (which will make the team menu to not show) and then "return Plugin_Continue;", because idk if simply doing "return Plugin_Handled;" would lead to a future bug, but seems it's not possible to call "return Plugin_Continue;" after changing the client's team without crashing the server.

asherkin 08-24-2017 08:56

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Your PbSetBool would have been throwing an error (because usermessages can't be modified from a usermessage hook) and aborting the call, which would cause later usermessage creation to become unbalanced, which caused the "crash" (it wasn't a crash in the normal sense, the server threw a fatal error).

joao7yt 08-24-2017 09:04

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by asherkin (Post 2544023)
Your PbSetBool would have been throwing an error (because usermessages can't be modified from a usermessage hook) and aborting the call, which would cause later usermessage creation to become unbalanced, which caused the "crash" (it wasn't a crash in the normal sense, the server threw a fatal error).

I didn't get it. Is changing the client's team changing the UserMessenge? If so, why when returning Continue cause the Error but returning Handled doesn't?

joao7yt 09-05-2017 19:05

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Guys, I might have found a bug related to it: if you change the client's team inside that hook, it could rarely throw a fatal error and crash the srcds.exe. I did a few tests and it might have gone if you create a timer to change the client's team, which is not a problem since we will still be able to hook when the team menu shows, it will only put the client in a team a bit later. I put 0.1 seconds in my timer and got no crashes. So be warned, guys.

Neuro Toxin 09-06-2017 03:02

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
I hook on player spawn.

The first occurrence is from client connecting. The second occurrence u can change the team and cs_respawn the client.

A better way is to listen to the jointeam command. Wait a frame and then set your team.

joao7yt 09-06-2017 04:37

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Neuro Toxin (Post 2546974)
I hook on player spawn.

The first occurrence is from client connecting. The second occurrence u can change the team and cs_respawn the client.

A better way is to listen to the jointeam command. Wait a frame and then set your team.

Well, then you need the player to select a team, which is not "fancy". My way it's exactly like valve does on their servers. And also if a player joins spec, you don't have player spawn to hook. And also if you do want to have the team menu disabled in your server, you wouldn't be able, since you require the client to spawn or do jointeam.

Neuro Toxin 09-06-2017 17:04

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Spawn calls for spec.

If you dont want a team menu. Wait a frame from the first spawn call during join and set your team and cs respawn if you want to.

joao7yt 09-06-2017 17:12

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Neuro Toxin (Post 2547168)
Spawn calls for spec.

If you dont want a team menu. Wait a frame from the first spawn call during join and set your team and cs respawn if you want to.

Then 2 of the 3 problems I mentioned with your method remains: it requires the player to actually select a team, clicking it in the menu (which I think unnecessary since my method bypasses it), and if you want to disable the team menu with "sv_disable_show_team_select_menu 1", you won't be able.

Neuro Toxin 09-06-2017 17:47

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Just set show to false in the VGUIMenu hook if sv_disable_show_team_select_menu doesn't work for you.

The team menu is distributed on the first spawn call. So wait a frame and then set your team.

joao7yt 09-06-2017 17:56

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Neuro Toxin (Post 2547175)
Just set show to false in the VGUIMenu hook if sv_disable_show_team_select_menu doesn't work for you.

The team menu is distributed on the first spawn call. So wait a frame and then set your team.

Oh, wait, the spawn you are saying is when the player connects? If so, I was doing it before, but as I said, if you change the client's with the "Continue" screen opened, it will bug the client, he won't be able to use the team menu to change team... I mean, if you already don't want the client to change team, it's ok, but in my case I want to let them to go to spec (then I set them as a coach for the team he was), and let coaches join to play on the team he's coaching... anyway, what I mean is that changing the client's team too soon (more specifically with the "Continue" screen opned) it will bug the team menu for that client.

Neuro Toxin 09-06-2017 18:06

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
On connect set a flag to set show to false in the vgui to block the team menu.

On first spawn use request frame and set the team in the callback.

On first team vgui set show to false and clear your flag.

joao7yt 09-06-2017 18:14

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Neuro Toxin (Post 2547183)
On connect set a flag to set show to false in the vgui to block the team menu.

On first spawn use request frame and set the team in the callback.

On first team vgui set show to false and clear your flag.

I don't see why set team vgui to false... what i'm saying is that the team menu gets unusable if you set the client's team with this screen opened, and I think your method will do exactly that, won't it? Because I think the player spawn callback is called right after the client finishes loading the map, where this screen appears... don't it?

If so, just try to change team after being spawned. You won't be able to use the menu.

Neuro Toxin 09-06-2017 18:26

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
The order will be.

OnSpawn > Request Frame
VGUI > hide
Set Team after VGUI is hidden

You are right. If u play with teams during the vgui you're screwed after an update a while back.

I wrote a whole thread on this then made the motd changer plugin.

joao7yt 09-06-2017 18:30

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Neuro Toxin (Post 2547186)
The order will be.

OnSpawn > Request Frame
VGUI > hide
Set Team after VGUI is hidden

Ok
Which spawn is that? the client full connected? or the client being spawned in a team?
Which vgui? The vgui which shows the "Continue" screen? because I think there's no vgui for that screen. Because I said, using ChangeClientTeam with that screen being showed, will bug the team menu...

Why don't you simply post the code here lol

Neuro Toxin 09-06-2017 18:33

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
The spawn is the very first one from connect.

It's been a while since the update that fucked with this stuff.

Im pretty sure if you block the team menu the continue screen doesn't show.

joao7yt 09-06-2017 18:39

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Neuro Toxin (Post 2547190)
The spawn is the very first one from connect.

It's been a while since the update that fucked with this stuff.

Im pretty sure if you block the team menu the continue screen doesn't show.

No, the continue screen always show, there's no way to hide/close it. That being said and you agreeding with me that you can't change the client's team with that screen being showed because it will bug the team menu for that client, the way to hook when that screen is gone is hooking when "team" vguimenu appears. And it's what my code does.

You could "bypass" the bugs by adding a timer to put the client in a team when the "Continue" screen (this one) was gone, but if the player minimize the game, the "Continue" screen is paused, making the timer useless, since it would trigger "ChangeClientTeam" with the "Continue" screen being showed.

Byte 11-13-2017 09:14

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
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();



joao7yt 11-13-2017 09:38

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Byte (Post 2560209)
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;



pride95 03-08-2018 05:49

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
For CS:GO:

mp_force_pick_time 0
mp_force_assign_teams 0

HookEvent: player_connect_full, then requestframe changeclientteam.

This works without any bugs (like buying weapons). This is for people which don't want to use vguimenu.

joao7yt 03-08-2018 06:38

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by pride95 (Post 2581908)
For CS:GO:

mp_force_pick_time 0
mp_force_assign_teams 0

HookEvent: player_connect_full, then requestframe changeclientteam.

This works without any bugs (like buying weapons). This is for people which don't want to use vguimenu.

This can work for auto sorting the players evenly, but can’t be used if you need to put a specific player, like using his steamid, in a specific team.

pride95 03-08-2018 07:36

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by joao7yt (Post 2581910)
This can work for auto sorting the players evenly, but can’t be used if you need to put a specific player, like using his steamid, in a specific team.

why not?
GetClientAuthId works in player_connect_full. then you check the steamid and use ChangeClientTeam.

joao7yt 03-08-2018 11:44

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by pride95 (Post 2581919)
why not?
GetClientAuthId works in player_connect_full. then you check the steamid and use ChangeClientTeam.

There’s a 5 seconds countdown before you are assigned to a team. If you do a ChangeClientTeam before that countdown ends, it will bug the buy menu and etc... and no, it’s not possible to just create a timer because if you minimize the game while the countdown is running, the countdown pauses...

pride95 03-08-2018 11:51

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by joao7yt (Post 2581944)
There’s a 5 seconds countdown before you are assigned to a team. If you do a ChangeClientTeam before that countdown ends, it will bug the buy menu and etc... and no, it’s not possible to just create a timer because if you minimize the game while the countdown is running, the countdown pauses...

Quote:

Originally Posted by pride95 (Post 2581908)
For CS:GO:

mp_force_pick_time 0
mp_force_assign_teams 0

HookEvent: player_connect_full, then requestframe changeclientteam.

This works without any bugs (like buying weapons). This is for people which don't want to use vguimenu.

read the bold text. this is tested. don't speak if you didn't tested my way. with mp_force_assign_teams that countdown doesn't exist so the bug with buymenu doesn't exist as well.

joao7yt 03-08-2018 12:04

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by pride95 (Post 2581947)
read the bold text. this is tested. don't speak if you didn't tested my way. with mp_force_assign_teams that countdown doesn't exist so the bug with buymenu doesn't exist as well.

If the countdown doesn’t exists, it should work. i’m not on my computer, as you didn’t mentioned that the countdown doesn’t even appear, I just speculated that that wouldn’t work

Sipro 03-22-2018 14:13

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
It is working for CS:S?

joao7yt 03-22-2018 14:14

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Sipro (Post 2584194)
It is working for CS:S?

I don’t really know... maybe

OSWO 03-24-2018 22:38

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Why dont you use RequestFrame instead of 0.1 timers (:

joao7yt 03-25-2018 02:13

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by OSWO (Post 2584525)
Why dont you use RequestFrame instead of 0.1 timers (:

Didn’t try it yet. Do you know if that works?

Papero 04-05-2018 15:56

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Yeah it works

joao7yt 04-05-2018 16:23

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Papero (Post 2586223)
Yeah it works

Nice, I updated the post.

Papero 06-01-2018 15:53

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
If someone is interested using this way you can put a player on a team on connect(without showing the teammenu) and prevent its change.

PHP Code:

public void OnPluginStart()
{
    
HookUserMessage(GetUserMessageId("VGUIMenu"), TeamMenuHooktrue);
    
    
//Team Hooks
    
AddCommandListener(Cmd_JoinTeam"jointeam");
    
AddCommandListener(Cmd_JoinTeam"spectate");
}

public 
Action Cmd_JoinTeam(int client, const char[] commandint args)
{
    
//Prevent team change
    
return Plugin_Stop;
}

public 
Action TeamMenuHook(UserMsg msg_idProtobuf msg, const int[] playersint playersNumbool reliablebool init)
{
    
char buffermsg[64];
    
    
msg.ReadString("name"buffermsgsizeof(buffermsg)); //Use methodmaps
    
if (StrEqual(buffermsg"team"true))
    {
        
int client players[0];
        
        
RequestFrame(Frame_SetTeamGetClientUserId(client));
        return 
Plugin_Stop//Don't show the teammenu
    
}
    
    return 
Plugin_Continue;
}  

public 
void Frame_SetTeam(any userid)
{
    
int client GetClientOfUserId(userid);
    if (!
client)
        return;
        
    
ChangeClientTeam(clientCS_TEAM_CT); //Change team



joao7yt 06-01-2018 15:58

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Papero (Post 2594864)
If someone is interested using this way you can put a player on a team on connect(without showing the teammenu) and prevent its change.

PHP Code:

public void OnPluginStart()
{
    
HookUserMessage(GetUserMessageId("VGUIMenu"), TeamMenuHooktrue);
    
    
//Team Hooks
    
AddCommandListener(Cmd_JoinTeam"jointeam");
    
AddCommandListener(Cmd_JoinTeam"spectate");
}

public 
Action Cmd_JoinTeam(int client, const char[] commandint args)
{
    
//Prevent team change
    
return Plugin_Stop;
}

public 
Action TeamMenuHook(UserMsg msg_idProtobuf msg, const int[] playersint playersNumbool reliablebool init)
{
    
char buffermsg[64];
    
    
msg.ReadString("name"buffermsgsizeof(buffermsg)); //Use methodmaps
    
if (StrEqual(buffermsg"team"true))
    {
        
int client players[0];
        
        
RequestFrame(Frame_SetTeamGetClientUserId(client));
        return 
Plugin_Stop//Don't show the teammenu
    
}
    
    return 
Plugin_Continue;
}  

public 
void Frame_SetTeam(any userid)
{
    
int client GetClientOfUserId(userid);
    if (!
client)
        return;
        
    
ChangeClientTeam(clientCS_TEAM_CT); //Change team



That’s exactly what I said on the original post -.-

Papero 06-01-2018 16:15

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by joao7yt (Post 2594866)
That’s exactly what I said on the original post -.-

I've just pointed out that they can use
Code:

Plugin_Stop
to stop the displaying and the listener to block the team change... :oops:

joao7yt 06-01-2018 16:21

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by Papero (Post 2594867)
I've just pointed out that they can use
Code:

Plugin_Stop
to stop the displaying and the listener to block the team change... :oops:

Oh, right... So, it’s been a long time since I posted it, but if I’m not mistaken, when I was messing with it back then, I tried Plugin_Stop and it cause some issue, I don’t remember if it crashed the server or something like that. But if you tried it and it didn’t, they must’ve changed something that fixed it. I will run some tests when I can to be sure it’s not causing any bugs...

Papero 06-01-2018 16:41

Re: [CS:GO] Final and fancy solution for putting a player in a team on connect
 
Quote:

Originally Posted by joao7yt (Post 2594868)
Oh, right... So, it’s been a long time since I posted it, but if I’m not mistaken, when I was messing with it back then, I tried Plugin_Stop and it cause some issue, I don’t remember if it crashed the server or something like that. But if you tried it and it didn’t, they must’ve changed something that fixed it. I will run some tests when I can to be sure it’s not causing any bugs...

On my test server it didn't caused any issue, I was alone but I don't think it matters.


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

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