Wow thx, Dr1fter's plugin really works well, so if someone needs same thing as me (prevent to spectate for someone), here how I did this:
PHP Code:
...
#include <dhooks>
...
Handle hIsValidTarget;
bool g_bCheckNullPtr = false;
bool g_bStopspec[MAXPLAYERS + 1];
...
public void OnPluginStart()
{
RegConsoleCmd("sm_stopspec", SM_Stopspec, "Prevent spectators to spec you");
Handle temp = LoadGameConfigFile("allow-spec.games");
if(!temp)
{
SetFailState("Failed to load allow-spec.games.txt");
}
int offset = GameConfGetOffset(temp, "IsValidObserverTarget");
hIsValidTarget = DHookCreate(offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity, IsValidTarget);
DHookAddParam(hIsValidTarget, HookParamType_CBaseEntity);
CloseHandle(temp);
g_bCheckNullPtr = (GetFeatureStatus(FeatureType_Native, "DHookIsNullParam") == FeatureStatus_Available);
}
...
public void OnClientPutInServer(int client)
{
if(IsFakeClient(client))
return;
DHookEntity(hIsValidTarget, true, client);
}
...
public MRESReturn IsValidTarget(int pThis, Handle hReturn, Handle hParams)
{
// As of DHooks 1.0.12 we must check for a null param.
if (g_bCheckNullPtr && DHookIsNullParam(hParams, 1))
return MRES_Ignored;
int target = DHookGetParam(hParams, 1);
if(target <= 0 || target > MaxClients || !IsClientInGame(pThis) || !IsClientInGame(target) || !IsPlayerAlive(target) || IsPlayerAlive(pThis))
{
return MRES_Ignored;
}
else if (g_bStopspec[target] && GetUserAdmin(pThis) == INVALID_ADMIN_ID)
{
PrintToChat(pThis, "You cannot spectate %N", target);
DHookSetReturn(hReturn, false);
return MRES_Override;
}
else
{
DHookSetReturn(hReturn, true);
return MRES_Override;
}
}
...
public void OnClientDisconnect(int client)
{
g_bStopspec[client] = false;
}
...
public Action SM_Stopspec(int client, int args)
{
g_bStopspec[client] = !g_bStopspec[client];
PrintToChat(client, "You toggle stopspec");
return Plugin_Handled;
}
...
Also you need to use dhook and
gamedata file, named "allow-spec.games"