View Single Post
Ren3gade
Senior Member
Join Date: Jul 2010
Old 08-18-2013 , 19:24   Re: CS:GO Force Team Join on Connect
Reply With Quote #11

Quote:
Originally Posted by thetwistedpanda View Post
This is the result of god knows how many hours of testing (~20?) and head banging attempting to get the desired results for my private idle manager / drop detector plugin. This specific paste wasn't tested, but it's a copy/paste of the important parts of my plugin, which works as desired, so this should work too as long as I didn't derp somewhere.

This prevents the first team selection menu from appearing, and if a new match occurs (without team change), somehow manages to automatically close the team selection panel (this was an accidental side effect). I can't attest to how this works in normal game play though, as my goal was for Idle/Achievement servers. If it works for you, feel free to support my booze fund in my signature, as after this headache I could definitely use a few bottles . *quietly weeps at the loss of potential sales from posting this*

PHP Code:
#include <cstrike>
#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
    
HookEvent("player_connect_full"Event_OnFullConnectEventHookMode_Pre);
    
HookEvent("cs_match_end_restart"Event_OnMatchRestartEventHookMode_Pre);
    
HookEvent("player_team"Event_OnPlayerTeamEventHookMode_Pre);
    
AddCommandListener(Command_Join"jointeam");
}

public 
Action:Event_OnFullConnect(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if(!
client || !IsClientInGame(client))
        return 
Plugin_Continue;

    new 
iRediBlue;
    for(new 
1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i))
            continue;

        new 
iTeam GetClientTeam(i);
        if(
iTeam == CS_TEAM_T)
            
iRed++;
        else if(
iTeam == CS_TEAM_CT)
            
iBlue++;
    }

    if(
iRed iBlue)
        
SetEntProp(clientProp_Send"m_iTeamNum"CS_TEAM_T);
    else
        
SetEntProp(clientProp_Send"m_iTeamNum"CS_TEAM_CT);

    
ForcePlayerSuicide(client);
    
CS_RespawnPlayer(client);
    return 
Plugin_Continue;
}

public 
Action:Event_OnMatchRestart(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
iRediBlueiJoin;
    for(new 
1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i))
            continue;

        switch(
GetClientTeam(i))
        {
            case 
CS_TEAM_T:
                
iRed++;
            case 
CS_TEAM_CT:
                
iBlue++;
        }
    }

    for(new 
1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i))
            continue;

        if(
iRed iBlue)
            
iJoin CS_TEAM_T;
        else if(
iBlue iRed)
            
iJoin CS_TEAM_CT;
        else
            
iJoin GetRandomInt(CS_TEAM_TCS_TEAM_CT);

        switch(
iJoin)
        {
            case 
CS_TEAM_T:
                
iRed++;
            case 
CS_TEAM_CT:
                
iBlue++;
        }

        
ChangeClientTeam(iiJoin);
    }
}

public 
Action:Event_OnPlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if(!
client || !IsClientInGame(client))
        return 
Plugin_Continue;

    if(!
IsPlayerAlive(client))
        
CreateTimer(0.1Timer_RespawnGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
    return 
Plugin_Continue;
}

public 
Action:Timer_Respawn(Handle:timerany:userid)
{
    new 
client GetClientOfUserId(userid);
    if(!
client)
        return 
Plugin_Continue;

    new 
iTeam GetClientTeam(client);
    if(
iTeam <= CS_TEAM_SPECTATOR)
        return 
Plugin_Continue;

    if(
IsPlayerAlive(client))
        return 
Plugin_Continue;

    
CS_RespawnPlayer(client);

    return 
Plugin_Continue;
}

public 
Action:Command_Join(client, const String:command[], argc)
{
    
decl String:sJoining[8];
    
GetCmdArg(1sJoiningsizeof(sJoining));
    new 
iJoining StringToInt(sJoining);
    if(
iJoining == CS_TEAM_SPECTATOR)
        return 
Plugin_Continue;

    new 
iTeam GetClientTeam(client);
    if(
iJoining == iTeam)
        return 
Plugin_Handled;
    else
    {
        
SetEntProp(clientProp_Send"m_iTeamNum"iJoining);
        
ForcePlayerSuicide(client);
        
CS_RespawnPlayer(client);
    }

    return 
Plugin_Continue;


Thank you very much for this. I tested it and it forces players onto a team, which is great. But when I used it, it made it so the round wouldnt end? When all the Ts were dead, it didnt end. and when the round time ran out, it still didnt end the round and start a new one?
Ren3gade is offline