Advertisement
Guest User

MTA SA FPS view

a guest
Sep 2nd, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. local rotX, rotY = 0, 0
  2. local camVehRot = 0
  3. local rot = 0
  4.  
  5. local curVehRot = 0
  6. local oldVehRot = 0
  7.  
  8. local egoEnabled = false
  9.  
  10. local mouseSensitivity = 0.1
  11.  
  12. lp = getLocalPlayer()
  13. local delay = 0
  14.  
  15. local PI = math.pi
  16.  
  17. local function freecamFrame ( slice )
  18.  
  19.  
  20.     local camPosX, camPosY, camPosZ = getPedBonePosition ( lp, 8 )
  21.    
  22.     local angleZ = math.sin(rotY)
  23.     local angleY = math.cos(rotY) * math.cos(rotX)
  24.     local angleX = math.cos(rotY) * math.sin(rotX)
  25.    
  26.     local camTargetX = camPosX + ( angleX ) * 100
  27.     local camTargetY = camPosY + angleY * 100
  28.     local camTargetZ = camPosZ + angleZ * 100
  29.    
  30.     local veh = getPedOccupiedVehicle ( lp )
  31.     if veh then
  32.         local rx, ry, curVehRot = getElementRotation ( veh )
  33.         local changedRotation = oldVehRot - curVehRot
  34.        
  35.         oldVehRot = curVehRot
  36.        
  37.         if not totalRot then
  38.             totalRot = curVehRot
  39.         end
  40.        
  41.         totalRot = changedRotation * 2 + totalRot
  42.        
  43.         local rotX = ( ( rotX * 360 / PI ) + totalRot ) / 360 * PI
  44.         if rotX > PI then
  45.             rotX = rotX - 2 * PI
  46.         elseif rotX < -PI then
  47.             rotX = rotX + 2 * PI
  48.         end
  49.        
  50.         camTargetX = camPosX + ( math.cos(rotY) * math.sin(rotX) ) * 100
  51.         camTargetY = camPosY + ( math.cos(rotY) * math.cos(rotX) ) * 100
  52.     end
  53.    
  54.     setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetX, camTargetY, camTargetZ )
  55. end
  56.  
  57. local function freecamMouse (cX,cY,aX,aY)
  58.  
  59.     if isCursorShowing() or isMTAWindowActive() then
  60.         delay = 5
  61.         return
  62.     elseif delay > 0 then
  63.         delay = delay - 1
  64.         return
  65.     end
  66.    
  67.     local width, height = guiGetScreenSize()
  68.     aX = aX - width / 2
  69.     aY = aY - height / 2
  70.    
  71.     rotX = rotX + aX * mouseSensitivity * 0.01745
  72.     rotY = rotY - aY * mouseSensitivity * 0.01745
  73.  
  74.     if rotX > PI then
  75.         rotX = rotX - 2 * PI
  76.     elseif rotX < -PI then
  77.         rotX = rotX + 2 * PI
  78.     end
  79.    
  80.     if rotY > PI then
  81.         rotY = rotY - 2 * PI
  82.     elseif rotY < -PI then
  83.         rotY = rotY + 2 * PI
  84.     end
  85.    
  86.     if rotY < -PI / 2.05 then
  87.        rotY = -PI / 2.05
  88.     elseif rotY > PI / 2.05 then
  89.         rotY = PI / 2.05
  90.     end
  91. end
  92.  
  93. function setEgoEnabled (x, y, z)
  94.  
  95.     if (x and y and z) then
  96.         setCameraMatrix ( camPosX, camPosY, camPosZ )
  97.     end
  98.     addEventHandler("onClientPreRender", getRootElement(), freecamFrame)
  99.     addEventHandler("onClientRender", getRootElement(), freecamFrame)
  100.     addEventHandler("onClientCursorMove",getRootElement(), freecamMouse)
  101. end
  102.  
  103. function setEgoDisabled()
  104.  
  105.     if egoEnabled then
  106.         egoEnabled = false
  107.         removeEventHandler("onClientPreRender", getRootElement(), freecamFrame)
  108.         removeEventHandler("onClientRender", getRootElement(), freecamFrame)
  109.         removeEventHandler("onClientCursorMove",getRootElement(), freecamMouse)
  110.         setCameraTarget ( lp )
  111.     end
  112. end
  113. addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), setEgoDisabled )
  114.  
  115. function ego_func ()
  116.  
  117.     if egoEnabled then
  118.         setEgoDisabled()
  119.     else
  120.         egoEnabled = true
  121.         local x, y, z = getElementPosition ( lp )
  122.         setEgoEnabled ( x, y, z )
  123.     end
  124. end
  125. addCommandHandler ( "fps", ego_func )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement