Advertisement
Noneatme

Untitled

Nov 10th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.79 KB | None | 0 0
  1. -- MODIFIED FREECAM --
  2. local zoom = 15
  3. local mouseFrameDelay = 0
  4. local ratio = 3
  5. local mouseSensetivity = 0.25
  6. local width, height = guiGetScreenSize()
  7. local PI = math.pi
  8. local hit
  9. local zOffset = 3
  10. local speed = 0
  11. local rotX, rotY = 0,PI/1.5
  12.  
  13. local aim_start = false
  14. local aim_done = false
  15. local aim_zoom1 = 0
  16. local aim_zoom2 = 0
  17.  
  18. mouse_look = false
  19.  
  20. local options = {
  21.     invertMouseLook = false,
  22.     normalMaxSpeed = 2,
  23.     slowMaxSpeed = 0.2,
  24.     fastMaxSpeed = 12,
  25.     smoothMovement = true,
  26.     acceleration = 0.3,
  27.     decceleration = 0.15,
  28.     maxYAngle = 188,
  29.     key_fastMove = "lshift",
  30.     key_slowMove = "lalt",
  31.     key_forward = "w",
  32. }
  33.  
  34. local rootElement = getRootElement()
  35.  
  36. local wrongWeapons = {
  37.     [0]=false,
  38.     [1]=false,
  39.     [2]=true,
  40.     [3]=true,
  41.     [4]=true,
  42.     [5]=true,
  43.     [6]=true,
  44.     [7]=true
  45. }
  46.  
  47.  
  48. --heavily modified freecam resource's core
  49. function freecamFrame()
  50.     local cameraAngleX = rotX
  51.     local cameraAngleY = rotY
  52.     local freeModeAngleZ = math.sin(cameraAngleY)
  53.     local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX)
  54.     local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX)
  55.     local camPosX, camPosY, camPosLastZ = getPedBonePosition(localPlayer, 31)
  56.     if(isPedInVehicle(localPlayer)) then
  57.         camPosX, camPosY, camPosLastZ = getElementPosition(getPedOccupiedVehicle(localPlayer))
  58.     end
  59.     if(aim_start == true) then
  60.         if(aim_done == false) then
  61.             if(aim_zoom1 < 2) then
  62.                 aim_zoom1 = aim_zoom1+0.1
  63.                 aim_zoom2 = aim_zoom2+0.025
  64.             end
  65.         else
  66.             if(aim_zoom1 > 0) then
  67.                 aim_zoom1 = aim_zoom1-0.1
  68.                 aim_zoom2 = aim_zoom2-0.025
  69.             end
  70.         end
  71.     end
  72.  
  73.     local camPosZ = camPosLastZ + zOffset
  74.     local mspeed = options.normalMaxSpeed
  75.  
  76.     -- Update the camera position based on the forwards/backwards speed
  77.     PosX = camPosX + freeModeAngleX * speed
  78.     PosY = camPosY + freeModeAngleY * speed
  79.     camPosZ = camPosLastZ + freeModeAngleZ * speed
  80.     -- calculate a target based on the current position and an offset based on the angle
  81.     local camTargetX = PosX + freeModeAngleX * zoom
  82.     local camTargetY = PosY + freeModeAngleY * zoom
  83.     local camTargetZ = camPosZ + freeModeAngleZ * zoom
  84.     camPosX = PosX - ( camTargetX - PosX ) / ratio
  85.     camPosY = PosY - ( camTargetY - PosY ) / ratio
  86.     camPosZ = camPosZ - ( camTargetZ - camPosZ ) / ratio
  87.    
  88.     camPosX = camPosX+aim_zoom1
  89.     if not (isLineOfSightClear(PosX, PosY, camPosLastZ, camPosX, camPosY, camPosZ, true, false, false, false, false, false, false)) then
  90.         _,camPosX,camPosY,camPosZ = processLineOfSight(PosX, PosY, camPosLastZ, camPosX, camPosY, camPosZ, true, false, false, false, false, false, false)
  91.     end
  92.     setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetX, camTargetY, camTargetZ )
  93.     if(isPedInVehicle(localPlayer)) then
  94.         setGameSpeed(1)
  95.     else
  96.         setGameSpeed(1.1)
  97.     end
  98.    
  99.     -- WAFFEN HUD --
  100.     if(isPedInVehicle(localPlayer) == false) then
  101.         local wep = getPedWeapon(localPlayer)
  102.         if (wrongWeapons[wep] == true) or (wrongWeapons[wep] == nil) then
  103.             local x1, y1, z1 = getPedTargetCollision( localPlayer )
  104.             if not(x1) or not(y1) or not(z1) then
  105.                 x1, y1, z1 = getPedTargetEnd(localPlayer)
  106.             end
  107.             setPedAimTarget(localPlayer, x1, y1, z1)
  108.             local x2, y2, z2 = getPedWeaponMuzzlePosition(localPlayer)
  109.             local sx, sy = guiGetScreenSize()
  110.             local x, y = getScreenFromWorldPosition(x1, y1, z1)
  111.             local dis = getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2)
  112.             if(x) and (y) then
  113.                 local thick = 3-dis*0.1
  114.                 if(thick < 1.5) then thick = 1.5 end
  115.                 -- Kreuz --
  116.                 local r, g, b
  117.                 if(getPedTarget(localPlayer)) then
  118.                     r, g, b = 255, 50, 50
  119.                 else
  120.                     r, g, b = 255, 255, 255
  121.                 end
  122.                 dxDrawLine(x, y, x, y-17, tocolor(r, g, b, 200), thick)
  123.                 dxDrawLine(x-17, y, x, y, tocolor(r, g, b, 200), thick)
  124.                 dxDrawLine(x+17, y, x, y, tocolor(r, g, b, 200), thick)
  125.                 dxDrawLine(x, y, x, y+17, tocolor(r, g, b, 200), thick)
  126.                 -- Kasten --
  127.                 dxDrawLine(x, y+5, x+5, y, tocolor(0, 255, 0, 200), thick)
  128.                 dxDrawLine(x, y+5, x-5, y, tocolor(0, 255, 0, 200), thick)
  129.                 dxDrawLine(x, y-5, x+5, y, tocolor(0, 255, 0, 200), thick)
  130.                 dxDrawLine(x, y-5, x-5, y, tocolor(0, 255, 0, 200), thick)
  131.             end
  132.         end
  133.     end
  134. end
  135.  
  136. bindKey("aim_weapon", "down", function()
  137.     aim_start = true
  138.     aim_done = false
  139.     setPedControlState(localPlayer, "aim_weapon", true)
  140. end)
  141.  
  142. bindKey("aim_weapon", "up", function()
  143.     aim_start = true
  144.     aim_done = true
  145.     setPedControlState(localPlayer, "aim_weapon", false)
  146. end)
  147.  
  148. function freecamMouse(_,_,aX,aY)
  149.     if (isCursorShowing()) or (isMTAWindowActive()) then
  150.         mouseFrameDelay = 5
  151.     return
  152.     elseif mouseFrameDelay > 0 then
  153.         mouseFrameDelay = mouseFrameDelay - 1
  154.     return
  155.     end
  156.  
  157.     aX = aX - width / 2
  158.     aY = aY - height / 2
  159.     rotX = rotX + aX *  0.01745 * mouseSensetivity
  160.     rotY = rotY - aY *  0.01745 * mouseSensetivity
  161.     if rotX > PI then
  162.         rotX = rotX - 2 * PI
  163.     elseif rotX < -PI then
  164.         rotX = rotX + 2 * PI
  165.     end
  166.     if rotY > PI then
  167.         rotY = rotY - 2 * PI
  168.     elseif rotY < -PI then
  169.         rotY = rotY + 2 * PI
  170.     end
  171.  
  172.     if rotY < -PI / 3 then
  173.        rotY = -PI / 3
  174.     elseif rotY > PI / 3 then
  175.         rotY = PI / 3
  176.     end
  177. end
  178. addEventHandler("onClientPreRender", root, freecamFrame)
  179. addEventHandler("onClientCursorMove", root, freecamMouse)
  180.  
  181. local function checkMouserad()
  182.     local richtung = getCursorMoveOn()
  183.     if(richtung == "up") then
  184.         if(zoom > 5) then
  185.             zoom = zoom-1
  186.         end
  187.     elseif(richtung == "down") then
  188.         if(zoom < 100) then
  189.             zoom = zoom+1
  190.         end
  191.     end
  192.     setCursorPosition(width/2, height/2)
  193. end
  194.  
  195. -- KEY BINDS --
  196. bindKey("mouse3", "down", function()
  197.     addEventHandler("onClientCursorMove", getRootElement(), checkMouserad)
  198.     setCursorPosition(width/2, height/2)
  199.     showCursor(true)
  200. end)
  201. bindKey("mouse3", "up", function()
  202.     removeEventHandler("onClientCursorMove", getRootElement(), checkMouserad)
  203.     showCursor(false)
  204. end)
  205.  
  206.  
  207. -- GET CURSOR MOVVE ON BY MTA WIKI --
  208.  
  209. function getCursorMoveOn()
  210.     if ( isCursorShowing() ) then
  211.         left = "left"
  212.         right = "right"
  213.         up = "up"
  214.         down = "down"
  215.         zero = "nil"
  216.         if getElementData(localPlayer,"movew") == right then
  217.             return right
  218.         elseif getElementData(localPlayer,"movew") == left then
  219.             return left
  220.         elseif getElementData(localPlayer,"movew") == up then
  221.             return up
  222.         elseif getElementData(localPlayer,"movew") == down then
  223.             return down
  224.         elseif getElementData(localPlayer,"movew") == zero then
  225.             return false
  226.         end
  227.     end
  228. end
  229.  
  230. function executeMoveOn(cursorX,cursorY)
  231.     if ( isCursorShowing() ) then
  232.     setElementData(localPlayer,"moveX",cursorX, false)
  233.     setElementData(localPlayer,"moveY",cursorY, false)
  234.          if cursorX > cX then
  235.             setElementData(localPlayer,"movew",right, false)
  236.          elseif cursorX < cX then
  237.             setElementData(localPlayer,"movew",left, false)
  238.          elseif cursorY > cY then
  239.             setElementData(localPlayer,"movew",down, false)
  240.          elseif cursorY < cY then
  241.             setElementData(localPlayer,"movew",up, false)
  242.          end
  243.     end
  244. end
  245. addEventHandler("onClientCursorMove",root,executeMoveOn)
  246.  
  247. setTimer( function()
  248.     if ( isCursorShowing() ) then
  249.         local curX = getElementData(localPlayer,"moveX")
  250.         local curY = getElementData(localPlayer,"moveY")
  251.         if cursorX == cX then
  252.             setElementData(localPlayer,"movew",zero, false)
  253.         elseif cursorY == cY then
  254.             setElementData(localPlayer,"movew",zero, false)
  255.         end
  256.     end
  257. end ,50,-1)
  258.  
  259. function previousM()
  260.    if ( isCursorShowing() ) then
  261.     cX = getElementData(localPlayer,"moveX")
  262.     cY = getElementData(localPlayer,"moveY")
  263.    end
  264. end
  265. setTimer(previousM,50,-1)
  266.  
  267.  
  268. -- VEHICLE --
  269. addEventHandler("onClientVehicleEnter", getRootElement(), function(p)
  270.     if(p == localPlayer) then
  271.         showCursor(false)
  272.     end
  273. end)
  274.  
  275. addEventHandler("onClientVehicleExit", getRootElement(), function(p)
  276.     if(p == localPlayer) then
  277.         showCursor(true)
  278.     end
  279. end)
  280.  
  281. -- RESOURCE START --
  282. addEventHandler("onClientResourceStart", getResourceRootElement(), function()
  283.  
  284. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement