LUA 173
V2+ Anti-Aimbot 4.1 By xdedeone on 25th February 2019 09:53:51 PM
  1. ----------------------------------------------------------------------------
  2. ----------------- Anti-Aimbot Script v4.1.1 for Phasor 2.0 -----------------
  3. ------ Thanks to Wizard for helping add aiming though wall detection -------
  4. ----- and optimizing the script so that it can run faster. Also thanks -----
  5. -------- to all the other people who helped make & test this script --------
  6. --------------------- Creator(s): Skylace & Wizard -------------------------
  7. ----------------------------------------------------------------------------
  8.  
  9. -- At what aimbot score should we take an action on the player?
  10. -- I recommend anywhere from 1500 to 5000.
  11. local max_score = 2000
  12.  
  13. -- What action to take when a player has been detected as a bot?
  14. local action = "ban"
  15.  
  16. -- Time to ban a player (in minutes.)
  17. local ban_time = "1440"
  18.  
  19. -- Minimum stop angle to be considered a snap.
  20. local snap_stop_angle = 10
  21.  
  22. -- Rate in which to reduce a players aimbot score (in seconds.)
  23. local aimbot_score_depletion_rate = 1.5
  24.  
  25. -- Score removed when aimbot_score_depletion_rate is called.
  26. local aimbot_score_depletion = 3
  27.  
  28. -- Message that is sent to admins when an action has been called on a player.
  29. local notify_admins = false
  30.  
  31.  -- Should the script create a Antibot.log file?
  32. local logging_enabled = true
  33.  
  34. ----------------------------------------------------------------------------
  35. -- DO NOT TOUCH ANYTHING BELOW THIS POINT UNLESS YOU KNOW WHAT YOUR DOING --
  36. ----------------------------------------------------------------------------
  37.  
  38. local player_score = {}
  39. local spawning = {}
  40. local loc = {}
  41. local camera_table = {}
  42.  
  43. local bipd_id
  44. local bipd_tag
  45. local bipd_data
  46. local standing_height
  47. local crouch_height
  48.  
  49. function GetRequiredVersion()
  50.         return 200
  51. end
  52.  
  53. function OnPlayerJoin(playerId)
  54.         camera_table[playerId] = nil
  55.         player_score[playerId] = 0
  56. end
  57.  
  58. function OnPlayerLeave(playerId)
  59.         camera_table[playerId] = nil
  60.         player_score[playerId] = 0
  61. end
  62.  
  63. function OnScriptLoad(process, game, persistent)
  64.         for i = 0,15 do
  65.                 loc[i] = {}
  66.                 camera_table[i] = nil
  67.                 player_score[i] = 0
  68.         end
  69.         registertimer(aimbot_score_depletion_rate * 1000, "score_depletion")
  70. end
  71.  
  72. function OnServerCommand(playerId, command, password)
  73.         local response = nil
  74.         t = tokenizecmdstring(command)
  75.         count = #t
  76.                 if t[1] == "sv_getscore" then
  77.                         response = 0
  78.                         if tonumber(t[2]) ~= nil then
  79.                                 sendconsoletext(playerId, math.floor(tonumber(player_score[rresolveplayer(t[2])])))
  80.                         else
  81.                                 sendconsoletext(playerId, "Invalid Player!")
  82.                         end
  83.                 elseif t[1] == "sv_getscores" or t[1] == "sv_aimbot_scores" then
  84.                         response = 0
  85.                         sendconsoletext(playerId, "Name  |  Score")
  86.                         for i = 0,15 do
  87.                                 if getplayer(i) then
  88.                                         sendconsoletext(playerId, getname(i) .. "  |  " .. math.floor(tonumber(player_score[i])))
  89.                                 end
  90.                         end
  91.                 elseif t[1] == "sv_aimbot_ban" then
  92.                         response = 0
  93.                         if t[2] ~= nil then
  94.                                 if tonumber(t[1]) ~= nil then
  95.                                         maxt_score = tonumber(t[1])
  96.                                 else
  97.                                         sendconsoletext(playerId, "Invalid Score! Use a number.")
  98.                                 end
  99.                                 if tostring(t[2]) == "ban" or tostring(t[3]) == "kick" or tostring(t[3]) == "none" then
  100.                                         action = tostring(t[2])
  101.                                 else
  102.                                         sendconsoletext(playerId, "Invalid action! Use ban, kick, or none.")
  103.                                 end
  104.                                 if tonumber(t[3]) ~= nil then
  105.                                         ban_time = tonumber(t[3])
  106.                                 else
  107.                                         sendconsoletext(playerId, "Invalid time! Ban time is in minutes")
  108.                                 end
  109.                         else
  110.                                 sendconsoletext(playerId, "Invalid Syntax! sv_aimbot_ban [type] {score} {time}")
  111.                         end
  112.                 end
  113.         return response
  114. end
  115.  
  116. function score_depletion(id, count)
  117.         for i = 0,15 do
  118.                 if getplayer(i) ~= nil then
  119.                         if tonumber(player_score[i]) > 0 then
  120.                                 player_score[i] = tonumber(player_score[i]) - aimbot_score_depletion
  121.                         elseif tonumber(player_score[i]) < 0 then
  122.                                 player_score[i] = 0
  123.                         end
  124.                 end
  125.         end
  126.         return true
  127. end
  128.  
  129. function OnPlayerKill(killer, victim, mode)
  130.         camera_table[victim] = nil
  131. end
  132.  
  133. function OnPlayerSpawn(playerId)
  134.         if not bipd_id then
  135.                 bipd_id = readdword(getobject(getplayerobjectid(playerId)))
  136.                 bipd_tag = gettagaddress(bipd_id)
  137.                 bipd_data = readdword(bipd_tag + 0x14)
  138.                 standing_height = readfloat(bipd_data + 0x400)
  139.                 crouch_height = readfloat(bipd_data + 0x404)
  140.         end
  141.         camera_table[playerId] = nil
  142.         spawning[playerId] = true
  143.         registertimer(1500, "removegrace", playerId)
  144. end
  145.  
  146. function removegrace(id, count, playerId)
  147.         spawning[playerId] = false
  148. end
  149.  
  150. local function WriteLog(filename, value)
  151.         if logging_enabled then
  152.                 local file = io.open(filename, "a")
  153.                 if file then
  154.                         file:write( string.format("%s\t%s\n", os.date("!%m/%d/%Y %H:%M:%S"), tostring(value) ) )
  155.                         file:close()
  156.                 end
  157.         end
  158. end
  159.  
  160. local function getping(playerId)
  161.         return readword(getplayer(playerId) + 0xDC)
  162. end
  163.  
  164. local function takeaction(playerId)
  165.  
  166.         local log_file = getprofilepath() .. "\\logs\\Antibot.log"
  167.         local line = "(Name: %s) (Hash: %s) (IP: %s) (Ping: %s) (Score: %s) (Action: %s)"
  168.         local Line = string.format(line, getname(playerId), gethash(playerId), getip(playerId), getping(playerId), math.floor(tonumber(player_score[playerId])), action)
  169.         WriteLog(log_file, Line)
  170.  
  171.         if notify_admins then
  172.                 for i=0,15 do
  173.                         if isadmin(i) then
  174.                                 privatesay(i, "Name: " .. getname(playerId) .. " - Action taken: " .. action .. " - Aimbot Score:" .. math.floor(tonumber(player_score[playerId])))
  175.                         end
  176.                 end
  177.         end
  178.         local player_id = resolveplayer(playerId)
  179.         if action == "ban" then
  180.                 if ban_time then
  181.                         svcmd("sv_ban " .. player_id .. " " .. ban_time .. "m")
  182.                 else
  183.                         svcmd("sv_ban " .. player_id)
  184.                 end
  185.                 say(getname(playerId) .. " has been banned from the server for aimbotting!")
  186.                 player_score[playerId] = 0
  187.         elseif action == "kick" then
  188.                 svcmd("sv_kick " .. player_id)
  189.                 player_score[playerId] = 0
  190.                 say(getname(playerId) .. " has been kicked from the server for aimbotting!")
  191.         elseif action == "none" or action == "warn" then
  192.                 say(getname(playerId) .. " may very possibly be aimbotting! Id: " .. player_id)
  193.         end
  194. end
  195.  
  196. local function OnPlayerTeleport(playerId)
  197.         spawning[playerId] = true
  198.         registertimer(500, "removegrace", playerId)
  199. end
  200.  
  201. local function checkforteleport(playerId)
  202.  
  203.         local m_objectId = getplayerobjectid(playerId)
  204.         local x,y,z = getobjectcoords(m_objectId)
  205.  
  206.         if x ~= loc[playerId][1] or y ~= loc[playerId][2] or z ~= loc[playerId][3] then
  207.                 if loc[playerId][1] == nil then
  208.                         loc[playerId][1] = x
  209.                         loc[playerId][2] = y
  210.                         loc[playerId][3] = z
  211.                 elseif m_object then
  212.                         distance = math.sqrt((loc[playerId][1] - x)^2 + (loc[playerId][2] - y)^2 + (loc[playerId][3] - z)^2)
  213.                         local result = true
  214.                         if distance >= 10 then result = OnPlayerTeleport(playerId) end
  215.                         if result == 0 or result == false then
  216.                                 --movobjectcoords(m_objectId, loc[playerId][1], loc[playerId][2], loc[playerId][3])
  217.                                 loc[playerId][1] = x
  218.                                 loc[playerId][2] = y
  219.                                 loc[playerId][3] = z
  220.                         else
  221.                                 loc[playerId][1] = x
  222.                                 loc[playerId][2] = y
  223.                                 loc[playerId][3] = z
  224.                         end
  225.                 end
  226.         end
  227. end
  228.  
  229. local function getstopangle(playerId, x_aim, y_aim, z_aim)
  230.         local m_objectId = getplayerobjectid(playerId)
  231.         local m_object = getobject(m_objectId)
  232.  
  233.         if camera_table[playerId] == nil then
  234.                 camera_table[playerId] = {x_aim, y_aim, z_aim}
  235.                 return
  236.         end
  237.  
  238.         local last_camera_x = camera_table[playerId][1]
  239.         local last_camera_y = camera_table[playerId][2]
  240.         local last_camera_z = camera_table[playerId][3]
  241.  
  242.         camera_table[playerId] = {x_aim, y_aim, z_aim}
  243.  
  244.         if      last_camera_x == 0 and
  245.                 last_camera_y == 0 and
  246.                 last_camera_z == 0 then
  247.                 return
  248.         end
  249.  
  250.         local movement = math.sqrt(
  251.                 (x_aim - last_camera_x) ^ 2 +
  252.                 (y_aim - last_camera_y) ^ 2 +
  253.                 (z_aim - last_camera_z) ^ 2)
  254.  
  255.         local angle = math.acos((2 - movement ^ 2) / 2)
  256.         stop_angle = angle * 180 / math.pi
  257.  
  258.         return stop_angle
  259. end
  260.  
  261. local function Intersect(playerId, vx, vy, vz)
  262.  
  263.         local playerObjId = getplayerobjectid(playerId)
  264.         local m_object = getobject(playerObjId)
  265.         if not m_object then
  266.                 return
  267.         end
  268.  
  269.         local crouch_state = readfloat(m_object + 0x50C)
  270.         local px, py, pz = getobjectcoords(playerObjId)
  271.         if (crouch_state == 0) then
  272.                 pz = pz + standing_height
  273.         else
  274.                 pz = pz + (crouch_height * crouch_state)
  275.         end
  276.  
  277.         local hit,x,y,z,objectId = halointersect(1000, px, py, pz, vx, vy, vz, playerObjId)
  278.         local walls = 1
  279.         while hit == true and walls < 20 do
  280.                 local playerId2 = objectId and objectidtoplayer(objectId)
  281.                 if not playerId2 then
  282.                         walls = walls + 1
  283.                         hit,x,y,z,objectId = halointersect(1000, x, y, z, vx, vy, vz, objectId)
  284.                 else
  285.                         --say(getname(playerId) .. " is aiming at " .. getname(playerId2))
  286.                         return true, getteam(playerId) == getteam(playerId2), math.sqrt((x - px) ^ 2 + (y - py) ^ 2 + (z - pz) ^ 2), walls
  287.                 end
  288.         end
  289. end
  290.  
  291. function OnClientUpdate(playerId)
  292.         if not bipd_id then
  293.                 return
  294.         end
  295.  
  296.         checkforteleport(playerId)
  297.  
  298.         if spawning[playerId] then
  299.                 return
  300.         end
  301.  
  302.         local m_objectId = getplayerobjectid(playerId)
  303.         local m_object = getobject(m_objectId)
  304.  
  305.         local x_aim,y_aim,z_aim = readfloat(m_object + 0x230),readfloat(m_object + 0x234),readfloat(m_object + 0x238)
  306.         local stop_angle = getstopangle(playerId, x_aim, y_aim, z_aim)
  307.  
  308.         if stop_angle ~= nil then else stop_angle = 1 end
  309.  
  310.         if stop_angle <= snap_stop_angle then
  311.                 return
  312.         end
  313.  
  314.         local hitting, at_teammate, distance, walls = Intersect(playerId, x_aim, y_aim, z_aim)
  315.         if distance ~= nil then else distance = 1 end
  316.         if hitting and not at_teammate then
  317.                 if walls < 2 then score_multiplier = 0.125 else score_multiplier = 0.175 end
  318.                 if tonumber(player_score[playerId]) then
  319.                         player_score[playerId] = tonumber(player_score[playerId]) + (stop_angle * score_multiplier  * distance)
  320.                         if tonumber(player_score[playerId]) > max_score then
  321.                                 takeaction(playerId)
  322.                         end
  323.                 else
  324.                         player_score[playerId] = (stop_angle * score_multiplier * distance)
  325.                 end
  326.         end
  327. end

HaloNet.Net is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.