Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <hamsandwich>
  4. #include <xs>
  5.  
  6. /*================================================================================
  7. [Constants, Offsets, Macros]
  8. =================================================================================*/
  9.  
  10. // Plugin Version
  11. new const PLUGIN_VERSION[] = "1.0"
  12.  
  13. /*================================================================================
  14. [Global Variables]
  15. =================================================================================*/
  16.  
  17. // Player vars
  18. new g_attacking[33] // get attacking
  19.  
  20. // Game vars
  21. new g_maxplayers // max players counter
  22.  
  23. // Cvar
  24. new cvar_kf1, cvar_kf2
  25.  
  26. // Cached stuff for players
  27. #define is_user_valid_connected(%1) (1 <= %1 <= g_maxplayers && is_user_connected(%1))
  28.  
  29. /*================================================================================
  30. [Precache and Init]
  31. =================================================================================*/
  32.  
  33. public plugin_precache()
  34. {
  35. // Register earlier to show up in plugins list properly after plugin disable/error at loading
  36. register_plugin("Custom Knife Distance", PLUGIN_VERSION, "Fai & Shardow")
  37. }
  38.  
  39. public plugin_init()
  40. {
  41. // Events
  42. register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
  43.  
  44. // FM Forwards
  45. RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "fw_PrimaryAttack")
  46. RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "fw_SecondaryAttack")
  47. RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "fw_PrimaryAttack_Post", 1)
  48. RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "fw_SecondaryAttack_Post", 1)
  49. register_forward(FM_TraceLine, "fw_TraceLine")
  50. register_forward(FM_TraceHull, "fw_TraceHull")
  51.  
  52. // Register Cvar
  53. cvar_kf1 = register_cvar("knife_distance1", "32.0")
  54. cvar_kf2 = register_cvar("knife_distance2", "48.0")
  55.  
  56. // Get Max Players
  57. g_maxplayers = get_maxplayers()
  58. }
  59.  
  60. /*================================================================================
  61. [Main Events]
  62. =================================================================================*/
  63.  
  64. // Event Round Start
  65. public event_round_start()
  66. {
  67. // Show the messages
  68. colored_print(0, "^x04[AlliedModders]^x03 The server running ^"Custom Knife Distance^" Version %d By Fai & Shardow", PLUGIN_VERSION)
  69. colored_print(0, "^x04[AlliedModders]^x03 Slash Distance: %1.f Stab Distance: %1.f", get_pcvar_float(cvar_kf1), get_pcvar_float(cvar_kf2))
  70. colored_print(0, "^x04[AlliedModders]^x03 Newest Version Download: http://forums.alliedmods.net/showthread.php?p=1414241#post1414241")
  71. }
  72.  
  73. /*================================================================================
  74. [Main Forwards]
  75. =================================================================================*/
  76.  
  77. public fw_PrimaryAttack(weapon_ent)
  78. {
  79. // Not valid
  80. if (!pev_valid(weapon_ent))
  81. return;
  82.  
  83. // Get owner
  84. static owner
  85. owner = pev(weapon_ent, pev_owner)
  86.  
  87. // Replace these for zombie only
  88. if (!is_user_valid_connected(owner))
  89. return;
  90.  
  91. g_attacking[owner] = 1
  92. }
  93.  
  94. public fw_SecondaryAttack(weapon_ent)
  95. {
  96. // Not valid
  97. if (!pev_valid(weapon_ent))
  98. return;
  99.  
  100. // Get owner
  101. static owner
  102. owner = pev(weapon_ent, pev_owner)
  103.  
  104. // Replace these for zombie only
  105. if (!is_user_valid_connected(owner))
  106. return;
  107.  
  108. g_attacking[owner] = 2
  109. }
  110.  
  111. public fw_PrimaryAttack_Post(weapon_ent)
  112. {
  113. // Not valid
  114. if (!pev_valid(weapon_ent))
  115. return;
  116.  
  117. // Get owner
  118. static owner
  119. owner = pev(weapon_ent, pev_owner)
  120.  
  121. // Replace these for zombie only
  122. if (!is_user_valid_connected(owner))
  123. return;
  124.  
  125. g_attacking[owner] = 0
  126. }
  127.  
  128. public fw_SecondaryAttack_Post(weapon_ent)
  129. {
  130. // Not valid
  131. if (!pev_valid(weapon_ent))
  132. return;
  133.  
  134. // Get owner
  135. static owner
  136. owner = pev(weapon_ent, pev_owner)
  137.  
  138. // Replace these for zombie only
  139. if (!is_user_valid_connected(owner))
  140. return;
  141.  
  142. g_attacking[owner] = 0
  143. }
  144.  
  145. public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle)
  146. {
  147. // Replace these for zombie only
  148. if (!is_user_valid_connected(id))
  149. return FMRES_IGNORED;
  150.  
  151. // Not alive
  152. if (!is_user_alive(id))
  153. return FMRES_IGNORED;
  154.  
  155. // Not using knife
  156. if (get_user_weapon(id) != CSW_KNIFE)
  157. return FMRES_IGNORED;
  158.  
  159. // Not attacking
  160. if (!g_attacking[id])
  161. return FMRES_IGNORED;
  162.  
  163. pev(id, pev_v_angle, vector_end)
  164. angle_vector(vector_end, ANGLEVECTOR_FORWARD, vector_end)
  165.  
  166. if (g_attacking[id] == 1)
  167. xs_vec_mul_scalar(vector_end, get_pcvar_float(cvar_kf1), vector_end)
  168. else
  169. xs_vec_mul_scalar(vector_end, get_pcvar_float(cvar_kf2), vector_end)
  170.  
  171. xs_vec_add(vector_start, vector_end, vector_end)
  172. engfunc(EngFunc_TraceLine, vector_start, vector_end, ignored_monster, id, handle)
  173.  
  174. return FMRES_SUPERCEDE;
  175. }
  176.  
  177. public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle)
  178. {
  179. // Replace these for zombie only
  180. if (!is_user_valid_connected(id))
  181. return FMRES_IGNORED;
  182.  
  183. // Not alive
  184. if (!is_user_alive(id))
  185. return FMRES_IGNORED;
  186.  
  187. // Not using knife
  188. if (get_user_weapon(id) != CSW_KNIFE)
  189. return FMRES_IGNORED;
  190.  
  191. // Not attacking
  192. if (!g_attacking[id])
  193. return FMRES_IGNORED;
  194.  
  195. pev(id, pev_v_angle, vector_end)
  196. angle_vector(vector_end, ANGLEVECTOR_FORWARD, vector_end)
  197.  
  198. if (g_attacking[id] == 1)
  199. xs_vec_mul_scalar(vector_end, get_pcvar_float(cvar_kf1), vector_end)
  200. else
  201. xs_vec_mul_scalar(vector_end, get_pcvar_float(cvar_kf2), vector_end)
  202.  
  203. xs_vec_add(vector_start, vector_end, vector_end)
  204. engfunc(EngFunc_TraceHull, vector_start, vector_end, ignored_monster, hull, id, handle)
  205.  
  206. return FMRES_SUPERCEDE;
  207. }
  208.  
  209. // Colored print by MeRcyLeZZ
  210. colored_print(target, const message[], any:...)
  211. {
  212. static buffer[512], i, argscount, g_msgSayText
  213. argscount = numargs()
  214. g_msgSayText = get_user_msgid("SayText")
  215.  
  216. // Send to everyone
  217. if (!target)
  218. {
  219. static player
  220. for (player = 1; player <= g_maxplayers; player++)
  221. {
  222. // Not connected
  223. if (!is_user_connected(player))
  224. continue;
  225.  
  226. // Remember changed arguments
  227. static changed[5], changedcount // [5] = max LANG_PLAYER occurencies
  228. changedcount = 0
  229.  
  230. // Replace LANG_PLAYER with player id
  231. for (i = 2; i < argscount; i++)
  232. {
  233. if (getarg(i) == LANG_PLAYER)
  234. {
  235. setarg(i, 0, player)
  236. changed[changedcount] = i
  237. changedcount++
  238. }
  239. }
  240.  
  241. // Format message for player
  242. vformat(buffer, charsmax(buffer), message, 3)
  243.  
  244. // Send it
  245. message_begin(MSG_ONE_UNRELIABLE, g_msgSayText, _, player)
  246. write_byte(player)
  247. write_string(buffer)
  248. message_end()
  249.  
  250. // Replace back player id's with LANG_PLAYER
  251. for (i = 0; i < changedcount; i++)
  252. setarg(changed[i], 0, LANG_PLAYER)
  253. }
  254. }
  255. // Send to specific target
  256. else
  257. {
  258. // Format message for player
  259. vformat(buffer, charsmax(buffer), message, 3)
  260.  
  261. // Send it
  262. message_begin(MSG_ONE, g_msgSayText, _, target)
  263. write_byte(target)
  264. write_string(buffer)
  265. message_end()
  266. }
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement