Senior Member
|
11-13-2018
, 17:35
Re: [TF2] Put Merasmus on Gray Team
|
#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_Grey, ADMFLAG_ROOT, "Set grey team"); RegAdminCmd("sm_resetteam", Command_ResetTeam, ADMFLAG_ROOT, "Set default team"); RegAdminCmd("sm_getspeccount", Command_GetSpecCount, ADMFLAG_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[] cName, bool 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[] cName, bool bDontBroadcast) { int iClient = GetClientOfUserId(hEvent.GetInt("userid")); if(bIsGreyTeam[iClient]) { TF2_ChangeClientTeam(iClient, view_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 iClient, int 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(iClient, Prop_Send, "m_iTeamNum"); //First we want to save his actual team
GetClientAbsOrigin(iClient, fOrigin[iClient]); //Get the actual location of him GetClientEyeAngles(iClient, fAngles[iClient]); //Get the actual angles of him TF2_ChangeClientTeam(iClient, TFTeam_Spectator); //Set to him Spectator team alias Grey Team SetEntProp(iClient, Prop_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(iClient, fOrigin[iClient], fAngles[iClient], NULL_VECTOR); //Teleport him where he was SetEntProp(iClient, Prop_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(1, arg1, sizeof(arg1));
if((target_count = ProcessTargetString(arg1, iClient, target_list, MAXPLAYERS, COMMAND_FILTER_ALIVE | COMMAND_FILTER_NO_MULTI, target_name, sizeof(target_name), tn_is_ml)) <= 0) { ReplyToTargetError(iClient, target_count); return Plugin_Handled; }
for(int i = 0; i < target_count; i++) { int iTarget = target_list[i]; if(!iTarget) //if iTarget == 0 return Plugin_Handled; if(!bIsGreyTeam[iTarget]) { iLastClientTeam[iTarget] = GetEntProp(iTarget, Prop_Send, "m_iTeamNum");
GetClientAbsOrigin(iTarget, fOrigin[iTarget]); GetClientEyeAngles(iTarget, fAngles[iTarget]); TF2_ChangeClientTeam(iTarget, TFTeam_Spectator); SetEntProp(iTarget, Prop_Send, "m_iTeamNum", 0); TF2_RespawnPlayer(iTarget); TeleportEntity(iTarget, fOrigin[iTarget], fAngles[iTarget], NULL_VECTOR); SetEntProp(iTarget, Prop_Send, "m_iTeamNum", 1); bIsGreyTeam[iTarget] = true;
//CreateTimer(0.1, ChangeTargetTeam, iTarget); } } } return Plugin_Handled; }
public Action Command_ResetTeam(int iClient, int 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(iClient, fOrigin[iClient]); //get the current location of him GetClientEyeAngles(iClient, fAngles[iClient]); //get the current location of him TF2_ChangeClientTeam(iClient, view_as<TFTeam>(iLastClientTeam[iClient])); //Change to him the team he was TF2_RespawnPlayer(iClient); //Respawn him TeleportEntity(iClient, fOrigin[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(1, arg1, sizeof(arg1));
if((target_count = ProcessTargetString(arg1, iClient, target_list, MAXPLAYERS, COMMAND_FILTER_ALIVE | COMMAND_FILTER_NO_MULTI, target_name, sizeof(target_name), tn_is_ml)) <= 0) { ReplyToTargetError(iClient, target_count); return Plugin_Handled; }
for(int i = 0; i < target_count; i++) { int iTarget = target_list[i]; if(!iTarget) //if iTarget == 0 return Plugin_Handled; if(bIsGreyTeam[iTarget]) { GetClientAbsOrigin(iTarget, fOrigin[iTarget]); GetClientEyeAngles(iTarget, fAngles[iTarget]);
TF2_ChangeClientTeam(iTarget, view_as<TFTeam>(iLastClientTeam[iTarget])); TF2_RespawnPlayer(iTarget); TeleportEntity(iTarget, fOrigin[iTarget], fAngles[iTarget], NULL_VECTOR); bIsGreyTeam[iTarget] = false;
} } } return Plugin_Handled; }
public Action Command_GetSpecCount(int iClient, int 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; i <= MaxClients; i++) if(IsValidClient(i) && !IsFakeClient(i) && (iTeamNum == -1 || GetClientTeam(i) == iTeamNum)) iCounter++; return iCounter; }
stock bool IsValidClient(int client) { return (1 <= 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");
__________________
Last edited by Whai; 11-14-2018 at 13:10.
|
|