HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <hamsandwich>
  4.  
  5. #define PLUGIN_NAME "Anti He Bug"
  6. #define PLUGIN_VERSION "1.1"
  7. #define PLUGIN_AUTHOR "Numb"
  8.  
  9. new maxplayers;
  10. new Float:old_gametime;
  11.  
  12. public plugin_init()
  13. {
  14. register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
  15.  
  16. RegisterHam(Ham_Think, "grenade", "Ham_Think_grenade_Pre", 0);
  17.  
  18. register_forward(FM_FindEntityInSphere, "FM_FindEntityInSphere_Pre", 0);
  19.  
  20. maxplayers = get_maxplayers();
  21. }
  22.  
  23. public Ham_Think_grenade_Pre(ent)
  24. {
  25. static model[32];
  26. pev(ent, pev_model, model, 31);
  27. if( equal(model, "models/w_hegrenade.mdl") )
  28. old_gametime = get_gametime();
  29. else
  30. old_gametime = 0.0;
  31. }
  32.  
  33. public FM_FindEntityInSphere_Pre(start, Float:origin[3], Float:radius)
  34. {
  35. if( radius!=350.0 || old_gametime!=get_gametime() )
  36. return FMRES_IGNORED;
  37.  
  38. static hit, trace, Float:ent_origin[3], Float:abs[3], Float:fraction;
  39. hit = start;
  40.  
  41. // run the same check to see what its result will be
  42. while( (hit=engfunc(EngFunc_FindEntityInSphere, hit, origin, radius))>0 )
  43. {
  44. // hit an invalid entery
  45. if( !pev_valid(hit) || is_origin_in_object(origin, hit) )
  46. {
  47. forward_return(FMV_CELL, hit);
  48. return FMRES_SUPERCEDE;
  49. }
  50.  
  51. // aim for the body
  52. get_ent_origin(hit, ent_origin); // get entity origin in professional way
  53. engfunc(EngFunc_TraceLine, origin, ent_origin, DONT_IGNORE_MONSTERS, 0, trace);
  54.  
  55. // hit body, grenade ok
  56. get_tr2(trace, TR_flFraction, fraction);
  57. if( get_tr2(trace, TR_pHit)==hit || (hit>maxplayers && fraction==1.0) )
  58. {
  59. // start backup check (de_dust2 B bug - outmap bug)
  60. engfunc(EngFunc_TraceLine, ent_origin, origin, DONT_IGNORE_MONSTERS, hit, trace);
  61.  
  62. // hit body with backup check
  63. get_tr2(trace, TR_flFraction, fraction);
  64. if( fraction==1.0 )
  65. {
  66. forward_return(FMV_CELL, hit);
  67. return FMRES_SUPERCEDE;
  68. }
  69. }
  70.  
  71. if( hit>maxplayers )
  72. continue;
  73.  
  74. // aim for the head
  75. pev(hit, pev_absmax, abs);
  76. ent_origin[2] = (abs[2]-20.0);
  77. engfunc(EngFunc_TraceLine, origin, ent_origin, DONT_IGNORE_MONSTERS, 0, trace);
  78.  
  79. // hit player head, grenade ok
  80. if( get_tr2(trace, TR_pHit)==hit )
  81. {
  82. // start backup check (de_dust2 B bug - outmap bug)
  83. engfunc(EngFunc_TraceLine, ent_origin, origin, DONT_IGNORE_MONSTERS, hit, trace);
  84.  
  85. // hit player head with backup check
  86. get_tr2(trace, TR_flFraction, fraction);
  87. if( fraction==1.0 )
  88. {
  89. forward_return(FMV_CELL, hit);
  90. return FMRES_SUPERCEDE;
  91. }
  92. }
  93.  
  94. // aim for the feet
  95. pev(hit, pev_absmin, abs);
  96. ent_origin[2] = (abs[2]+20.0);
  97. engfunc(EngFunc_TraceLine, origin, ent_origin, DONT_IGNORE_MONSTERS, 0, trace);
  98.  
  99. // hit player feet, grenade ok
  100. if( get_tr2(trace, TR_pHit)==hit )
  101. {
  102. // start backup check (de_dust2 B bug - outmap bug)
  103. engfunc(EngFunc_TraceLine, ent_origin, origin, DONT_IGNORE_MONSTERS, hit, trace);
  104.  
  105. // hit player feet with backup check
  106. get_tr2(trace, TR_flFraction, fraction);
  107. if( fraction==1.0 )
  108. {
  109. forward_return(FMV_CELL, hit);
  110. return FMRES_SUPERCEDE;
  111. }
  112. }
  113. }
  114.  
  115. // grenade could not hit anything, cancel the check
  116. forward_return(FMV_CELL, -1);
  117. return FMRES_SUPERCEDE;
  118. }
  119.  
  120. /*get_ent_origin(ent, Float:origin[3]) // this is the new way of getting entity origin (supports all entities including offset)
  121. {
  122. static s_fMins_3[3], s_fMaxs_3[3];
  123.  
  124. pev(ent, pev_origin, origin); // first lets get its origin or offset
  125. pev(ent, pev_mins, s_fMins_3);
  126. pev(ent, pev_maxs, s_fMaxs_3);
  127.  
  128. origin[0] += ((s_fMins_3[0]+s_fMaxs_3[0])*0.5); // now with size formating we are adding to offset real entity origin (brush entity case)
  129. origin[1] += ((s_fMins_3[1]+s_fMaxs_3[1])*0.5); // in non brush entity case this format is 0, so to real origin we are adding 0 (nothing changes)
  130. origin[2] += ((s_fMins_3[2]+s_fMaxs_3[2])*0.5);
  131.  
  132. return 1;
  133. }*/
  134.  
  135. get_ent_origin(ent, Float:origin[3]) // this is the new way of getting entity origin (supports all entities including offset)
  136. {
  137. static Float:absmin[3], Float:absmax[3]; // Why I figured it out only now? Why noone of you arent using absolutes???
  138.  
  139. pev(ent, pev_absmin, absmin); // this way works just like one I commented, only this one requires less cpu usage...
  140. pev(ent, pev_absmax, absmax);
  141.  
  142. origin[0] = (absmin[0]+absmax[0])*0.5;
  143. origin[1] = (absmin[1]+absmax[1])*0.5;
  144. origin[2] = (absmin[2]+absmax[2])*0.5;
  145.  
  146. return 1;
  147. }
  148.  
  149. is_origin_in_object(Float:origin[3], ent)
  150. {
  151. static Float:absmin[3], Float:absmax[3];
  152.  
  153. pev(ent, pev_absmin, absmin);
  154. pev(ent, pev_absmax, absmax);
  155.  
  156. if( origin[0]>absmin[0] && origin[0]<absmax[0]
  157. && origin[1]>absmin[1] && origin[1]<absmax[1]
  158. && origin[2]>absmin[2] && origin[2]<absmax[2] )
  159. return 1;
  160.  
  161. return 0;
  162. }
  163.