231 Posted January 25, 2019 Share Posted January 25, 2019 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) how can you do it for the players Link to comment
Guest Posted January 26, 2019 Share Posted January 26, 2019 triggerServerEvent -- If you want to use it for all players use Link to comment
Discord Moderators Pirulax Posted January 27, 2019 Discord Moderators Share Posted January 27, 2019 (edited) 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 January 27, 2019 by Pirulax 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