Advertisement
Wonderrrmannn

Strict Enemy Checks

Feb 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. local menu = {
  2. active = ui.new_checkbox("AA", "Other", "Strict enemy checks")
  3. }
  4.  
  5. local function draw_angle(c, name, distance, location_x, location_y, location_z, origin_x, origin_y, yaw, r, g, b, a)
  6. local location_x_angle = location_x + math.cos(math.rad(yaw)) * distance
  7. local location_y_angle = location_y + math.sin(math.rad(yaw)) * distance
  8.  
  9. local world_x, world_y = client.world_to_screen(c, location_x_angle, location_y_angle, location_z)
  10.  
  11. if world_x ~= nil then
  12. client.draw_line(c, origin_x, origin_y, world_x, world_y, r, g, b, 220)
  13. client.draw_text(c, world_x, world_y, r, g, b, a, "c-", 0, name)
  14. end
  15. end
  16.  
  17. local function calc_angle(x_src, y_src, z_src, x_dst, y_dst, z_dst)
  18. x_delta = x_src - x_dst
  19. y_delta = y_src - y_dst
  20. z_delta = z_src - z_dst
  21. hyp = math.sqrt(x_delta^2 + y_delta^2)
  22. x = math.atan2(z_delta, hyp) * 57.295779513082
  23. y = math.atan2( y_delta , x_delta) * 180 / 3.14159265358979323846
  24.  
  25. if y > 180 then
  26. y = y - 180
  27. end
  28. if y < -180 then
  29. y = y + 180
  30. end
  31. return y
  32. end
  33.  
  34. local function normalize_angles(angle)
  35. angle = angle % 360
  36. angle = (angle + 360) % 360
  37. if (angle > 180) then
  38. angle = angle - 360
  39. end
  40.  
  41. return angle
  42. end
  43.  
  44. local function get_near_target()
  45. local enemy_players = entity.get_players(true)
  46. if #enemy_players ~= 0 then
  47. local own_x, own_y, own_z = client.eye_position()
  48. local own_pitch, own_yaw = client.camera_angles()
  49. local closest_enemy = nil
  50. local closest_distance = 999999999
  51.  
  52. for i = 1, #enemy_players do
  53. local enemy = enemy_players[i]
  54. local enemy_x, enemy_y, enemy_z = entity.get_prop(enemy, "m_vecOrigin")
  55.  
  56. local x = enemy_x - own_x
  57. local y = enemy_y - own_y
  58. local z = enemy_z - own_z
  59.  
  60. local yaw = ((math.atan2(y, x) * 180 / math.pi))
  61. local pitch = -(math.atan2(z, math.sqrt(math.pow(x, 2) + math.pow(y, 2))) * 180 / math.pi)
  62.  
  63. local yaw_dif = math.abs(own_yaw % 360 - yaw % 360) % 360
  64. local pitch_dif = math.abs(own_pitch - pitch ) % 360
  65.  
  66. if yaw_dif > 180 then yaw_dif = 360 - yaw_dif end
  67. local real_dif = math.sqrt(math.pow(yaw_dif, 2) + math.pow(pitch_dif, 2))
  68.  
  69. if closest_distance > real_dif then
  70. closest_distance = real_dif
  71. closest_enemy = enemy
  72. end
  73. end
  74.  
  75. if closest_enemy ~= nil then
  76. return closest_enemy, closest_distance
  77. end
  78. end
  79.  
  80. return nil, nil
  81. end
  82.  
  83. -- CALLBACK
  84. g_pLocal = entity.get_local_player()
  85. local threat_id, threat_dist = get_near_target()
  86.  
  87. if ui_get(menu.active) and (threat_dist and threat_dist <= 15) then
  88. local x, y, z = entity.get_prop(g_pLocal, "m_vecOrigin")
  89.  
  90. if x ~= nil then
  91. local ent_x, ent_y, ent_z = entity.hitbox_position(threat_id, 0)
  92. angle = calc_angle(x, y, z, ent_x, ent_y, ent_z) + 180
  93.  
  94. if isLeft then
  95. angle = angle - 130
  96. elseif isRight then
  97. angle = angle + 31
  98. end
  99.  
  100. ui_set(aa_yaw, "Static")
  101. ui_set(aa_num, normalize_angles(angle))
  102. is_targeting = true
  103.  
  104. client.draw_text(c, 12, 700, 243, 125, 124, 255, "-", "200", "THREAT: ", string.upper(entity.get_player_name(threat_id)))
  105. client.draw_text(c, 12, 710, 255, 255, 255, 255, "-", "200", "DISTANCE: ", round(threat_dist, 0) .. " FT")
  106. client.draw_text(c, 12, 720, 255, 255, 255, 255, "-", "200", "ANGLE: ", round(angle, 1))
  107. end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement