View Single Post
Whai
Senior Member
Join Date: Jul 2018
Old 11-13-2018 , 17:35   Re: [TF2] Put Merasmus on Gray Team
Reply With Quote #5

After some test of my plugin that I've created, my code should works :

Here is the code :

PHP Code:
#pragma semicolon 1

#define PLUGIN_VERSION "1.0.0"

#include <sourcemod>
#include <sdktools>
#include <tf2>
#include <tf2_stocks>

#pragma newdecls required

public Plugin myinfo 
{
    
name "[TEST] Grey Team",
    
author "Whai",
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_grey"Command_GreyADMFLAG_ROOT"Set grey team");
    
RegAdminCmd("sm_resetteam"Command_ResetTeamADMFLAG_ROOT"Set default team");
    
RegAdminCmd("sm_getspeccount"Command_GetSpecCountADMFLAG_ROOT); //This is for looking if the number of spectators updated
    
    
HookEvent("player_team"PlayerChangeTeam);
    
HookEvent("player_death"PlayerDeath);
}

float fOrigin[MAXPLAYERS+1][3], fAngles[MAXPLAYERS+1][3];

int iLastClientTeam[MAXPLAYERS+1];

bool bIsGreyTeam[MAXPLAYERS+1];

public 
void OnClientPutInServer(int iClient)
{
    
bIsGreyTeam[iClient] = false;
}

public 
void OnClientDisconnect(int iClient)
{
    
bIsGreyTeam[iClient] = false;
}

public 
Action PlayerChangeTeam(Event hEvent, const char[] cNamebool bDontBroadcast)
{
    
int iClient GetClientOfUserId(hEvent.GetInt("userid"));
    
    if(
bIsGreyTeam[iClient])
        
bIsGreyTeam[iClient] = false//Tell after changed team he is no longer in Grey Team
}

public 
Action PlayerDeath(Event hEvent, const char[] cNamebool bDontBroadcast)
{
    
int iClient GetClientOfUserId(hEvent.GetInt("userid"));
    
    if(
bIsGreyTeam[iClient])
    {
        
TF2_ChangeClientTeam(iClientview_as<TFTeam>(iLastClientTeam[iClient])); //After player died, change to him the team he was
        
bIsGreyTeam[iClient] = false//Tell after changed team he is no longer in Grey Team
    
}
}

public 
Action Command_Grey(int iClientint iArgs)
{
    if (!
iClient && !iArgs//!iClient = (iClient == 0); !iArgs = (iArgs == 0)
    
{
        
ReplyToCommand(iClient"[SM] Usage in console server: sm_grey <target>");
        return 
Plugin_Handled;
    }
    
    if(
iArgs 1)
    {
        
ReplyToCommand(iClient"[SM] Usage: sm_grey or sm_grey <target>");
        return 
Plugin_Handled;
    }
    
    if(!
iArgs)
    {
        if(!
bIsGreyTeam[iClient])    //We want to know if he is not already in grey team
        
{
            
iLastClientTeam[iClient] = GetEntProp(iClientProp_Send"m_iTeamNum"); //First we want to save his actual team

            
GetClientAbsOrigin(iClientfOrigin[iClient]);    //Get the actual location of him
            
GetClientEyeAngles(iClientfAngles[iClient]); //Get the actual angles of him
            
            
TF2_ChangeClientTeam(iClientTFTeam_Spectator); //Set to him Spectator team alias Grey Team
            
SetEntProp(iClientProp_Send"m_iTeamNum"0); //Set to him Unassigned team because it will choose random team, and because we want to make him respawning 
            
TF2_RespawnPlayer(iClient); //Respawn the player
            
TeleportEntity(iClientfOrigin[iClient], fAngles[iClient], NULL_VECTOR); //Teleport him where he was
            
SetEntProp(iClientProp_Send"m_iTeamNum"1); //Now set him to Spectator Team alias Grey Team
            
bIsGreyTeam[iClient] = true//Tell now he is on Grey Team

            //CreateTimer(0.1, ChangeTargetTeam, iClient);    //Removed because didn't know that doesn't need 0.1s
        
}
        else
        {
            
ReplyToCommand(iClient"[SM] You are already in grey team");
            return 
Plugin_Handled;
        }
    }
    
    if(
iArgs == 1)
    {
        
char arg1[MAX_NAME_LENGTH], target_name[MAX_TARGET_LENGTH];
        
int target_list[MAXPLAYERS], target_count;
        
bool tn_is_ml;

        
GetCmdArg(1arg1sizeof(arg1));

        if((
target_count ProcessTargetString(arg1iClienttarget_listMAXPLAYERSCOMMAND_FILTER_ALIVE COMMAND_FILTER_NO_MULTItarget_namesizeof(target_name), tn_is_ml)) <= 0)
        {
            
ReplyToTargetError(iClienttarget_count);
            return 
Plugin_Handled;
        }

        for(
int i 0target_counti++)
        {
            
int iTarget target_list[i];
            
            if(!
iTarget//if iTarget == 0
                
return Plugin_Handled;
                
            if(!
bIsGreyTeam[iTarget])
            {
                
iLastClientTeam[iTarget] = GetEntProp(iTargetProp_Send"m_iTeamNum");

                
GetClientAbsOrigin(iTargetfOrigin[iTarget]);
                
GetClientEyeAngles(iTargetfAngles[iTarget]);
                
TF2_ChangeClientTeam(iTargetTFTeam_Spectator);
                
SetEntProp(iTargetProp_Send"m_iTeamNum"0);
                
TF2_RespawnPlayer(iTarget);
                
TeleportEntity(iTargetfOrigin[iTarget], fAngles[iTarget], NULL_VECTOR);
                
SetEntProp(iTargetProp_Send"m_iTeamNum"1);
                
bIsGreyTeam[iTarget] = true;

                
//CreateTimer(0.1, ChangeTargetTeam, iTarget);
            
}
        }
    }
    return 
Plugin_Handled;
}

public 
Action Command_ResetTeam(int iClientint iArgs)
{
    if(!
iClient && !iArgs)
    {
        
ReplyToCommand(iClient"[SM] Usage in console server: sm_resetteam <target>");
        return 
Plugin_Handled;
    }
    
    if(
iArgs 1)
    {
        
ReplyToCommand(iClient"[SM] Usage: sm_resetteam or resetteam <target>");
        return 
Plugin_Handled;
    }
    
    if(!
iArgs)
    {
        if(
bIsGreyTeam[iClient])    //Check if he is atleast in Grey Team
        
{
            
GetClientAbsOrigin(iClientfOrigin[iClient]);    //get the current location of him
            
GetClientEyeAngles(iClientfAngles[iClient]);    //get the current location of him
            
            
TF2_ChangeClientTeam(iClientview_as<TFTeam>(iLastClientTeam[iClient])); //Change to him the team he was
            
TF2_RespawnPlayer(iClient); //Respawn him
            
TeleportEntity(iClientfOrigin[iClient], fAngles[iClient], NULL_VECTOR); //Teleport him where he was
            
bIsGreyTeam[iClient] = false//Tell that he is not in Grey Team
        
}
        else
        {
            
ReplyToCommand(iClient"[SM] You are already on your default team");
            return 
Plugin_Handled;
        }
    }
    
    if(
iArgs == 1)
    {
        
char arg1[MAX_NAME_LENGTH], target_name[MAX_TARGET_LENGTH];
        
int target_list[MAXPLAYERS], target_count;
        
bool tn_is_ml;

        
GetCmdArg(1arg1sizeof(arg1));

        if((
target_count ProcessTargetString(arg1iClienttarget_listMAXPLAYERSCOMMAND_FILTER_ALIVE COMMAND_FILTER_NO_MULTItarget_namesizeof(target_name), tn_is_ml)) <= 0)
        {
            
ReplyToTargetError(iClienttarget_count);
            return 
Plugin_Handled;
        }

        for(
int i 0target_counti++)
        {
            
int iTarget target_list[i];
            
            if(!
iTarget//if iTarget == 0
                
return Plugin_Handled;
                
            if(
bIsGreyTeam[iTarget])
            {
                
GetClientAbsOrigin(iTargetfOrigin[iTarget]);
                
GetClientEyeAngles(iTargetfAngles[iTarget]);

                
TF2_ChangeClientTeam(iTargetview_as<TFTeam>(iLastClientTeam[iTarget]));
                
TF2_RespawnPlayer(iTarget);
                
TeleportEntity(iTargetfOrigin[iTarget], fAngles[iTarget], NULL_VECTOR);
                
bIsGreyTeam[iTarget] = false;

            }
        }
    }
    
    return 
Plugin_Handled;
}

public 
Action Command_GetSpecCount(int iClientint iArgs)
{
    
int iHelp GetTeamPlayerCount(view_as<int>(TFTeam_Spectator));
    
    
PrintToChat(iClient"[SM] There is/are %i spectator(s)"iHelp);
    
    return 
Plugin_Handled;
}

stock int GetTeamPlayerCount(int iTeamNum = -1)
{
    
int iCounter;
    for(
int i 1<= MaxClientsi++)
        if(
IsValidClient(i) && !IsFakeClient(i) && (iTeamNum == -|| GetClientTeam(i) == iTeamNum))
            
iCounter++;
    return 
iCounter;
}

stock bool IsValidClient(int client)
{
    return (
<= client <= MaxClients) && IsClientInGame(client) && !IsFakeClient(client);
}

/*public Action ChangeTargetTeam(Handle timer, any target) ////Useless : no need a timer
{
    TF2_ChangeClientTeam(target, TFTeam_Spectator);
    SetEntProp(target, Prop_Send, "m_iTeamNum", 2);
    TF2_RespawnPlayer(target);
    TeleportEntity(target, fOrigin[target], fAngles[target], NULL_VECTOR);
    SetEntProp(target, Prop_Send, "m_iTeamNum", 1);
    bIsGreyTeam[target] = true;
}*/ 
or here is the .sp file

[EDIT]
I was wrong about unassinged team, it’s not the random team but a team when you didn’t choose any team (spec, blu or red)
Some info : while you are in unassigned team you have the red skin but you can still deal damage to everyone but in the scoreboard you will still be in your team (red or blu) so that’s better to choose spec instead of unassigned team

NOTE :

Add on "OnPluginStart()" :

Code:
	LoadTranslations("common.phrases");
Attached Files
File Type: sp Get Plugin or Get Source (NewScript.sp - 251 views - 7.4 KB)
__________________

Last edited by Whai; 11-14-2018 at 13:10.
Whai is offline