Jump to content

First Person Scripting


aneco

Recommended Posts

hi i found a script which player press f2 and have first person camera but i have a problem when player steers a car the cam wont steer and player have to steer camera via mouse i couldnt make a fix for this and i need some help please help me i need this code soo much.

Here is the code which i found

local x, y, z, x1, y1, z1 
local fpcam = false 
  
bindKey( "F2", "down", 
   function() 
      if fpcam then 
         setCameraTarget(getLocalPlayer(), getLocalPlayer()) 
      end 
      fpcam = not fpcam 
   end 
) 
  
addEventHandler("onClientPreRender", root, 
    function() 
        if fpcam then 
            x, y, z = getPedBonePosition(getLocalPlayer(), 6) 
            setCameraMatrix(x, y, z, x + x1, y + y1, z + z1) 
            dxDrawImage(screenWidth/2-10, screenHeight/2-10, 20, 20, "images/aimer.png") 
            local tarX, tarY, tarZ = getWorldFromScreenPosition(screenWidth/2, screenHeight/2, 30) 
            setPedAimTarget(getLocalPlayer(), tarX, tarY, tarZ) 
        end 
    end 
) 
  
addEventHandler("onClientCursorMove", root, 
    function( _, _, _, _, wx, wy, wz ) 
        local cx, cy, cz = getCameraMatrix() 
        x1 = ( wx - cx ) / 300 
        y1 = ( wy - cy ) / 300 
        z1 = ( wz - cz ) / 300 
    end 
) 

Edited by Guest
Link to comment

get the car Z rotation, then calculate wx, and wy with function

  
function getPointFromDistanceRotation(x,y,dist,angle) 
    local a=math.rad(90-angle) 
    local dx=math.cos(a)*dist 
    local dy=math.sin(a)*dist 
    return x+dx,y+dy 
end 
  

by using this

  
if getControlState"left" or getControlState"right"  then 
  local _,_,Zrot=getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) 
  wx,wy=getPointFromDistanceRotation(cx,cy,((cx-wx)^2+(cy-wy)^2)^0.5,Zrot) 
end 
  

Edited by Guest
Link to comment
get the car Z rotation, then calculate wx, and wy with function
  
function getPointFromDistanceRotation(x,y,dist,angle) 
    local a=math.rad(90-angle) 
    local dx=math.cos(a)*dist 
    local dy=math.sin(a)*dist 
    return x+dx,y+dy 
end 
  

by using this

  
if getControlState"left" or getControlState"right"  then 
  local _,_,Zrot=getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) 
  wx,wy=getPointFromDistanceRotation(cx,cy,((cx-wx)^2+(cy-wy)^2)^0.5,Zrot) 
end 
  

where i should put this code to script.i make like this.

  
local x, y, z, x1, y1, z1 
local fpcam = false 
  
bindKey( "F2", "down", 
   function() 
      if fpcam then 
         setCameraTarget(getLocalPlayer(), getLocalPlayer()) 
      end 
      fpcam = not fpcam 
   end 
) 
  
addEventHandler("onClientPreRender", root, 
    function() 
        if fpcam then 
            x, y, z = getPedBonePosition(getLocalPlayer(), 6) 
            setCameraMatrix(x, y, z, x + x1, y + y1, z + z1) 
            dxDrawImage(screenWidth/2-10, screenHeight/2-10, 20, 20, "images/aimer.png") 
            local tarX, tarY, tarZ = getWorldFromScreenPosition(screenWidth/2, screenHeight/2, 30) 
            setPedAimTarget(getLocalPlayer(), tarX, tarY, tarZ) 
  
function getPointFromDistanceRotation(x,y,dist,angle) 
    local a=math.rad(90-angle) 
    local dx=math.cos(a)*dist 
    local dy=math.sin(a)*dist 
    return x+dx,y+dy 
  
if getControlState"left" or getControlState"right"  then 
  local _,_,Zrot=getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) 
  wx,wy=getPointFromDistanceRotation(cx,cy,((cx-wx)^2+(cy-wy)^2)^0.5,Zrot) 
end 
        end 
    end 
) 
  
  
  
addEventHandler("onClientCursorMove", root, 
    function( _, _, _, _, wx, wy, wz ) 
        local cx, cy, cz = getCameraMatrix() 
        x1 = ( wx - cx ) / 300 
        y1 = ( wy - cy ) / 300 
        z1 = ( wz - cz ) / 300 
    end 
) 
  
  

Link to comment
      
    local x, y, z, x1, y1, z1 
    local fpcam = false 
      
    bindKey( "F2", "down", 
       function() 
          if fpcam then 
             setCameraTarget(getLocalPlayer(), getLocalPlayer()) 
          end 
          fpcam = not fpcam 
       end 
    ) 
      
    addEventHandler("onClientPreRender", root, 
        function() 
            if fpcam then 
                  x, y, z = getPedBonePosition(getLocalPlayer(), 6) 
                  if isPedInVehicle(getLocalPlayer()) and (getControlState"left" or getControlState"right")  then 
                    local _,_,Zrot=getElementRotation(getPedOccupiedVehicle(getLocalPlayer())) 
                    x1,y1=getPointFromDistanceRotation(x,y,(x1^2+x1^2)^0.5,Zrot) 
                end 
                setCameraMatrix(x, y, z, x + x1, y + y1, z + z1) 
                dxDrawImage(screenWidth/2-10, screenHeight/2-10, 20, 20, "images/aimer.png") 
                local tarX, tarY, tarZ = getWorldFromScreenPosition(screenWidth/2, screenHeight/2, 30) 
                setPedAimTarget(getLocalPlayer(), tarX, tarY, tarZ) 
end) 
  
function getPointFromDistanceRotation(x,y,dist,angle) 
        local a=math.rad(90-angle) 
        local dx=math.cos(a)*dist 
        local dy=math.sin(a)*dist 
        return x+dx,y+dy 
end 
      
      
    addEventHandler("onClientCursorMove", root, 
        function( _, _, _, _, wx, wy, wz ) 
            local cx, cy, cz = getCameraMatrix() 
            x1 = ( wx - cx ) / 300 
            y1 = ( wy - cy ) / 300 
            z1 = ( wz - cz ) / 300 
        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...