ronaldoguedess Posted July 15, 2014 Author Share Posted July 15, 2014 I managed to hit all the weapons I need, minus 1. The Sniper is not right without the Zoom she is in a position to give give it totally changes the zoom position. I tried to filter by "if getControlState (" zoom_out ") then" however, is very wrong the way while giving zoom this. if you do not like leave without autoain the sniper, thanks for the help, I could never alone. Link to comment
ronaldoguedess Posted October 2, 2014 Author Share Posted October 2, 2014 Goodnight everyone ... went back to work in resourcer and am having major problems ... - If the target is higher or lower the automatic crosshair gets wrong. - Depending on the angle that the player is not the shot hits the target. I tried to make corrections, but I can not succeed in any way! This is the most complicated system I tried to do. Anyone willing to help me? local localPlayerName = getPlayerName(getLocalPlayer()) local function getPedsOnScreen() --outputChatBox("Chama: getPedsOnScreen ^^") local peds = {} for key, ped in ipairs(getElementsByType("ped", root, true)) do if isElementOnScreen(ped) and isPedDead(ped) == false then table.insert(peds, ped) --if getElementType(ped) == "ped" then end end return peds end function funcInput() getPedsOnScreen() refreshPeds() end addEventHandler("onClientRender", root, funcInput) local function dxDrawCircle(posX, posY, radius, width, angleAmount, color, postGUI) radius = radius or 20 width = width or 1 angleAmount = angleAmount or 1 color = color or tocolor(255, 255, 255, 150) postGUI = postGUI or false for i=0,360,angleAmount do local _i = i*(math.pi/180) --dxDrawImage ( posX, posY, 6, 6, 'target.png') 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 function refreshPeds() --outputChatBox("Chama: refreshPeds ^^") local peds = getPedsOnScreen() if #peds > 0 then table.sort(peds, sortbyrot) StreamedPlayers = peds[1] --outputChatBox("Maior que 1") end end refreshPeds() local x,y,z = getElementPosition( getLocalPlayer ()) local distMax = 30 local dx,dy = guiGetScreenSize() aimX ,aimY = dx*0.54 , dy*0.3971 function AimOnPosition(weapon) local setToX,setToY = 0,0 local hx, hy, hz = getPedBonePosition(StreamedPlayers, 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(StreamedPlayers, 6) local a4,a5,a6 = getElementPosition(StreamedPlayers) local b1,b2,b3 = getElementPosition(localPlayer) local dist = getDistanceBetweenPoints3D(a1,a2,a3,b1,b2,b3) local difZ = (a3 - b3) --outputChatBox("".. math.floor(difZ) .." ") outputChatBox("distanc: "..math.floor(dist).."") ------------------------------------------- if weapon then aimX = dx*0.54 offsetheight = 0.2 distMin = 8 end setToX,setToY = getWorldFromScreenPosition(sx-setToX,sy+setToY,dist) _,_,setToX1 = getWorldFromScreenPosition(dx/2,dy/2,dist) _,_,setToX2 = getWorldFromScreenPosition(aimX,aimY,dist) setToX3 = (setToX2 - setToX1) local sx, sy = getScreenFromWorldPosition(hx, hy, hz) local angL = findRotation(a1, a2, b1, b2) outputChatBox("Angulo: "..math.floor(angL).."") if angL >= 130 and angL <= 145 then if dist <= 32 then ajuS = (dist * 0.003) elseif dist >= 33 and dist <= 40 then ajuS = (dist * 0.003) elseif dist >= 41 and dist <= 50 then ajuS = (dist * 0.001) end elseif angL >= 146 and angL <= 270 then if dist <= 32 then ajuS = (dist * 0.006) end if dist >= 33 and dist <= 40 then ajuS = (dist * 0.002) end if dist >= 41 and dist <= 50 then ajuS = (dist * 0.001) end --25m = 0.006 --40m = 0.002 --50m = 0.001 elseif angL >= 271 and angL <= 320 then if dist <= 32 then ajuS = (dist * 0.004) end if dist >= 33 and dist <= 40 then ajuS = (dist * 0.001) end if dist >= 41 and dist <= 50 then ajuS = (dist * 0.02) end else ajuS = (dist * 0.006) end if dist <= 50 and dist >=25 then -------------------------------- if dist > 25 then if dist >= 25 and dist <= 49 then offS = 0.15 elseif dist >= 50 then offS = 0.05 end setCameraTarget(setToX-ajuS+offS, setToY-ajuS+offS, b3-setToX3+0.2 +(a6-b3)) if sx then --dxDrawCircle(sx, sy) --marca na cabeça (sx, sy) setPedTargetingMarkerEnabled ( falso ) end end ------------------------------- end end function drawStuff() local weapon = getPedWeapon(localPlayer) if getControlState("aim_weapon")then if ( isPedDead ( StreamedPlayers ) == false ) and weapon and weapon > 0 and getElementData(localPlayer, "logedin") and localPlayerName == "ronaldoguedess" then --getPedsOnScreen() --refreshPeds() AimOnPosition(weapon) end end end addEventHandler("onClientRender", root, drawStuff) Link to comment
Einheit-101 Posted October 2, 2014 Share Posted October 2, 2014 This is almost impossible to make it perfect.... I think MTA team did not implement the "setPlayerAimTarget" because of security issues... Link to comment
ronaldoguedess Posted October 2, 2014 Author Share Posted October 2, 2014 I wanted to do as a benefit for those who have enough Experience. but I think they should create this function natively, so we would have the option to use or not use. needed so that system! would be really cool! Link to comment
Reaper Posted April 3, 2016 Share Posted April 3, 2016 What is the destination folder can I put that script Link to comment
slau Posted May 22, 2021 Share Posted May 22, 2021 local ped = createPed(49,1491.0987548828, -1735.0596923828, 13.3828125 +1) local dx,dy = guiGetScreenSize() aimX ,aimY = dx*0.55 , dy*0.3991 function AimOnPosition() local setToX,setToY = 0,0 local hx, hy, hz = getElementPosition(ped) 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) setToX,setToY = getWorldFromScreenPosition(sx-setToX,sy+setToY,dist) _,_,setToX1 = getWorldFromScreenPosition(dx/2,dy/2,dist) _,_,setToX2 = getWorldFromScreenPosition(aimX,aimY,dist) pos1 = (setToX2 - setToX1) setCameraTarget(a4,a5,a6) setCameraTarget(setToX - 0.19,setToY, b3 - pos1 + (a3-b3)) end function drawStuff() if getControlState("aim_weapon") then AimOnPosition() end end addEventHandler("onClientRender", root, drawStuff) https://prnt.sc/138u4p9 I edited the automatic aiming script, but it keeps showing up in the debugscript (attempt to perform arithmetic on local 'sx' (a boolean value)) if someone knows for him to aim directly at the pedestrian or he just aims at the pedestrians who are on my screen I've tried several things but none works Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now