View Single Post
butare
Senior Member
Join Date: Nov 2016
Old 10-06-2017 , 12:01   Re: [CSGO] How to prevent someone to spectate?!
Reply With Quote #9

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(offsetHookType_EntityReturnType_BoolThisPointer_CBaseEntityIsValidTarget);
    
    
DHookAddParam(hIsValidTargetHookParamType_CBaseEntity);
    
    
CloseHandle(temp);
    
    
g_bCheckNullPtr = (GetFeatureStatus(FeatureType_Native"DHookIsNullParam") == FeatureStatus_Available);
}
...
public 
void OnClientPutInServer(int client)
{
    if(
IsFakeClient(client))
        return;

    
DHookEntity(hIsValidTargettrueclient);
}
...
public 
MRESReturn IsValidTarget(int pThisHandle hReturnHandle hParams)
{
    
// As of DHooks 1.0.12 we must check for a null param.
    
if (g_bCheckNullPtr && DHookIsNullParam(hParams1))
        return 
MRES_Ignored;
    
    
int target DHookGetParam(hParams1);
    if(
target <= || 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(hReturnfalse);
        return 
MRES_Override;
    } 
    else 
    {
        
DHookSetReturn(hReturntrue);
        return 
MRES_Override;
    }
}
...
public 
void OnClientDisconnect(int client)
{
    
g_bStopspec[client] = false;
}
...
public 
Action SM_Stopspec(int clientint 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"
butare is offline