Raised This Month: $12 Target: $400
 3% 

Solved [CSGO] How to prevent someone to spectate?!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
butare
Senior Member
Join Date: Nov 2016
Old 09-23-2017 , 12:38   [CSGO] How to prevent someone to spectate?!
Reply With Quote #1

Is there any way that I can prevent someone to spectate? Like for example if player 1 types in chat "!stopspec", then when player 2 is trying to spectate player 1, he will be noticed that he can not spectate player 1 and will be redirected to another player that he allowed to spectate. How can I do same thing?

Last edited by butare; 10-06-2017 at 12:06.
butare is offline
fraise
Member
Join Date: Sep 2016
Location: Paris, France
Old 09-29-2017 , 07:28   Re: [CSGO] How to prevent someone to spectate?!
Reply With Quote #2

PHP Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#include <sdkhooks>
bool spectate[MAXPLAYERS+1];
public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_stopspectate"stopspectate);
    
CreateTimer(2.0refreshspec_TIMER_REPEAT);
}

public 
Action stopspectate(int clientint args)
{
    if(
spectate[client])
    {
        
spectate[client]=false;
        
PrintToChat(client"Spectate off !");
    }
    else if(!
spectate[client])
    {
        
spectate[client]=true;
        
PrintToChat(client"Spectate on !");
    }
}
public 
Action refreshspec(Handle timer)
{
    for(
int i=1i<MaxClientsi++)
    {
        if(
IsClientObserver(i))
        {
            
int ent GetEntPropEnt(iProp_Send"m_hObserverTarget");
            if(!
spectate[ent])
            {
                
PrintToChat(i"You're not allowed to watch this player");
                
SetEntProp(iProp_Send"m_iObserverMode"3);
            }
        }
    }

__________________
\o/
fraise is offline
butare
Senior Member
Join Date: Nov 2016
Old 09-29-2017 , 07:43   Re: [CSGO] How to prevent someone to spectate?!
Reply With Quote #3

Hmm delay is a bit big, but if I change it to like 0.2, its hard to switch to another player cuz plugin sets you in a free look, so you need to press space and switch to another player fast enough, so plugin did not set you in a free look again. How can I prevent spectating? Maybe some sort of hook or smth?
butare is offline
butare
Senior Member
Join Date: Nov 2016
Old 09-29-2017 , 07:47   Re: [CSGO] How to prevent someone to spectate?!
Reply With Quote #4

Also if you will spam space key, you can clearly see what player is doing.
butare is offline
fraise
Member
Join Date: Sep 2016
Location: Paris, France
Old 09-29-2017 , 07:53   Re: [CSGO] How to prevent someone to spectate?!
Reply With Quote #5

sorry, don't found other solution :s btw, there is no fucking help on google about different spec mode >< if someone could solve this =)
__________________
\o/
fraise is offline
Kinsi
Senior Member
Join Date: Apr 2013
Old 09-29-2017 , 12:18   Re: [CSGO] How to prevent someone to spectate?!
Reply With Quote #6

You can listen to the client commands spec_mode, spec_next and spec_prev and handle them. Also use mp_forcecamera 2 (fade to black)
__________________

Last edited by Kinsi; 09-29-2017 at 12:19.
Kinsi is offline
butare
Senior Member
Join Date: Nov 2016
Old 10-02-2017 , 15:56   Re: [CSGO] How to prevent someone to spectate?!
Reply With Quote #7

Sorry for late reply, but that also didn't work, when I hook those commands(spec_prev and spec_next) it only hooks when I type that command, and if I press mouse button it will not hook. And mp_forcecamera works on all players and only when player die. Maybe I did something wrong? It only displays text when I use spec_prev directly and not displaying when I switching by using mouse buttons, or left/right keys on keyboard.
PHP Code:
...
public 
void OnPluginStart()
{
    ...
    
AddCommandListener(PrevCallback"spec_prev");
    ...
}
...
public 
Action PrevCallback(int client, const char[] commandint args)
{
    
PrintToChat(client"You switched to prev player;");
    
    return 
Plugin_Continue;
}
... 
butare is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-02-2017 , 19:54   Re: [CSGO] How to prevent someone to spectate?!
Reply With Quote #8

There is Drifter's plugin what use Dhooks, only admins can spectate.
__________________
Do not Private Message @me
Bacardi is offline
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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode