#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>
new Handle:hHideFeed = INVALID_HANDLE;
public Plugin:myinfo =
{
name = "[CS:S] Bot Control",
author = "DonRevan",
description = "Take control of bots while spectating them.",
version = "1.0",
url = "http://sourcemod.net/"
}
public OnPluginStart()
{
CreateTimer(5.0, Timer_CheckObserver, _, TIMER_REPEAT);
hHideFeed = CreateArray();
HookEvent("player_death", OnPlayerDeath, EventHookMode_Pre);
}
public OnMapStart()
{
ClearArray(hHideFeed);
}
public Action:OnPlayerDeath(Handle:hEvent, const String:strName[], bool:bBroadcast)
{
new iVictimID = GetEventInt(hEvent, "userid");
new iVictim = GetClientOfUserId(iVictimID);
if(IsValidClient(iVictim) && IsFakeClient(iVictim))
{
new idx = FindValueInArray(hHideFeed, iVictimID);
if(idx != -1)
{
SetEventBroadcast(hEvent, true);
RemoveFromArray(hHideFeed, idx);
}
}
return Plugin_Continue;
}
/*stock Handle:CreateSpectatorStack(client)
{
decl cl;
new Handle:hSpec = INVALID_HANDLE;
for(new x=1;x<=MAXPLAYERS;x++)
{
cl = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if(cl == client)
{
if(hSpec == INVALID_HANDLE)
{
hSpec = CreateStack();
}
PushStackCell(hSpec, cl);
}
}
return hSpec;
}*/
new bool:bCantUse[MAXPLAYERS];
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
if((buttons & IN_USE))
{
if (!bCantUse[client] && IsClientInGame(client) && !IsPlayerAlive(client))
{
bCantUse[client] = true;
CreateTimer(1.0, Timer_ResetPressDelay, client);
new target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if(IsValidClient(target) && IsFakeClient(target))
{
new targetID = GetClientUserId(target);
if(FindValueInArray(hHideFeed, targetID) == -1)
{
PushArrayCell(hHideFeed, targetID);
}
decl Float:fPos[3];
GetClientAbsOrigin(target, Float:fPos);
ForcePlayerSuicide(target);
CS_RespawnPlayer(target);
TeleportEntity(client, fPos, NULL_VECTOR, NULL_VECTOR);
}
}
}
return Plugin_Continue;
}
public Action:Timer_CheckObserver(Handle:timer, any:client)
{
new target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
if(IsValidClient(target) && IsFakeClient(target))
{
PrintHintTextSilent(target, "You're spectating a bot, press E to take control.");
}
}
public Action:Timer_ResetPressDelay(Handle:timer, any:client)
{
bCantUse[client] = false;
}
/** STOCKS */
stock PrintHintTextSilent(client, const String:szMessage[])
{
PrintHintText(client, szMessage);
StopSound(client, SNDCHAN_STATIC, "UI/hint.wav"); //dat sound
}
stock bool:IsValidClient(iClient)
{
if(iClient <= 0 || iClient > MaxClients || !IsClientInGame(iClient))
return false;
return true;
}