HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include <amxmodx>
  4. #include <amxmisc>
  5. #include <hamsandwich>
  6. #include <engine>
  7. #include <fakemeta>
  8.  
  9. #define PLUGIN "Minecraft Knives"
  10. #define VERSION "1.0.2"
  11. #define AUTHOR "Kia"
  12.  
  13. // ===============================================================================
  14. // Variables
  15. // ===============================================================================
  16.  
  17. new const g_szOldSounds[][] =
  18. {
  19. "weapons/knife_hit1.wav",
  20. "weapons/knife_hit2.wav",
  21. "weapons/knife_hit3.wav",
  22. "weapons/knife_hit4.wav"
  23. }
  24.  
  25. new const g_szHitSounds[][] =
  26. {
  27. "minecraftknives/hit1.wav",
  28. "minecraftknives/hit2.wav",
  29. "minecraftknives/hit3.wav"
  30. }
  31.  
  32.  
  33. /* Pointers */
  34.  
  35. new g_pKnockBack
  36.  
  37. // ===============================================================================
  38. // plugin_precache
  39. // ===============================================================================
  40.  
  41. public plugin_precache()
  42. {
  43. for(new i = 0; i < sizeof(g_szHitSounds); i++)
  44. precache_sound(g_szHitSounds[i])
  45. }
  46.  
  47. // ===============================================================================
  48. // plugin_init
  49. // ===============================================================================
  50.  
  51. public plugin_init()
  52. {
  53. register_plugin(PLUGIN, VERSION, AUTHOR)
  54.  
  55. /* CVars */
  56.  
  57. g_pKnockBack = register_cvar("mk_knockback", "15")
  58.  
  59. /* Hamsandwich */
  60.  
  61. RegisterHam(Ham_TakeDamage, "player", "Ham_PlayerTakeDamagePost", true);
  62. RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "Ham_KnifeSecondaryAttackPre")
  63.  
  64. /* Forwards */
  65.  
  66. register_forward(FM_EmitSound , "Forward_EmitSound");
  67. }
  68.  
  69. // ===============================================================================
  70. // Ham_PlayerTakeDamagePost - Called after a player got damage
  71. // ===============================================================================
  72.  
  73. public Ham_PlayerTakeDamagePost(id, iInflictor, iAttacker, Float:flDamage, iDmgBits)
  74. {
  75. if(iAttacker != iInflictor
  76. || !is_user_alive(id)
  77. || !is_user_alive(iAttacker)
  78. || get_user_weapon(iAttacker) != CSW_KNIFE)
  79. return HAM_IGNORED
  80.  
  81. //client_cmd(iInflictor, "spk %s", g_szHitSounds[random_num(0, sizeof(g_szHitSounds))])
  82.  
  83. new Float:flVec[2][3]
  84.  
  85. entity_get_vector ( iAttacker, EV_VEC_origin, flVec[0] )
  86. entity_get_vector ( id, EV_VEC_origin, flVec[1] )
  87.  
  88. for ( new i = 0; i < 2; i++ )
  89. {
  90. flVec[1][i] -= flVec[0][i]
  91. flVec[1][i] *= get_pcvar_num(g_pKnockBack)
  92. }
  93.  
  94. entity_set_vector ( id, EV_VEC_velocity, flVec[1] )
  95.  
  96. return HAM_HANDLED
  97. }
  98.  
  99. // ===============================================================================
  100. // Ham_KnifeSecondaryAttackPre - Credits to wbyokomo
  101. // ===============================================================================
  102.  
  103. public Ham_KnifeSecondaryAttackPre(iEnt)
  104. {
  105. ExecuteHamB(Ham_CS_Weapon_SendWeaponAnim, iEnt, 0, 0)
  106. return HAM_SUPERCEDE;
  107. }
  108.  
  109. // ===============================================================================
  110. // Forward_EmitSound
  111. // ===============================================================================
  112.  
  113. public Forward_EmitSound(iEnt, iChan, const szSound[])
  114. {
  115. if(pev_valid(iEnt) && is_user_alive(iEnt))
  116. {
  117. for(new i = 0; i < sizeof(g_szOldSounds); i++)
  118. {
  119. if(equal(szSound , g_szOldSounds[i]))
  120. {
  121. emit_sound(iEnt, iChan, g_szHitSounds[random_num(0, sizeof(g_szHitSounds))], 1.0, ATTN_NORM, 0, PITCH_NORM);
  122. return FMRES_SUPERCEDE;
  123. }
  124. }
  125. }
  126.  
  127. return FMRES_IGNORED;
  128. }
  129.