Here's something I created that makes it so when you type "sm_hiddenspectate" it puts up a message in chat saying that you disconnected from the game, silently switches you to spectator, and removes you from the scoreboard.
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <cstrike>
#include <sdkhooks>
#include <sdktools>
new bool:g_bIsHiding[MAXPLAYERS+1];
public Plugin:myinfo = {
name = "Hidden Spectate",
author = "bl4nk",
description = "Command to go to spectator and appear to no longer be in the game",
version = "1.0.0",
url = "http://forums.alliedmods.net/"
};
public OnPluginStart() {
RegAdminCmd("sm_hiddenspectate", Command_HiddenSpectate, ADMFLAG_SLAY, "sm_hiddenspectate - Sticks you into spectator and makes it appear as if you left the game");
HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre);
}
public OnMapStart() {
new iIndex = FindEntityByClassname(MaxClients+1, "cs_player_manager");
if (iIndex == -1) {
SetFailState("Unable to find tf_player_manager entity");
}
SDKHook(iIndex, SDKHook_ThinkPost, Hook_OnThinkPost);
}
public OnClientPutInServer(iClient) {
g_bIsHiding[iClient] = false;
}
public OnClientDisconnect(iClient) {
g_bIsHiding[iClient] = false;
}
public Action:Command_HiddenSpectate(iClient, iArgs) {
if (g_bIsHiding[iClient]) {
ReplyToCommand(iClient, "[SM] You are already hiding.");
return Plugin_Handled;
}
g_bIsHiding[iClient] = true;
if (GetClientTeam(iClient) != CS_TEAM_SPECTATOR) {
ChangeClientTeam(iClient, CS_TEAM_SPECTATOR);
}
PrintToChatAll("Player %N left the game (Disconnect by user.)", iClient);
ReplyToCommand(iClient, "[SM] You are now hiding.");
LogAction(iClient, -1, "%L used the hidden spectate command.", iClient);
return Plugin_Handled;
}
public Action:Event_PlayerTeam(Handle:hEvent, const String:szEventName[], bool:bDontBroadcast) {
new iClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
if (g_bIsHiding[iClient]) {
if (GetEventInt(hEvent, "team") == CS_TEAM_SPECTATOR) {
return Plugin_Handled;
} else {
g_bIsHiding[iClient] = false;
ReplyToCommand(iClient, "[SM] You are no longer hiding.");
}
}
return Plugin_Continue;
}
public Hook_OnThinkPost(iEnt) {
static iConnectedOffset = -1;
if (iConnectedOffset == -1) {
iConnectedOffset = FindSendPropInfo("CCSPlayerResource", "m_bConnected");
}
new iConnected[65];
GetEntDataArray(iEnt, iConnectedOffset, iConnected, MaxClients+1);
for (new i = 1; i <= MaxClients; i++) {
if (g_bIsHiding[i]) {
iConnected[i] = 0;
}
}
SetEntDataArray(iEnt, iConnectedOffset, iConnected, MaxClients+1);
}