Jump to content

Aim Automatic (Aimbot) in MTA?


Recommended Posts

  • Replies 56
  • Created
  • Last Reply

Top Posters In This Topic

Use client-side scripting, bind the aim key, get the distance between the players to get the closest player, there's a useful function findRotation on the wiki, if you want it to lock onto the target (use a timer to determine if the player is still close to the target and keep setting rotation to that target), if you want it to bounce to the closest player always (use the timer to determine who's the closest player and set rotation towards the closest player).

For the health arrows I'm sure you will find a way, I'm not too experienced in that subject but I am learning.

Link to comment

Well yes it's realy simple. Detection methode 2 way : closest by 3D world distance or closes in 2D dist by screen center. MTA has an inbulid aim script but it work's only with Ped's ( And not real player's ) so for aim you need to use some position matrix , maybe adding soem offset's etc... and after that use : setPedLookAt , and other aim function's.

Link to comment
  • Moderators

There are no functions that make this possible yet very easily.

The functions that are there do not work for the localPlayer, but only for remote players(other players except your self) and peds.

Link to comment

I'm trying to do here!

the beginning did check when the player clicks the button to aim!

  
function funcInput ( key, keyState ) 
   if ( keyState == "down" ) then 
   
   local x,y,z = getElementPosition( getLocalPlayer () ) -- ok 
   local tx,ty,tz = getElementPosition( source ) -- [b][color=#FF0000]How to get the target?[/color][/b] 
  
  
  end 
end 
bindKey ( "aim_weapon", "down", funcInput )   -- bind the aim_weapon down key 
bindKey ( "aim_weapon", "up", funcInput )       -- bind the aim_weapon up key 
  
  

And now? what is the next step?

Link to comment

To get the target you can do a for loop with getElementsByType("player"):

local X, Y, Z = 0.0, 0.0, 0.0;

local TX, TY, TZ = 0.0, 0.0, 0.0;

local ClosestPlayer = nil;

local Distance = 999999.999999;

local StreamedPlayers = {};

X, Y, Z = getElementPosition(getLocalPlayer() or source);

StreamedPlayers = getElementsByType("player", getRootElement(), true);

for Key, Value in ipairs(StreamedPlayers) do

-- Value is the element.

'/t' TX, TY, TZ= getElementPosition(Value);

'/t' if(Distance > getDistanceBetweenPoints3D(X, Y, Z, TX, TY, TZ)) then

'/t' '/t' ClosestPlayer = Value;

'/t' '/t' Distance = getDistanceBetweenPoints3D(X, Y, Z, TX, TY, TZ);

'/t' end

end

if(isElement(ClosestPlayer) and getElementType(ClosestPlayer) == "player") then

'/t' TX, TY, TZ= getElementPosition(Value);

-- Aiming code here.

end

'/t' - tab.

Link to comment

This working! Thanks "SkittlesAreFalling"

Thus I take the position of all players, like picking the nearest? only 1?

What is the function to set the target?

I tried:

setElementRotation(player,0,0,TZ)  
setCameraTarget(player, Value)  

But it did not work! The player turns around, but not on top of the PED.

Link to comment

Like "bandi94" said:

"you need to use some position matrix , maybe adding soem offset's etc... and after that use : setPedLookAt , and other aim function's."

Try setting the rotation to (TZ + 0.05) or even (TZ + 0.000005), small tinkers and experimenting until it's 100% perfect.

I gave you a untested base, it wasn't going to work flawlessly the first test, you need to use your brain and the wiki.

I can do it flawless but I am busy.

Goodluck!

Link to comment

There is no function that forces the localPlayer to aim with a weapon at a specific point/target. I don't think this is possible.

You can easily determine which ped to actually aim/focus on by a combination of getting the closest ped by distance, and least rotation change to face the ped.

The following code draws the circles ontop of the ped that should have the aim/focus (untested btw):

Doesn't scale, or check for Line of sight.

local function getPedsOnScreen() 
    local peds = {} 
    for key, ped in ipairs(getElementsByType("ped", root, true)) do 
        if isElementOnScreen(ped) then 
            table.insert(peds, ped) 
             
        end 
    end 
    return peds 
end 
  
local function dxDrawCircle(posX, posY, radius, width, angleAmount, color, postGUI) 
    radius = radius or 50 
    width = width or 5 
    angleAmount = angleAmount or 1 
    color = color or tocolor(255, 255, 255, 200) 
    postGUI = postGUI or false 
  
    for i=0,360,angleAmount do 
        local _i = i*(math.pi/180) 
        dxDrawLine(math.cos(_i)*(radius-width)+posX, math.sin(_i)*(radius-width)+posY, math.cos(_i)*(radius+width)+posX, math.sin(_i)*(radius+width)+posY, tocolor(255, 0, 0), width, postGUI) 
    end 
  
    return true 
end 
  
local function findRotation(x1,y1,x2,y2) 
  
  local t = -math.deg(math.atan2(x2-x1,y2-y1)) 
  if t < 0 then t = t + 360 end; 
  return t; 
  
end 
  
  
local function sortbyrot(a, b) 
    local _, _, rz = getElementRotation(localPlayer) 
    local x, y = getElementPosition(localPlayer) 
    local ax, ay = getElementPosition(a) 
    local bx, by = getElementPosition(b) 
    local arz = findRotation(x, y, ax, ay) 
    arz = math.abs(rz - arz) 
    local brz = findRotation(x, y, bx, by) 
    brz = math.abs(rz - brz) 
    return arz < brz 
end 
  
  
addEventHandler("onClientRender", root, 
function() 
    local weapon = getPedWeapon(localPlayer) 
    if weapon and weapon > 0 then 
        local peds = getPedsOnScreen() 
        if #peds > 0 then 
            table.sort(peds, sortbyrot) 
            local chosen = peds[1] 
            local hx, hy, hz = getPedBonePosition(chosen, 6) 
            local sx, sy = getScreenFromWorldPosition(hx, hy, hz) 
            if sx then 
                dxDrawCircle(sx, sy) 
            end 
        end 
    end 
end) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...