Advertisement
Guest User

Untitled

a guest
Jul 26th, 2011
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <amxmodx>
  2. #include <engine>
  3. #include <fakemeta>
  4. #include <hamsandwich>
  5.  
  6. #pragma semicolon 1
  7.  
  8. #define MAX_ENTITYS 1380 // (900+15*SERVER_SLOTS) is the calculation cs uses but it can be bypassed by the "-num_edicts <x>"-parameter
  9.  
  10. new bool:g_bPlayerInvisible[33];
  11. new bool:g_bWaterInvisible[33];
  12.  
  13. new bool:g_bWaterEntity[MAX_ENTITYS];
  14. new bool:g_bWaterFound;
  15.  
  16. new g_iSpectatedId[33];
  17.  
  18. public plugin_init( )
  19. {
  20.     register_plugin( "Invis", "2.0", "SchlumPF" );
  21.    
  22.     register_clcmd( "say /invis", "menuInvisDisplay" );
  23.     register_menucmd( register_menuid( "\rInvisibility - SchlumPF^n^n" ), 1023, "menuInvisAction" );
  24.    
  25.     register_forward( FM_AddToFullPack, "fwdAddToFullPack_Post", 1 );
  26.     RegisterHam( Ham_Spawn, "player", "hamSpawnPlayer_Post", 1 );
  27.    
  28.     register_event( "StatusValue", "changedSpectatedPlayer", "bd", "1=2" );
  29.     register_event( "SpecHealth", "changedSpectatedPlayer", "bd" );
  30. }
  31.  
  32. public plugin_cfg( )
  33. {
  34.     // precache in a boolean variable whether an entity is func_water or not.
  35.     // this will save a lot performance since AddToFullPack is called very often.
  36.     // i could set the ents iuser variable to avoid using such a huge variable
  37.     // and problems with the "-num_edicts" parameter but this is a lot faster
  38.     // than retrieving pev_iuser in AddToFullPack. another way would have been
  39.     // using a binary system to store the data in less than a huge array but in
  40.     // fact a huge array takes a few kb ram which is for me less than a constant
  41.     // usage of the cpu since i would need to use a few operators to read the data
  42.     // out of the bianry system. all in all a binary storing system is at least a good
  43.     // alternative which some iuser variable of the private ent values (pev) would not be.
  44.    
  45.     new count;
  46.    
  47.     new ent = find_ent_by_class( -1, "func_water" );
  48.     while( ent )
  49.     {
  50.         // ( pev( ent, pev_skin ) == CONTENTS_WATER ) is also true on func_water entities
  51.        
  52.         g_bWaterEntity[ent] = true;
  53.         count++;
  54.        
  55.         find_ent_by_class( ent, "func_water" );
  56.     }
  57.    
  58.     // thanks to connor for finding the following two detections
  59.     ent = find_ent_by_class( -1, "func_illusionary" );
  60.     while( ent )
  61.     {
  62.         if( pev( ent, pev_skin ) ==  CONTENTS_WATER )
  63.         {
  64.             g_bWaterEntity[ent] = true;
  65.             count++;
  66.         }
  67.        
  68.         find_ent_by_class( ent, "func_illusionary" );
  69.     }
  70.    
  71.     ent = find_ent_by_class( -1, "func_conveyor" );
  72.     while( ent )
  73.     {
  74.         if( pev( ent, pev_spawnflags ) == 3 )
  75.         {
  76.             g_bWaterEntity[ent] = true;
  77.             count++;
  78.         }
  79.        
  80.         find_ent_by_class( ent, "func_conveyor" );
  81.     }
  82.    
  83.     g_bWaterFound = !!count;
  84. }
  85.  
  86. public fwdAddToFullPack_Post( es_handle, e, ent, host, hostflags, player, pset )
  87. {
  88.     if( ( player && g_bPlayerInvisible[host] && host != ent && ent != g_iSpectatedId[host] )
  89.     || ( g_bWaterInvisible[host] && g_bWaterEntity[ent] ) )
  90.     {
  91.         set_es( es_handle, ES_Effects, get_es( es_handle, ES_Effects ) | EF_NODRAW );
  92.     }
  93. }
  94.  
  95. public hamSpawnPlayer_Post( plr )
  96. {
  97.     g_iSpectatedId[plr] = 0;
  98. }
  99.  
  100. // thanks to xPaw who told me about this event
  101. public changedSpectatedPlayer( plr )
  102. {
  103.     g_iSpectatedId[plr] = read_data( 2 );
  104. }
  105.  
  106. public menuInvisDisplay( plr )
  107. {
  108.     static menu[256];
  109.  
  110.     new len = formatex( menu, 255, "\rInvisibility - SchlumPF^n^n" );
  111.    
  112.     len += formatex( menu[len], 255 - len, "\r1. \wPlayers: %s^n", g_bPlayerInvisible[plr] ? "invisible" : "visible" );
  113.    
  114.     if( g_bWaterFound )
  115.     {
  116.         len += formatex( menu[len], 255 - len, "\r2. \wWater: %s^n", g_bWaterInvisible[plr] ? "invisible" : "visible" );
  117.     }
  118.     //else
  119.     //{
  120.     //  len += formatex( menu[len], 255 - len, "\r2. \wWater: There is no water on this map!^n" );
  121.     //}
  122.  
  123.     len += formatex( menu[len], 255 - len, "^n\r0. \wExit" );
  124.    
  125.     show_menu( plr, ( 1<<0 | 1<<1 | 1<<9 ), menu, -1 );
  126.        
  127.     return PLUGIN_HANDLED;
  128. }
  129.  
  130. public menuInvisAction( plr, key )
  131. {
  132.     switch( key )
  133.     {
  134.         case 0:
  135.         {
  136.             g_bPlayerInvisible[plr] = !g_bPlayerInvisible[plr];
  137.             menuInvisDisplay( plr );
  138.         }
  139.         case 1:
  140.         {
  141.             if( g_bWaterFound )
  142.             {
  143.                 g_bWaterInvisible[plr] = !g_bWaterInvisible[plr];
  144.             }
  145.            
  146.             menuInvisDisplay( plr );
  147.         }
  148.         case 9: show_menu( plr, 0, "" );
  149.     }
  150. }
  151.  
  152. public client_connect( plr )
  153. {
  154.     g_bPlayerInvisible[plr] = false;
  155.     g_bWaterInvisible[plr] = false;
  156.     g_iSpectatedId[plr] = 0;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement