Raised This Month: $ Target: $400
 0% 

Disable spectating for certain players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ludak
Member
Join Date: Oct 2014
Old 05-06-2018 , 16:18   Disable spectating for certain players
Reply With Quote #1

Hello everyone.
Is it possible to disable spectating for certain players?
For example, I want for VIP's to have an ability that they can not be spectated by other players without admin kick flag.
Can it be done with solid black ScreenFade?
Thank you.
Ludak is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 05-06-2018 , 16:30   Re: Disable spectating for certain players
Reply With Quote #2

Yes, you can try to hook SpecHealth2 message (to get target id) and set permanent black ScreenFade until next round or spawn event begins.
__________________
My English is A0

Last edited by E1_531G; 05-06-2018 at 16:30.
E1_531G is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 05-06-2018 , 17:16   Re: Disable spectating for certain players
Reply With Quote #3

Quote:
Originally Posted by E1_531G View Post
Yes, you can try to hook SpecHealth2 message (to get target id) and set permanent black ScreenFade until next round or spawn event begins.
This makes no sense.
All players will disconnect from your server.
Message for OP: Please don't overkill VIP features. Noone would sit watching a black screen for 3 minutes, over and over. Close this thread, barely trashing. Don't suggest bad ideas either examples/solutions.
__________________
Relaxing is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-06-2018 , 20:00   Re: Disable spectating for certain players
Reply With Quote #4

You don't need to set to a black screen, just set to another player who is not a VIP. If only VIP's are playing, then set to black screen, or something.
__________________
Bugsy is offline
Ludak
Member
Join Date: Oct 2014
Old 05-08-2018 , 06:37   Re: Disable spectating for certain players
Reply With Quote #5

Quote:
Originally Posted by Relaxing View Post
This makes no sense.
All players will disconnect from your server.
Message for OP: Please don't overkill VIP features. Noone would sit watching a black screen for 3 minutes, over and over. Close this thread, barely trashing. Don't suggest bad ideas either examples/solutions.
I have a custom game mode where VIP needs to be protected, and no one should leak the information about his position.

Quote:
Originally Posted by Bugsy View Post
You don't need to set to a black screen, just set to another player who is not a VIP. If only VIP's are playing, then set to black screen, or something.
I do not know how to do it, I have searched but failed to found the answer.
Can you give me the code?
Thank you
Ludak is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-08-2018 , 17:18   Re: Disable spectating for certain players
Reply With Quote #6

Not sure if it will work, but try using set_pev(id, pev_iuser2, target_id). It makes sense do to this because pev_iuser2 holds the id of the spectated player, but I'm not sure if modifying it will actually change anything.
__________________

Last edited by OciXCrom; 05-08-2018 at 17:19.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-08-2018 , 19:18   Re: Disable spectating for certain players
Reply With Quote #7

Players with ADMIN_KICK can spectate all.
Players without ADMIN_KICK cannot spectate players with ADMIN_KICK.

May want to add a HUD or something explaining why they are getting a black screen if no spectate-able players are available.

Hardly tested.
PHP Code:

#include <amxmodx>
#include <engine>
#include <fakemeta>

new const Version[] = "0.1";

const 
No_Spectate_Flag ADMIN_KICK;
const 
Float:fRefreshInterval 0.15;

new 
g_MsgFade;

public 
plugin_init() 
{
    
register_plugin"No Spec Player" Version "bugsy" );
    
    new 
iEntity create_entity"info_target" );
    
entity_set_stringiEntity EV_SZ_classname "SpecEntity" );
    
register_think"SpecEntity" "SpecThink" );
    
entity_set_floatiEntity EV_FL_nextthink get_gametime() + fRefreshInterval );
    
    
g_MsgFade get_user_msgid"ScreenFade" ); 
}

public 
SpecThinkiEntity )
{
    new 
iPlayers32 ] , iNum iPlayer iSpectating;
    new 
iCanBeSpectated32 ] , iCanBeSpectatedCount;
    new 
iNoSpectate szName32 ];
    
    
//Get alive players who can and cannot be spectated.
    
get_playersiPlayers iNum "a" );
    
    if ( 
iNum )
    {
        for ( new 
iNum i++ )
        {
            
iPlayer iPlayers];
            
            if ( 
get_user_flagsiPlayer ) & No_Spectate_Flag )
            {
                
iNoSpectate |= ( << iPlayer );
            }
            else
            {
                
iCanBeSpectatediCanBeSpectatedCount++ ] = iPlayer;
            }
        }    
    }
    
    
//Cycle through all spectating players. Check who they are spectating and if the spectated has the no-spectate flag
    //set spectated to a player who does not have the no-spectate flag.
    
    
get_playersiPlayers iNum "bch" );
    
    if ( 
iNum )
    {
        for ( new 
iNum i++ )
        {
            
iPlayer iPlayers];
            
            
iSpectating peviPlayer pev_iuser2 );
    
            
//Spectating player does not have flag and player being spectated does.
            
if ( !( get_user_flagsiPlayer ) & No_Spectate_Flag ) && ( iNoSpectate & ( << iSpectating ) ) )
            {
                if ( 
iCanBeSpectatedCount )
                {    
                    
get_user_nameiSpectating szName charsmaxszName ) );
                    
client_printiPlayer print_chat "* %s cannot be spectated!" szName );
                    
                    
set_peviPlayer pev_iuser2 iCanBeSpectatedrandomiCanBeSpectatedCount ) ] );
                }
                else
                {
                    
BlackScreeniPlayer );
                }
            }
        }
    }
    
    
entity_set_floatiEntity EV_FL_nextthink get_gametime() + fRefreshInterval );
}

BlackScreenid 

    
message_beginMSG_ONE g_MsgFade , {0,0,0} , id ); 
    
write_short4096 ); 
    
write_short4096 ); 
    
write_short4096 ); 
    
write_byte); 
    
write_byte); 
    
write_byte); 
    
write_byte255 ); 
    
message_end(); 

__________________

Last edited by Bugsy; 05-08-2018 at 21:16.
Bugsy is offline
fvRate
Junior Member
Join Date: May 2018
Old 05-08-2018 , 20:58   Re: Disable spectating for certain players
Reply With Quote #8

This will do the job :

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <fakemeta> #pragma semicolon         1 #define ADMIN_ACCES     ADMIN_KICK #define ADMIN_VIP       ADMIN_LEVEL_H #define FFADE_STAYOUT   0x0004 new msg_ScreenFade; public plugin_init( ) {     register_plugin     (         .plugin_name    = "Plugin",         .version         = "1.0",         .author         = "fvRate"     );         register_event( "SpecHealth2", "event_Spec", "bd" );         msg_ScreenFade = get_user_msgid( "ScreenFade" ); } public event_Spec( index ) {       new specIndex = read_data(2);         if( specIndex == index && !( get_user_flags( specIndex ) & ADMIN_VIP ) )         return;         ( get_user_flags( specIndex ) & ADMIN_ACCES  ) ?         set_Fade( index, false  ) :         set_Fade( index, true ) ; } stock set_Fade( index, bool:fadeState ) {     message_begin( MSG_ONE_UNRELIABLE, msg_ScreenFade, _, index );     {         write_short( 0 );         write_short( 0 );         write_short( fadeState ? FFADE_STAYOUT : ~FFADE_STAYOUT );         write_byte( 0 );         write_byte( 0 );         write_byte( 0 );         write_byte( 255 );     }     message_end( ); }

Last edited by fvRate; 05-09-2018 at 09:16.
fvRate is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-08-2018 , 21:00   Re: Disable spectating for certain players
Reply With Quote #9

So you set to black if the player doesn't have the admin flag ? And I dont think your code does what he wants.

and this ?
PHP Code:
    get_user_flagsspecIndex ) & ADMIN_ACCES ) ?
        
set_Fadeindextrue  ) : 
        
set_Fadeindexfalse ) ; 
Why?? lol
__________________

Last edited by Bugsy; 05-08-2018 at 21:03.
Bugsy is offline
fvRate
Junior Member
Join Date: May 2018
Old 05-08-2018 , 21:07   Re: Disable spectating for certain players
Reply With Quote #10

I've tested the code and it worked.

I need to reset the fade to normal by reversing the bit set at the first place.

I'm not giving him a good solution, I'm just following his idea.

"So you set to black if the player doesn't have the admin flag ?" what's wrong with that?

Last edited by fvRate; 05-08-2018 at 21:08.
fvRate is offline
Reply



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 07:14.


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