#include <sourcemod>
#include <sdktools>
#include <menus>
#include <topmenus>
#define PLUGIN_PREFIX "[Easy Spectate]"
public Plugin:myinfo =
{
name = "Easy Spectate",
author = "Tadeo 'Pichi' Cantuano",
description = "Simple spectate by client names",
version = "0.0.1",
url = "http://www.google.com/"
};
new Handle:g_Cvar_EasySpecEnable = INVALID_HANDLE;
new bool:g_EasySpecEnable = true;
public OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("easyspectate.phrases");
g_Cvar_EasySpecEnable = CreateConVar("easy_spec_enable", "1", "Enable easy spectating", 0, true, 0.0, true, 1.0);
g_EasySpecEnable = GetConVarBool(g_Cvar_EasySpecEnable);
HookConVarChange(g_Cvar_EasySpecEnable, OnEasySpecChange);
RegAdminCmd("sm_es", EasySpec, 0);
}
public OnEasySpecChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
g_EasySpecEnable = bool:StringToInt(newVal);
}
public Action:EasySpec(client, args)
{
if (!g_EasySpecEnable)
{
PrintToChat(client, "%s %t", PLUGIN_PREFIX, "Easy Spectate Disabled");
return Plugin_Handled;
}
if (client < 1 || !IsClientInGame(client))
{
return Plugin_Handled;
}
if (!IsClientObserver(client))
{
PrintToChat(client, "%s %t", PLUGIN_PREFIX, "Easy Spectate Not Alive");
return Plugin_Handled;
}
if (args < 1)
{
PrintToChat(client, "%s Usage: sm_es <#userid|name>", PLUGIN_PREFIX);
return Plugin_Handled;
}
decl String:arg1[MAX_NAME_LENGTH];
GetCmdArgString(arg1, sizeof(arg1));
new target = FindTarget(client, arg1, false, false);
if (target == -1 || !IsClientInGame(target))
{
return Plugin_Handled;
}
if (IsClientObserver(target))
{
PrintToChat(client, "%s %t", PLUGIN_PREFIX, "Easy Spectate Alive Only");
return Plugin_Handled;
}
FakeClientCommand(client, "spec_player %d", target);
decl String:targetname[MAX_NAME_LENGTH];
GetClientName(target, targetname, sizeof(targetname));
PrintToChat(client, "%s %t", PLUGIN_PREFIX, "Easy Spectate Spectating", targetname);
return Plugin_Handled;
}