AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Disable spectating for certain players (https://forums.alliedmods.net/showthread.php?t=307357)

Ludak 05-06-2018 16:18

Disable spectating for certain players
 
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.

E1_531G 05-06-2018 16:30

Re: Disable spectating for certain players
 
Yes, you can try to hook SpecHealth2 message (to get target id) and set permanent black ScreenFade until next round or spawn event begins.

Relaxing 05-06-2018 17:16

Re: Disable spectating for certain players
 
Quote:

Originally Posted by E1_531G (Post 2591001)
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.

Bugsy 05-06-2018 20:00

Re: Disable spectating for certain players
 
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.

Ludak 05-08-2018 06:37

Re: Disable spectating for certain players
 
Quote:

Originally Posted by Relaxing (Post 2591005)
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 (Post 2591017)
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 :D

OciXCrom 05-08-2018 17:18

Re: Disable spectating for certain players
 
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.

Bugsy 05-08-2018 19:18

Re: Disable spectating for certain players
 
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(); 



fvRate 05-08-2018 20:58

Re: Disable spectating for certain players
 
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( ); }

Bugsy 05-08-2018 21:00

Re: Disable spectating for certain players
 
So you set to black if the player doesn't have the admin flag ? :nono: 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

fvRate 05-08-2018 21:07

Re: Disable spectating for certain players
 
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?


All times are GMT -4. The time now is 04:40.

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