Raised This Month: $ Target: $400
 0% 

Disable spectating for certain players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
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 #1

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
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 04:40.


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