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

Solved Swap teams plugin without players dying?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Austin
Senior Member
Join Date: Oct 2005
Old 09-17-2021 , 19:14   Swap teams plugin without players dying?
Reply With Quote #1

EDIT:
Never mind!

As a software developer a good way to figure out some problem is to describe it to someone else. Often times you will find the solution while describing it.

There was no reason to hook into the player_team event when just creating a command to switch the teams and then do a mp_restartgame to reset the scores works good enough for what I need.

I updated the source with the working plugin that
auto selcts the team for connecting humans who are not the first human on the server and
there is a swapTeams commands that handles swapping and restarts the round.
All good.

--------------------------------------
I wrote a plugin that forces connecting humans to jon the same team as other humans on the server
and when a human player uses the choose team command to change teams
all the other humans are switched to the same team and
all bots switch teams.

It works (with other bugs listed below) but everyone dies when switched.

1) Is there a way to do the team switch so everyone switches teams without dying?
Switching teams this way causes the team score to increase and I am trying to avoid that.

The game engine will switch teams without the players dying if you are using these and you switch them and do a restart game but I am not using those settings.
mp_humanteam
bot_join_team
mp_restartgame 1

2) I am also forcing the team of humans connecting to be the same team as already in game humans.
That was working until I added the swap team feature. It looks like I need another check in the EventPlayerTeam to not switch humans that are -just connecting- and not already in game. How would I do that?

3) I have been wondering what the
bool dontBroadcast
parms is used for in these hooks?

Sort of working plugin with death and bugs with more than 1 human connecting:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma semicolon 1

//-----------------------------------------------------------------------------
public void OnPluginStart()
{
    
RegConsoleCmd("sm_st"Command_SwitchTeams);
    
HookEvent("player_connect_full"Event_PlayerConnectFull);
}

//-----------------------------------------------------------------------------
public void Event_PlayerConnectFull(Event event, const char[] namebool dontBroadcast)
{
    
int team GetHumanTeam();
    if (
team != CS_TEAM_NONE)
    {
        
int client GetClientOfUserId(event.GetInt("userid"));
        
// check if the client is valid and not assigned to a team yet
        
if (client && !GetClientTeam(client))
        {
            
ChangeClientTeam(clientteam);
        }
    }
}

//-----------------------------------------------------------------------------
public Action Command_SwitchTeams(int clientint args)
{
    
int newTeam;
    if (
GetClientTeam(client) == CS_TEAM_NONE)
        return 
Plugin_Continue;

    if (
GetClientTeam(client) == CS_TEAM_T)
        
newTeam CS_TEAM_CT;
    else
        
newTeam CS_TEAM_T;

    
PrintToServer("TEAMCHANGE user=%d"client);

    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
// set all humans to the team the human chose to change to
            
if (!IsFakeClient(i))
            {
                
ChangeClientTeam(inewTeam);
            }
            else
            {
                
// Swap the bots
                
if (GetClientTeam(i) == CS_TEAM_T)
                    
ChangeClientTeam(i,CS_TEAM_CT);
                else if (
GetClientTeam(i) == CS_TEAM_CT)
                    
ChangeClientTeam(i,CS_TEAM_T);
            }
        }
    }
    
ServerCommand("mp_restartgame 1");
    return 
Plugin_Continue;
}

//-----------------------------------------------------------------------------
public int GetHumanTeam()
{
    for (new 
client 1client <= MaxClientsclient++)
        if (
IsClientInGame(client) && !IsFakeClient(client))
            return 
GetClientTeam(client);
    return 
CS_TEAM_NONE;


Last edited by Austin; 09-17-2021 at 20:54.
Austin is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 09-17-2021 , 20:55   Re: Swap teams plugin without players dying?
Reply With Quote #2

Wow. That was quick. I was going to say that there is a TF2 plugin that allows players to instantly change teams without having to respawn. It's called 'Instantly Change Team'.

Here's a link: https://forums.alliedmods.net/showthread.php?t=329416
PC Gamer 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 17:38.


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