Sign in to follow this  
231

Auto aim

Recommended Posts


 
  1.  
  2.  local x,y,z = getElementPosition( getLocalPlayer ())
  3.  local Ped = createPed(49,x,y,z)
  4.  
  5. local dx,dy = guiGetScreenSize()
  6.  aimX ,aimY = dx*0.54 , dy*0.3971
  7.  
  8.  
  9.  function AimOnPosition()
  10.     local setToX,setToY = 0,0
  11.     local hx, hy, hz = getPedBonePosition(Ped, 6)
  12.     local sx,sy = getScreenFromWorldPosition(hx,hy,hz)
  13.    
  14.      setToX = math.abs(dx/2-(aimX))
  15.      setToY = math.abs(dy/2-aimY)
  16.      
  17.      local a1,a2,a3 = getPedBonePosition(Ped, 6)
  18.      local a4,a5,a6 = getElementPosition(Ped)
  19.      local b1,b2,b3 = getElementPosition(localPlayer)
  20.      local dist = getDistanceBetweenPoints3D(a1,a2,a3,b1,b2,b3)
  21.  
  22. -- here
  23.  
  24.  if isRifle then
  25.     aimX = dx*0.54 + (10 - dist*0.2)  -- maybe you will need to play around with 10 or *0.2 to get the right result.
  26.  else
  27.     aimX =   dx*0.54
  28. end
  29.  
  30.      setToX,setToY  = getWorldFromScreenPosition(sx-setToX,sy+setToY,dist)
  31.      _,_,setToX1 = getWorldFromScreenPosition(dx/2,dy/2,dist)
  32.      _,_,setToX2 = getWorldFromScreenPosition(aimX,aimY,dist)
  33.      setToX3 = (setToX2 - setToX1)
  34.     setCameraTarget(setToX,setToY,b3-setToX3+0.2 +(a6-b3))
  35. end
  36.  
  37.  
  38. function drawStuff()
  39.     if getControlState("aim_weapon") then
  40.      AimOnPosition()
  41.     end
  42. end
  43.  addEventHandler("onClientRender", root, drawStuff)
  44.  
how can you do it for the players

Share this post


Link to post

Same code, just posted it in without color overwrite because it messes with mit dark theme setting

 


 local x,y,z = getElementPosition( getLocalPlayer ())
 local Ped = createPed(49,x,y,z)
 
local dx,dy = guiGetScreenSize()
 aimX ,aimY = dx*0.54 , dy*0.3971
 
 
 function AimOnPosition()
    local setToX,setToY = 0,0
    local hx, hy, hz = getPedBonePosition(Ped, 6)
    local sx,sy = getScreenFromWorldPosition(hx,hy,hz)
   
     setToX = math.abs(dx/2-(aimX))
     setToY = math.abs(dy/2-aimY)
     
     local a1,a2,a3 = getPedBonePosition(Ped, 6)
     local a4,a5,a6 = getElementPosition(Ped)
     local b1,b2,b3 = getElementPosition(localPlayer)
     local dist = getDistanceBetweenPoints3D(a1,a2,a3,b1,b2,b3)
 
-- here
 
 if isRifle then
    aimX = dx*0.54 + (10 - dist*0.2)  -- maybe you will need to play around with 10 or *0.2 to get the right result.
 else
    aimX =   dx*0.54
end
 
     setToX,setToY  = getWorldFromScreenPosition(sx-setToX,sy+setToY,dist)
     _,_,setToX1 = getWorldFromScreenPosition(dx/2,dy/2,dist)
     _,_,setToX2 = getWorldFromScreenPosition(aimX,aimY,dist)
     setToX3 = (setToX2 - setToX1)
    setCameraTarget(setToX,setToY,b3-setToX3+0.2 +(a6-b3))
end
 
 
function drawStuff()
    if getControlState("aim_weapon") then
     AimOnPosition()
    end
end
 addEventHandler("onClientRender", root, drawStuff)

 

Edited by Pirulax

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.