it300

anti-aimbot(alpha)

Nov 20th, 2020 (edited)
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.82 KB | None | 0 0
  1. api_version = "1.10.0.0"
  2.  
  3. -- Setting this higher will make the script pick up players aiming closer to others
  4. -- more often but will make the script highly inaccurate. Do not go above 0.015.
  5. autoaim_sensitivity = 0.04
  6.  
  7. -- Setting this lower will change the minimum sensitivity to detect a player aiming at
  8. -- another player.  Below 0.035 the script cannot read headshots accurately.
  9. -- DO NOT SET THIS HIGHER THAN autoaim_sensitivity EVER!
  10. autoaim_baseline_sensitivity = 0.004
  11.  
  12. -- Minimum snap to trigger a snapped scoring event.
  13. snap_baseline_sensitivity = 6
  14.  
  15. aimbot_max_score = 3000
  16.  
  17. Mode = "k" -- name of command
  18. Reason = "Aimbot!"
  19.  
  20. standing_height = 0.64
  21. crouch_height = 0.35
  22. camera_table = {}
  23. aimbot_score = {}
  24. aiming_at = {}
  25. spawned = {}
  26.  
  27. function OnScriptLoad()
  28.     register_callback(cb['EVENT_TICK'], "OnEventTick")
  29.     register_callback(cb['EVENT_DIE'], "OnPlayerDeath")
  30.     register_callback(cb['EVENT_SPAWN'], "OnPlayerSpawn")
  31.     register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
  32.     for i = 1,16 do
  33.         aiming_at[i] = 0
  34.         aimbot_score[i] = 0
  35.     end
  36. end
  37.  
  38. function OnScriptUnload() end
  39.  
  40. function OnPlayerLeave(PlayerIndex)
  41.     aimbot_score[tonumber(PlayerIndex)] = 0
  42. end
  43.  
  44. function OnPlayerSpawn(PlayerIndex)
  45.     spawned[tonumber(PlayerIndex)] = true
  46. end
  47.  
  48. function OnPlayerDeath(VictimIndex, KillerIndex)
  49.     camera_table[tonumber(VictimIndex)] = nil
  50. end
  51.  
  52. function OnEventTick()
  53.     for i = 1,16 do
  54.         if player_present(i) then
  55.             if aimbot_score[i] > 1 then
  56.                 aimbot_score[i] = aimbot_score[i] - 0.25
  57.             end
  58.         end
  59.         if player_alive(i) then
  60.             local m_object = get_dynamic_player(i)
  61.             if m_object ~= 0 then
  62.                 OnAimbotCheck(i, m_object)
  63.             end
  64.         end
  65.     end
  66. end
  67.  
  68. function OnAimbotCheck(PlayerIndex, m_object)
  69.     local scoring = false
  70.     local x, y, z = read_vector3d(m_object + 0x230)
  71.     local stop_angle = get_stop_angle(PlayerIndex, m_object)
  72.     if spawned[PlayerIndex] then stop_angle = 0 spawned[PlayerIndex] = false end
  73.     local team = get_team(PlayerIndex)
  74.     for j = 0,16 do
  75.         if j ~= PlayerIndex and get_team(j) ~= team then
  76.             local TargetIndex, Distance, vx, vy, vz = IsLookingAt(PlayerIndex, j)
  77.             if TargetIndex ~= nil then
  78.                 local player_hit = intersect_to_player(m_object, PlayerIndex, vx, vy, vz)
  79.                 local score = math.floor(aiming_at[PlayerIndex] * Distance) * 0.0015
  80.                 if stop_angle > snap_baseline_sensitivity then
  81.                     aiming_at[PlayerIndex] = aiming_at[PlayerIndex] + 1
  82.                     scoring = true
  83.                     if player_hit then
  84.                         score = score +  stop_angle * 5
  85.                     else
  86.                         score = score +  stop_angle * 15
  87.                     end
  88.                 else
  89.                     local moving = velocity(PlayerIndex)
  90.                     if moving > 0 and stop_angle > 0 and stop_angle < 0.4 then
  91.                         aiming_at[PlayerIndex] = aiming_at[PlayerIndex] + 1
  92.                         scoring = true
  93.                         if player_hit then
  94.                             score = score + 4
  95.                         else
  96.                             score = score + 10
  97.                         end
  98.                     end
  99.                 end
  100.                 aimbot_score[PlayerIndex] = aimbot_score[PlayerIndex] + score
  101.                 break
  102.             end
  103.         end
  104.     end
  105.     if aimbot_score[PlayerIndex] > aimbot_max_score then
  106.         execute_command(Mode .. " " .. PlayerIndex .. ' "'..Reason..'"')
  107.     end
  108.     if not scoring then
  109.         aiming_at[PlayerIndex] = 0
  110.     end
  111. end
  112.  
  113. function get_team(PlayerIndex)
  114.     local m_player = get_player(PlayerIndex)
  115.     if m_player ~= 0 then
  116.         return read_byte(m_player + 0x20)
  117.     end
  118.     return -1
  119. end
  120.  
  121. function velocity(PlayerIndex)
  122.     local m_object = get_dynamic_player(PlayerIndex)
  123.     if m_object ~= 0 then
  124.         local xv, yv, zv = read_vector3d(m_object + 0x278)
  125.         return math.abs(xv) + math.abs(yv)
  126.     end
  127.     return 0
  128. end
  129.  
  130. function get_stop_angle(PlayerIndex, m_object)
  131.     local x_aim, y_aim, z_aim = read_vector3d(m_object + 0x230)
  132.  
  133.     if camera_table[PlayerIndex] == nil then
  134.         camera_table[PlayerIndex] = {x_aim, y_aim, z_aim}
  135.         return 0
  136.     end
  137.  
  138.     local last_camera_x = camera_table[PlayerIndex][1]
  139.     local last_camera_y = camera_table[PlayerIndex][2]
  140.     local last_camera_z = camera_table[PlayerIndex][3]
  141.  
  142.     camera_table[PlayerIndex] = {x_aim, y_aim, z_aim}
  143.  
  144.     if  last_camera_x == 0 and
  145.         last_camera_y == 0 and
  146.         last_camera_z == 0 then
  147.         return 0
  148.     end
  149.  
  150.     local movement = math.sqrt(
  151.         (x_aim - last_camera_x) ^ 2 +
  152.         (y_aim - last_camera_y) ^ 2 +
  153.         (z_aim - last_camera_z) ^ 2)
  154.  
  155.     local angle = math.acos((2 - movement ^ 2) / 2)
  156.     stop_angle = angle * 180 / math.pi
  157.  
  158.     return stop_angle
  159. end
  160.  
  161. function intersect_to_player(m_object, PlayerIndex, vx, vy, vz)
  162.     local crouch_state = read_float(m_object + 0x50C)
  163.     local x, y, z = read_vector3d(m_object + 0x5c) -- Player Location
  164.  
  165.     if (crouch_state == 0) then
  166.         z = z + standing_height
  167.     else
  168.         z = z + crouch_height
  169.     end
  170.  
  171.     local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
  172.     local hit, cx, cy, cz, ObjectID = intersect(x, y, z, vx*250, vy*250, vz*250, player_object_id)
  173.  
  174.     for i = 1,16 do
  175.         if player_alive(i) and i ~= PlayerIndex then -- Can they be aimed at?
  176.             if get_object_memory(ObjectID) == get_dynamic_player(i) then -- Are we aiming at a player
  177.                 return true
  178.             end
  179.         end
  180.     end
  181.     return false
  182. end
  183.  
  184. function IsLookingAt(PlayerIndex, TargetIndex)
  185.     local m_player = get_player(PlayerIndex)
  186.     local m_target = get_player(TargetIndex)
  187.     local m_object = get_dynamic_player(PlayerIndex)
  188.     local m_target_object = get_dynamic_player(TargetIndex)
  189.  
  190.     if m_object == 0 or m_target_object == 0 then
  191.         return
  192.     end
  193.  
  194.     -- PlayerIndex
  195.     local crouch_state = read_float(m_object + 0x50C)
  196.     local camera_x, camera_y, camera_z = read_vector3d(m_object + 0x230)
  197.     local player_x, player_y, player_z = read_vector3d(m_object + 0x5c) -- Player Location
  198.  
  199.     if (crouch_state == 0) then -- We need to adjust for crouching and standing heights.
  200.         player_z = player_z + standing_height
  201.     else
  202.         player_z = player_z + crouch_height
  203.     end
  204.  
  205.     -- TargetIndex
  206.     local target_x, target_y, target_z = read_vector3d((m_target_object + 0x7C0) + 0x28) -- Player Location
  207.  
  208.     local radius = math.sqrt((target_x - player_x)^2 + (target_y - player_y)^2 + (target_z - player_z)^2)
  209.  
  210.     local local_x = target_x - player_x
  211.     local local_y = target_y - player_y
  212.     local local_z = target_z - player_z
  213.  
  214.     local point_x = 1 / radius * local_x
  215.     local point_y = 1 / radius * local_y
  216.     local point_z = 1 / radius * local_z
  217.  
  218.     local x_diff = math.abs(camera_x - point_x)
  219.     local y_diff = math.abs(camera_y - point_y)
  220.     local z_diff = math.abs(camera_z - point_z)
  221.  
  222.     local scaler = 0
  223.     if radius > 10 then
  224.         scaler = tonumber("0.00" .. math.floor(radius)) * 10
  225.     end
  226.  
  227.     local auto_aim = autoaim_sensitivity - scaler
  228.     if auto_aim < autoaim_baseline_sensitivity then auto_aim = autoaim_baseline_sensitivity  end
  229.  
  230.     if x_diff <= auto_aim and y_diff <= auto_aim and z_diff <= auto_aim then
  231.         return TargetIndex, radius, point_x, point_y, point_z
  232.     end
  233.  
  234.     return nil, 0, 0, 0, 0
  235. end
  236.  
  237. function getname(PlayerIndex)
  238.     if get_player(PlayerIndex) then
  239.         local name = get_var(PlayerIndex, "$name")
  240.         return name
  241.     end
  242.     return nil
  243. end
  244.  
  245.  
Advertisement
Add Comment
Please, Sign In to add comment