SHARE
TWEET

Untitled

a guest May 24th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <amxmodx>
  2. #include <fakemeta>
  3.  
  4. #pragma semicolon 1
  5.  
  6. #define DISTANCE 120.0
  7. #define UPDATE_FREQ 0.2
  8.  
  9. new bool:g_bSemiclip[33][33];
  10. new bool:g_bHasSemiclip[33];
  11. new bool:g_bSemiclipEnabled;
  12.  
  13. new g_iTaskId;
  14. new g_iForwardId[3];
  15. new g_iMaxPlayers;
  16. new g_iCvar[3];
  17.  
  18. public plugin_init( )
  19. {
  20.     register_plugin( "(Team-)Semiclip", "1.0", "SchlumPF*" );
  21.  
  22.     g_iCvar[0] = register_cvar( "semiclip_enabled", "1" );
  23.     g_iCvar[1] = register_cvar( "semiclip_teamclip", "1" );
  24.     g_iCvar[2] = register_cvar( "semiclip_transparancy", "0" );
  25.  
  26.     register_forward( FM_Think, "fwdThink" );
  27.     register_forward( FM_ClientCommand, "fwdClientCommand" );
  28.  
  29.     if( get_pcvar_num( g_iCvar[0] ) )
  30.     {
  31.         g_iForwardId[0] = register_forward( FM_PlayerPreThink, "fwdPlayerPreThink" );
  32.         g_iForwardId[1] = register_forward( FM_PlayerPostThink, "fwdPlayerPostThink" );
  33.         g_iForwardId[2] = register_forward( FM_AddToFullPack, "fwdAddToFullPack_Post", 1 );
  34.  
  35.         g_bSemiclipEnabled = true;
  36.     }
  37.     else
  38.     {
  39.         g_bSemiclipEnabled = false;
  40.  
  41.         g_iMaxPlayers = get_maxplayers( );
  42.  
  43.         new ent = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
  44.         set_pev( ent, pev_classname, "task_semiclip" );
  45.         set_pev( ent, pev_nextthink, get_gametime( ) + 1.01 );
  46.         g_iTaskId = ent;
  47.     }
  48. }
  49.  
  50. public fwdPlayerPreThink( plr )
  51. {
  52.     static id;
  53.  
  54.     if( is_user_alive( plr ) )
  55.     {
  56.         for( id = 1 ; id <= g_iMaxPlayers ; id++ )
  57.         {
  58.             if( pev( id, pev_solid ) == SOLID_SLIDEBOX && g_bSemiclip[plr][id] && id != plr )
  59.             {
  60.                 set_pev( id, pev_solid, SOLID_NOT );
  61.                 g_bHasSemiclip[id] = true;
  62.             }
  63.         }
  64.     }
  65. }
  66.  
  67. public fwdPlayerPostThink( plr )
  68. {
  69.     static id;
  70.  
  71.     if( is_user_alive( plr ) )
  72.     {
  73.         for( id = 1 ; id <= g_iMaxPlayers ; id++ )
  74.         {
  75.             if( g_bHasSemiclip[id] )
  76.             {
  77.                 set_pev( id, pev_solid, SOLID_SLIDEBOX );
  78.                 g_bHasSemiclip[id] = false;
  79.             }
  80.         }
  81.     }
  82. }
  83.  
  84. public fwdThink( ent )
  85. {
  86.     static i, j;
  87.     static team[33];
  88.     static Float:origin[33][3];
  89.  
  90.     if( ent == g_iTaskId )
  91.     {
  92.         if( get_pcvar_num( g_iCvar[0] ) )
  93.         {
  94.             for( i = 1 ; i <= g_iMaxPlayers ; i++ )
  95.             {
  96.                 if( is_user_alive( i ) )
  97.                 {
  98.                     pev( i, pev_origin, origin );
  99.  
  100.                     if( get_pcvar_num( g_iCvar[1] ) )
  101.                     team[i] = get_user_team( i );
  102.  
  103.                     for( j = 1 ; j <= g_iMaxPlayers ; j++ )
  104.                     {
  105.                         if( is_user_alive( j ) )
  106.                         {
  107.                             if( get_pcvar_num( g_iCvar[1] ) && team[i] != team[j] )
  108.                             {
  109.                                 g_bSemiclip[i][j] = false;
  110.                                 g_bSemiclip[i][j] = false;
  111.  
  112.                             }  
  113.                             else if( floatabs( origin[i][0] - origin[j][0] ) < DISTANCE && floatabs( origin[i][1] - origin[j][1] ) < DISTANCE && floatabs( origin[i][2] - origin[j][2] ) < ( DISTANCE * 2 ) )
  114.                             {
  115.                                 g_bSemiclip[i][j] = true;
  116.                                 g_bSemiclip[i][j] = true;
  117.                             }
  118.                             else
  119.                             {
  120.                                 g_bSemiclip[i][j] = false;
  121.                                 g_bSemiclip[i][j] = false;
  122.                             }
  123.                         }
  124.                     }
  125.                 }
  126.             }
  127.         }
  128.  
  129.         set_pev( ent, pev_nextthink, get_gametime( ) + UPDATE_FREQ );
  130.     }
  131. }
  132.  
  133. public fwdAddToFullPack_Post( es_handle, e, ent, host, hostflags, player, pset )
  134. {
  135.     if( player )
  136.     {
  137.         if( g_bSemiclip[host][ent] )
  138.         {
  139.             set_es( es_handle, ES_Solid, SOLID_NOT ); // makes semiclip flawless
  140.  
  141.             if( get_pcvar_num( g_iCvar[2] ) == 1 )
  142.             {
  143.                 set_es( es_handle, ES_RenderMode, kRenderTransAlpha );
  144.                 set_es( es_handle, ES_RenderAmt, 85 );
  145.             }
  146.             else if( get_pcvar_num( g_iCvar[2] ) == 2 )
  147.             {
  148.                 set_es( es_handle, ES_Effects, EF_NODRAW );
  149.                 set_es( es_handle, ES_Solid, SOLID_NOT );
  150.             }
  151.         }
  152.     }
  153. }
  154.  
  155. // is there a better way to detect changings of g_iCvar[0]?
  156. public fwdClientCommand( plr )
  157. {
  158.     // use the forwards just when needed, for good performance
  159.     if( !get_pcvar_num( g_iCvar[0] ) && g_bSemiclipEnabled )
  160.     {
  161.         unregister_forward( FM_PlayerPreThink, g_iForwardId[0] );
  162.         unregister_forward( FM_PlayerPostThink, g_iForwardId[1] );
  163.         unregister_forward( FM_AddToFullPack, g_iForwardId[2], 1 );
  164.  
  165.         g_bSemiclipEnabled = false;
  166.     }
  167.     else if( get_pcvar_num( g_iCvar[0] ) && !g_bSemiclipEnabled )
  168.     {
  169.         g_iForwardId[0] = register_forward( FM_PlayerPreThink, "fwdPlayerPreThink" );
  170.         g_iForwardId[1] = register_forward( FM_PlayerPostThink, "fwdPlayerPostThink" );
  171.         g_iForwardId[2] = register_forward( FM_AddToFullPack, "fwdAddToFullPack_Post", 1 );
  172.  
  173.         g_bSemiclipEnabled = true;
  174.     }
  175. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top