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_string( iEntity , EV_SZ_classname , "SpecEntity" );
register_think( "SpecEntity" , "SpecThink" );
entity_set_float( iEntity , EV_FL_nextthink , get_gametime() + fRefreshInterval );
g_MsgFade = get_user_msgid( "ScreenFade" );
}
public SpecThink( iEntity )
{
new iPlayers[ 32 ] , iNum , iPlayer , iSpectating;
new iCanBeSpectated[ 32 ] , iCanBeSpectatedCount;
new iNoSpectate , szName[ 32 ];
//Get alive players who can and cannot be spectated.
get_players( iPlayers , iNum , "a" );
if ( iNum )
{
for ( new i = 0 ; i < iNum ; i++ )
{
iPlayer = iPlayers[ i ];
if ( get_user_flags( iPlayer ) & No_Spectate_Flag )
{
iNoSpectate |= ( 1 << iPlayer );
}
else
{
iCanBeSpectated[ iCanBeSpectatedCount++ ] = 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_players( iPlayers , iNum , "bch" );
if ( iNum )
{
for ( new i = 0 ; i < iNum ; i++ )
{
iPlayer = iPlayers[ i ];
iSpectating = pev( iPlayer , pev_iuser2 );
//Spectating player does not have flag and player being spectated does.
if ( !( get_user_flags( iPlayer ) & No_Spectate_Flag ) && ( iNoSpectate & ( 1 << iSpectating ) ) )
{
if ( iCanBeSpectatedCount )
{
get_user_name( iSpectating , szName , charsmax( szName ) );
client_print( iPlayer , print_chat , "* %s cannot be spectated!" , szName );
set_pev( iPlayer , pev_iuser2 , iCanBeSpectated[ random( iCanBeSpectatedCount ) ] );
}
else
{
BlackScreen( iPlayer );
}
}
}
}
entity_set_float( iEntity , EV_FL_nextthink , get_gametime() + fRefreshInterval );
}
BlackScreen( id )
{
message_begin( MSG_ONE , g_MsgFade , {0,0,0} , id );
write_short( 4096 );
write_short( 4096 );
write_short( 4096 );
write_byte( 0 );
write_byte( 0 );
write_byte( 0 );
write_byte( 255 );
message_end();
}
__________________