HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <engine>
  4. #include <zombieplague>
  5.  
  6. #define CUSTOM_MODELS 1
  7. #define MAX_KNIFE_SNDS 9
  8.  
  9. #if (CUSTOM_MODELS)
  10. new MODEL_PLAYER[] = "models/v_bknuckles.mdl"
  11. #endif
  12.  
  13. #define PLUGIN "MoJloT Knockback"
  14. #define VERSION "1.0"
  15. #define AUTHOR "Van"
  16.  
  17. new zp_knife_sound;
  18.  
  19. new cvar_knife , cvar_knock , cvar_jump , cvar_sound , cvar_survivor;
  20.  
  21. public plugin_init()
  22. {
  23. register_plugin(PLUGIN , VERSION , AUTHOR);
  24. register_cvar("zp_knife", VERSION, FCVAR_SERVER);
  25. register_event("Damage" , "event_Damage" , "b" , "2>0");
  26. register_event( "CurWeapon", "Event_CurWeapon", "be", "1=1" );
  27. register_event("HLTV", "event_round_start", "a");
  28. register_forward(FM_EmitSound, "fw_EmitSound");
  29.  
  30. cvar_knife = register_cvar("zp_knife_knock" , "1");
  31. cvar_knock = register_cvar("zp_knife_power" , "10");
  32. cvar_jump = register_cvar("zp_knife_jump", "300.0");
  33. cvar_sound = register_cvar("zp_knife_sound" , "1");
  34. cvar_survivor = register_cvar("zp_knife_survivor" , "1");
  35. }
  36.  
  37. public event_round_start()
  38. {
  39. if (get_pcvar_num(cvar_sound) == 1)
  40. zp_knife_sound = true;
  41. else
  42. zp_knife_sound = false;
  43. }
  44.  
  45. public event_Damage(id)
  46. {
  47. if(!get_pcvar_num(cvar_knife))
  48. return PLUGIN_CONTINUE;
  49.  
  50. if(!is_user_alive(id))
  51. return PLUGIN_CONTINUE;
  52.  
  53. if(zp_is_survivor_round() && get_pcvar_num(cvar_survivor) == 0)
  54. return PLUGIN_CONTINUE;
  55.  
  56. new weapon , attacker = get_user_attacker(id , weapon);
  57.  
  58. if(!is_user_alive(attacker))
  59. return PLUGIN_CONTINUE;
  60.  
  61. if(weapon == CSW_KNIFE)
  62. {
  63. new Float:vec[3];
  64. new Float:oldvelo[3];
  65. get_user_velocity(id, oldvelo);
  66. create_velocity_vector(id , attacker , vec);
  67. vec[0] += oldvelo[0];
  68. vec[1] += oldvelo[1];
  69. set_user_velocity(id , vec);
  70. }
  71.  
  72. return PLUGIN_CONTINUE;
  73. }
  74.  
  75. public Event_CurWeapon( id )
  76. {
  77. if (!is_user_connected(id) || !is_user_alive(id) || zp_get_user_zombie(id))
  78. return PLUGIN_CONTINUE
  79.  
  80. new WeaponID = read_data(2)
  81. if (WeaponID != CSW_KNIFE)
  82. return PLUGIN_CONTINUE
  83.  
  84. #if (CUSTOM_MODELS)
  85. entity_set_string(id, EV_SZ_weaponmodel, MODEL_PLAYER)
  86. #endif
  87.  
  88. return PLUGIN_CONTINUE;
  89. }
  90.  
  91. stock create_velocity_vector(victim,attacker,Float:velocity[3])
  92. {
  93. if(!zp_get_user_zombie(victim) || !is_user_alive(attacker))
  94. return 0;
  95.  
  96. new Float:vicorigin[3];
  97. new Float:attorigin[3];
  98. entity_get_vector(victim , EV_VEC_origin , vicorigin);
  99. entity_get_vector(attacker , EV_VEC_origin , attorigin);
  100.  
  101. new Float:origin2[3]
  102. origin2[0] = vicorigin[0] - attorigin[0];
  103. origin2[1] = vicorigin[1] - attorigin[1];
  104.  
  105. new Float:largestnum = 0.0;
  106.  
  107. if(floatabs(origin2[0])>largestnum) largestnum = floatabs(origin2[0]);
  108. if(floatabs(origin2[1])>largestnum) largestnum = floatabs(origin2[1]);
  109.  
  110. origin2[0] /= largestnum;
  111. origin2[1] /= largestnum;
  112.  
  113. velocity[0] = ( origin2[0] * (get_pcvar_float(cvar_knock) * 3000) ) / get_entity_distance(victim , attacker);
  114. velocity[1] = ( origin2[1] * (get_pcvar_float(cvar_knock) * 3000) ) / get_entity_distance(victim , attacker);
  115. if(velocity[0] <= 20.0 || velocity[1] <= 20.0)
  116. velocity[2] = random_float(200.0 , 275.0);
  117.  
  118. return 1;
  119. }
  120.  
  121. new knife_sounds_o[MAX_KNIFE_SNDS][] =
  122. {
  123. "weapons/knife_deploy1.wav",
  124. "weapons/knife_hit1.wav",
  125. "weapons/knife_hit2.wav",
  126. "weapons/knife_hit3.wav",
  127. "weapons/knife_hit4.wav",
  128. "weapons/knife_hitwall1.wav",
  129. "weapons/knife_slash1.wav",
  130. "weapons/knife_slash2.wav",
  131. "weapons/knife_stab.wav"
  132. }
  133.  
  134. new knife_sounds_r[MAX_KNIFE_SNDS][] =
  135. {
  136. "zombie_plague/knife_deploy1.wav",
  137. "zombie_plague/knife_hit1.wav",
  138. "zombie_plague/knife_hit2.wav",
  139. "zombie_plague/knife_hit3.wav",
  140. "zombie_plague/knife_hit4.wav",
  141. "zombie_plague/knife_hitwall1.wav",
  142. "zombie_plague/knife_slash1.wav",
  143. "zombie_plague/knife_slash2.wav",
  144. "zombie_plague/knife_stab.wav"
  145. }
  146.  
  147. public plugin_precache()
  148. {
  149. for(new i = 0; i < MAX_KNIFE_SNDS; i++)
  150. precache_sound(knife_sounds_r[i]);
  151.  
  152. #if (CUSTOM_MODELS)
  153. precache_model(MODEL_PLAYER)
  154. #endif
  155. }
  156.  
  157. public EmitSound(entity, channel, const sound[])
  158. {
  159. if(pev_valid(entity) && is_user_alive(entity))
  160. {
  161. for(new i = 0; i < MAX_KNIFE_SNDS; i++)
  162. {
  163. if(equal(sound , knife_sounds_o[i]))
  164. {
  165. if (zp_knife_sound) emit_sound(entity, channel, knife_sounds_r[i], 1.0, ATTN_NORM, 0, PITCH_NORM);
  166. return FMRES_SUPERCEDE;
  167. }
  168. }
  169. }
  170. return FMRES_IGNORED;
  171. }
  172.  
  173. public client_PreThink(id)
  174. {
  175. if (!is_user_connected(id) || !is_user_alive(id) || zp_get_user_zombie(id))
  176. return PLUGIN_CONTINUE
  177.  
  178. new temp[2], weapon = get_user_weapon(id, temp[0], temp[1])
  179. if (weapon != CSW_KNIFE)
  180. return PLUGIN_CONTINUE
  181.  
  182. if ((get_user_button(id) & IN_JUMP) && !(get_user_oldbutton(id) & IN_JUMP))
  183. {
  184. new flags = entity_get_int(id, EV_INT_flags)
  185. new waterlvl = entity_get_int(id, EV_INT_waterlevel)
  186.  
  187. if (!(flags & FL_ONGROUND))
  188. return PLUGIN_CONTINUE
  189. if (flags & FL_WATERJUMP)
  190. return PLUGIN_CONTINUE
  191. if (waterlvl > 1)
  192. return PLUGIN_CONTINUE
  193.  
  194. new Float:fVelocity[3]
  195. entity_get_vector(id, EV_VEC_velocity, fVelocity)
  196. fVelocity[2] += get_pcvar_num(cvar_jump)
  197.  
  198. entity_set_vector(id, EV_VEC_velocity, fVelocity)
  199. entity_set_int(id, EV_INT_gaitsequence, 6)
  200. }
  201. return PLUGIN_CONTINUE;
  202. }
  203.  
  204.