Advertisement
Garey

Flashbang Things

Jan 23rd, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.12 KB | None | 0 0
  1. /*
  2.     Flashbang Things - by Misz (c) 2016
  3.    
  4.     Includes:
  5.     - Anti Noflash
  6.     - Anti Airflash
  7.     - Chat message when somebody is full flashed (with duration)
  8.     - HUD message for spectators showing how much the player is flashed in %%
  9.    
  10.     Credits to:
  11.     ConnorMcLeod - Nades API (hooking flashbang explosion)
  12.     Rul4 - Anti NoFlash
  13. */
  14.  
  15. #include < amxmodx >
  16. #include < cstrike >
  17. #include < fakemeta >
  18. #include < hamsandwich >
  19. #include < colorchat >
  20. #include < engine >
  21.  
  22. #pragma ctrlchar '\'
  23. #define IsOnLadder(%1) (pev(%1, pev_movetype) == MOVETYPE_FLY)
  24.  
  25. const m_pfnThink = 4;
  26. const m_usEvent_Grenade = 228;
  27. new const Source[3] = {255, 0, 0};  // green
  28. new const Target[3] = {0, 0, 0};  // red
  29.  
  30. const FL_ONGROUND2 = (FL_CONVEYOR|FL_ONGROUND|FL_PARTIALGROUND|FL_INWATER|FL_FLOAT);  
  31.  
  32. new think_Detonate;
  33.  
  34. #define GetThink(%0) get_pdata_int(%0, m_pfnThink, 0)
  35.  
  36. #define HUDMSG_CHANNEL 1
  37. #define HUDMSG_UPDATE_TIME 0.05
  38.  
  39. new g_iMaxPlayers;
  40.  
  41. new Float:g_flFlashUntil[33];
  42. new Float:g_flUpdateTime[33];
  43. new Float:g_flFlashDuration[33];
  44. new Float:g_flFlashHoldTime[33];
  45.  
  46. new g_iCurrentFlasher,g_msgScreenFade;
  47.  
  48. public plugin_init()
  49. {
  50.     register_plugin( "Flashbang Things", "0.5b", "Misz" );
  51.    
  52.     state initializing;
  53.  
  54.     g_iMaxPlayers = get_maxplayers();
  55.    
  56.     register_event( "ScreenFade", "event_blinded", "be", "4=255", "5=255", "6=255", "7=255" );
  57.    
  58.     register_forward( FM_PlayerPreThink, "fwd_PlayerPreThink", 0 );
  59.     register_forward( FM_AddToFullPack, "fwd_AddToFullPack", 0 );
  60.    
  61.     RegisterHam( Ham_Think, "grenade", "fwd_GrenadeThink", false );
  62.    
  63.     g_msgScreenFade = get_user_msgid("ScreenFade")
  64. }
  65.  
  66. public client_putinserver( id )
  67. {
  68.     g_flFlashUntil[id] = g_flUpdateTime[id] = g_flFlashDuration[id] = g_flFlashHoldTime[id] = 0.0;
  69. }
  70.  
  71. public client_disconnect( id )
  72. {
  73.     g_flFlashUntil[id] = g_flUpdateTime[id] = g_flFlashDuration[id] = g_flFlashHoldTime[id] = 0.0;
  74. }
  75.  
  76. public fwd_PlayerPreThink( id ) <initializing> { return FMRES_IGNORED; }
  77.  
  78. public fwd_PlayerPreThink( id ) <initialized>
  79. {
  80.     if( !is_user_alive(id) || cs_get_user_team(id) != CS_TEAM_CT ) return FMRES_IGNORED;
  81.     /*
  82.     if(!(pev(id, pev_flags) & FL_ONGROUND2) && !IsOnLadder(id))
  83.         return FMRES_IGNORED;
  84.     */
  85.     static Float:gametime; gametime = get_gametime();
  86.    
  87.     if( g_flFlashUntil[id] > gametime && g_flUpdateTime[id] < gametime )
  88.     {
  89.         new percent;
  90.         if( g_flFlashHoldTime[id] > gametime )
  91.         {
  92.             percent = 100;
  93.         }
  94.         else
  95.         {
  96.             percent = floatround( ((g_flFlashUntil[id]-gametime)/(g_flFlashUntil[id] - g_flFlashHoldTime[id]))*100, floatround_tozero );
  97.         }
  98.        
  99.         new MyColour[3];
  100.        
  101.         MyColour = Source;
  102.        
  103.         MyColour[0] = Source[0]   + (((Target[0]   - Source[0])   * percent) / 100);
  104.         MyColour[1] = Source[1] + (((Target[1] - Source[1]) * percent) / 100);
  105.         MyColour[2] = Source[2]  + (((Target[2]  - Source[2])  * percent) / 100);
  106.        
  107.         set_hudmessage( MyColour[0], MyColour[1], MyColour[2], 0.04, 0.5, 0, 0.0, 0.5+HUDMSG_UPDATE_TIME, 0.1, 0.1, HUDMSG_CHANNEL );
  108.        
  109.         for( new i = 1; i <= g_iMaxPlayers; i++ )
  110.         {
  111.             if( is_user_spectating_player(i,id) || i == 1)
  112.             {
  113.                 show_hudmessage( i, "Flashed: %d\%", percent );
  114.             }
  115.         }
  116.         g_flUpdateTime[id] = gametime + HUDMSG_UPDATE_TIME;
  117.     }
  118.     return FMRES_IGNORED;
  119. }
  120.  
  121. public fwd_AddToFullPack( es, e, ent, host, flags, player, set ) <initializing> { return FMRES_IGNORED; }
  122.  
  123. public fwd_AddToFullPack( es, e, ent, host, flags, player, set ) <initialized>
  124. {  
  125.     if ( !is_user_alive(host) )
  126.         return FMRES_IGNORED;
  127.        
  128.     if( cs_get_user_team(host) != CS_TEAM_CT )
  129.         return FMRES_IGNORED;
  130.  
  131.     if(player)
  132.     {
  133.         if( !is_user_alive(ent) || ent == host )
  134.             return FMRES_IGNORED;
  135.     }
  136.     else
  137.     {  
  138.         if(pev_valid(ent))
  139.         {
  140.             static Classname[33];
  141.             pev(ent, pev_classname, Classname,32);
  142.             new is_grenade = equal(Classname,"grenade");
  143.    
  144.             if( !is_grenade || pev( ent, pev_owner ) == host )     
  145.                 return FMRES_IGNORED;
  146.    
  147.         } else return FMRES_IGNORED;
  148.     }
  149.     if( get_gametime() < g_flFlashHoldTime[host] )
  150.     {
  151.         forward_return(FMV_CELL, 0);
  152.         return FMRES_SUPERCEDE;
  153.     }
  154.     return FMRES_IGNORED;
  155. }
  156.  
  157. public fwd_GrenadeThink( ent ) <initialized>
  158. {
  159.     if( GetThink(ent) == think_Detonate )
  160.     {
  161.         g_iCurrentFlasher = pev(ent, pev_owner);
  162.     }
  163.     return HAM_IGNORED;
  164. }
  165.  
  166. public fwd_GrenadeThink( ent ) <initializing>
  167. {
  168.     static thinkNum;
  169.     if( isFlashBang2( ent ) == false ) return HAM_IGNORED;
  170.        
  171.     if( thinkNum != 0 && GetThink(ent) != thinkNum )
  172.     {
  173.         think_Detonate = GetThink(ent);
  174.         g_iCurrentFlasher = pev(ent, pev_owner);
  175.         state initialized;
  176.     }
  177.     thinkNum = GetThink(ent);
  178.     return HAM_IGNORED;
  179. }
  180.  
  181. public event_blinded( const id ) <initializing> { return PLUGIN_CONTINUE; }
  182.  
  183. public event_blinded(const id) <initialized>
  184. {
  185.     if(!is_user_alive(id) || !is_user_connected(g_iCurrentFlasher) || id == g_iCurrentFlasher)
  186.         return PLUGIN_HANDLED;
  187.  
  188.     if( cs_get_user_team(g_iCurrentFlasher) != CS_TEAM_T || cs_get_user_team(id) != CS_TEAM_CT)
  189.         return PLUGIN_CONTINUE;
  190.        
  191.     if(!(pev(id, pev_flags) & FL_ONGROUND2) && !IsOnLadder(id) && distance_to_ground(id) > 150.0)
  192.         {
  193.                 message_begin(MSG_ONE, g_msgScreenFade, {0,0,0}, id)
  194.                 write_short(1)
  195.                 write_short(1)
  196.                 write_short(1)
  197.                 write_byte(0)
  198.                 write_byte(0)
  199.                 write_byte(0)
  200.                 write_byte(255)
  201.                 message_end()
  202.                
  203.                 return PLUGIN_CONTINUE;
  204.         }
  205.  
  206.     new flasher[32], name[32];
  207.     get_user_name(g_iCurrentFlasher, flasher, 31);
  208.     get_user_name(id, name, 31);
  209.  
  210.     g_flFlashDuration[id] = read_data(1)/4096.0;
  211.     g_flFlashUntil[id] = get_gametime() + g_flFlashDuration[id];
  212.     g_flFlashHoldTime[id] = get_gametime() + read_data(2)/4096.0;
  213.    
  214.     for( new i = 1; i <= g_iMaxPlayers; i++ )
  215.     {
  216.         if( !is_user_connected(i) ) continue;
  217.         if( i == id )
  218.             ColorChat(i,NORMAL, "Player\x04 %s\x01 flashed\x04 you", flasher);
  219.         else
  220.             ColorChat(i,NORMAL, "Player\x04 %s\x01 flashed\x04 %s\x01 for \x04%.2f\x01 seconds", flasher,name, read_data(2)/4096.0 );
  221.     }
  222.        
  223.     return PLUGIN_CONTINUE
  224. }
  225.  
  226. stock is_user_spectating_player(spectator, player)
  227. {
  228.         if( !is_user_connected(spectator) || !is_user_connected(player) )
  229.                 return 0;
  230.         if( is_user_alive(spectator) || !is_user_alive(player) )
  231.                 return 0;
  232.         if( pev(spectator, pev_deadflag) != 2 )
  233.                 return 0;
  234.        
  235.         static specmode;
  236.         specmode = pev(spectator, pev_iuser1);
  237.         if( specmode == 3 )
  238.                 return 0;
  239.        
  240.         if( pev(spectator, pev_iuser2) == player )
  241.                 return 1;
  242.        
  243.         return 0;
  244. }
  245.  
  246. stock bool:isFlashBang2( ent )
  247. {
  248.     new iBits = get_pdata_int(ent, 114, 5)
  249.     if( !iBits )
  250.     {
  251.         return true;
  252.     }
  253.     return false;
  254. }
  255.  
  256.  
  257. stock Float:distance_to_ground( id )
  258. {
  259.     new Float:start[3], Float:end[3];
  260.     entity_get_vector(id, EV_VEC_origin, start);
  261.     if( entity_get_int(id, EV_INT_flags) & FL_DUCKING )
  262.     {
  263.         start[2] += 18.0;
  264.     }
  265.  
  266.     end[0] = start[0];
  267.     end[1] = start[1];
  268.     end[2] = start[2] - 9999.0;
  269.  
  270.     new ptr = create_tr2();
  271.     engfunc(EngFunc_TraceHull, start, end, IGNORE_MONSTERS, HULL_HUMAN, id, ptr);
  272.     new Float:fraction;
  273.     get_tr2(ptr, TR_flFraction, fraction);
  274.     free_tr2(ptr);
  275.  
  276.     return fraction * 9999.0;
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement