Garey

HNS Block Return

Mar 19th, 2019
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.62 KB | None | 0 0
  1. /*
  2.  *
  3.  * HNS Block Return 0.3
  4.  *
  5.  * Copyright 2018 Garey <ggarey@ya.ru>
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20.  * MA 02110-1301, USA.
  21.  *
  22.  *
  23.  */
  24.  
  25. #include <amxmodx>
  26. #include <fakemeta>
  27. #include <hamsandwich>
  28.  
  29. new Array:g_arFlPlayerOrigin[33];
  30. new Array:g_arFlPlayerAngle[33];
  31.  
  32. new bool:g_bIsTouched[33];
  33. new bool:g_bIsBlocked[33];
  34.  
  35. new iToucher[33];
  36. new g_iMaxPlayers;
  37.  
  38. /*! Cvars */
  39. new g_cFX;
  40. new g_cTeam;
  41.  
  42. public plugin_precache()
  43. {
  44.     precache_sound("ambience/rewind.wav")
  45. }
  46.  
  47. public plugin_init()
  48. {
  49.     register_plugin("Block Return", "0.3", "Garey");
  50.  
  51.     g_cFX   = register_cvar("hns_block_fx", "1");
  52.     g_cTeam = register_cvar("hns_block_team", "0");
  53.  
  54.     g_iMaxPlayers = get_maxplayers();
  55.  
  56.     for(new i = 1; i <= g_iMaxPlayers; i++)
  57.     {
  58.         g_arFlPlayerOrigin[i] = ArrayCreate(3);
  59.         g_arFlPlayerAngle[i] = ArrayCreate(3);
  60.     }
  61.  
  62.     RegisterHam( Ham_Player_PreThink, "player", "fwd_PlayerPreThink", 0 );
  63.     RegisterHam( Ham_Touch, "player", "fwd_TouchPlayer", 0 );
  64.     RegisterHam( Ham_TakeDamage, "player", "Ham_TakeDamagePlayer" );
  65. }
  66.  
  67. public fwd_TouchPlayer( id, entity )
  68. {
  69.     if(get_pcvar_num(g_cTeam) == 1) {
  70.         if( get_user_team( id ) != 2 || !is_user_alive( entity ))
  71.             return;
  72.  
  73.         if( get_user_team( entity ) != 1 )
  74.             return;
  75.     }
  76.  
  77.     new flVelocity[3]
  78.     pev(id, pev_velocity, flVelocity);
  79.     // Check if player was in Air
  80.     if(flVelocity[2] != 0.0)
  81.     {
  82.         g_bIsTouched[id] = true;
  83.         iToucher[id] = entity;
  84.     }
  85. }
  86.  
  87.  
  88. public Ham_TakeDamagePlayer(iVictim, iInflictor, iAttacker, Float:flDamage, iDamageBits)
  89. {
  90.     if( is_user_alive(iVictim) && flDamage >= 50.0 && iDamageBits & DMG_FALL )
  91.     {  
  92.         if(get_pcvar_num(g_cTeam) == 1) {
  93.             if( get_user_team(iVictim) == 2 )
  94.             {
  95.                 if(g_bIsTouched[iVictim] && is_user_alive(iToucher[iVictim]))
  96.                 {
  97.                     iToucher[iVictim] = 0;
  98.                     g_bIsBlocked[iVictim] = true;
  99.  
  100.                     if(get_pcvar_num(g_cFX))
  101.                         emit_sound(iVictim, CHAN_AUTO, "ambience/rewind.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
  102.                        
  103.                     set_pev(iVictim, pev_movetype, MOVETYPE_NOCLIP)
  104.                     return HAM_SUPERCEDE;
  105.                 }
  106.             }
  107.         } else {
  108.             if(g_bIsTouched[iVictim] && is_user_alive(iToucher[iVictim]))
  109.             {
  110.                 iToucher[iVictim] = 0;
  111.                 g_bIsBlocked[iVictim] = true;
  112.  
  113.                 if(get_pcvar_num(g_cFX))
  114.                     emit_sound(iVictim, CHAN_AUTO, "ambience/rewind.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
  115.  
  116.                 set_pev(iVictim, pev_movetype, MOVETYPE_NOCLIP)
  117.                 return HAM_SUPERCEDE;
  118.             }
  119.         }
  120.     }
  121.  
  122.     return HAM_IGNORED;
  123. }
  124.  
  125. public fwd_PlayerPreThink( id )
  126. {
  127.     static flPlayerOrigin[3], flPlayerAngles[3], LastFrames[33]
  128.  
  129.     if(is_user_alive(id))
  130.     {
  131.         if(!g_bIsBlocked[id])
  132.         {
  133.             pev(id, pev_origin, flPlayerOrigin);
  134.             pev(id, pev_v_angle, flPlayerAngles);
  135.  
  136.             if((pev(id, pev_flags) & FL_ONGROUND) || pev(id, pev_movetype) == MOVETYPE_FLY)
  137.             {
  138.                 if(LastFrames[id] > 10)
  139.                 {
  140.                     g_bIsTouched[id] = false;
  141.                     ArrayClear(g_arFlPlayerOrigin[id]);
  142.                     ArrayClear(g_arFlPlayerAngle[id]);
  143.                     LastFrames[id] = 0;
  144.                 }
  145.                 else
  146.                 {
  147.                     ArrayPushArray(g_arFlPlayerOrigin[id], flPlayerOrigin);
  148.                     ArrayPushArray(g_arFlPlayerAngle[id], flPlayerAngles);
  149.                     LastFrames[id]++;
  150.                 }
  151.             }
  152.             else
  153.             {
  154.                 ArrayPushArray(g_arFlPlayerOrigin[id], flPlayerOrigin);
  155.                 ArrayPushArray(g_arFlPlayerAngle[id], flPlayerAngles);
  156.             }
  157.         }
  158.         else
  159.         {
  160.             new Length = ArraySize(g_arFlPlayerOrigin[id]) - 1;
  161.  
  162.             if(Length)
  163.             {
  164.                 ArrayGetArray(g_arFlPlayerOrigin[id], Length, flPlayerOrigin);
  165.                 ArrayGetArray(g_arFlPlayerAngle[id], Length, flPlayerAngles);
  166.  
  167.                 ArrayDeleteItem(g_arFlPlayerOrigin[id], Length);
  168.                 ArrayDeleteItem(g_arFlPlayerAngle[id], Length);
  169.  
  170.                 set_pev(id, pev_origin, flPlayerOrigin);
  171.                 set_pev(id, pev_angles, flPlayerAngles);
  172.                 set_pev(id, pev_fixangle, 1);
  173.             }
  174.             else
  175.             {
  176.                 set_pev(id, pev_movetype, MOVETYPE_WALK);
  177.                 set_pev(id, pev_velocity, Float:{ 0.0, 0.0, 0.0 });
  178.                 set_pev(id, pev_flags, pev(id,pev_flags) | FL_DUCKING);
  179.                 g_bIsBlocked[id] = false;
  180.             }
  181.         }
  182.     }
  183.     else
  184.     {
  185.         LastFrames[id] = 0;
  186.     }
  187. }
Add Comment
Please, Sign In to add comment