Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MODIFIED FREECAM --
- local zoom = 15
- local mouseFrameDelay = 0
- local ratio = 3
- local mouseSensetivity = 0.25
- local width, height = guiGetScreenSize()
- local PI = math.pi
- local hit
- local zOffset = 3
- local speed = 0
- local rotX, rotY = 0,PI/1.5
- local aim_start = false
- local aim_done = false
- local aim_zoom1 = 0
- local aim_zoom2 = 0
- mouse_look = false
- local options = {
- invertMouseLook = false,
- normalMaxSpeed = 2,
- slowMaxSpeed = 0.2,
- fastMaxSpeed = 12,
- smoothMovement = true,
- acceleration = 0.3,
- decceleration = 0.15,
- maxYAngle = 188,
- key_fastMove = "lshift",
- key_slowMove = "lalt",
- key_forward = "w",
- }
- local rootElement = getRootElement()
- local wrongWeapons = {
- [0]=false,
- [1]=false,
- [2]=true,
- [3]=true,
- [4]=true,
- [5]=true,
- [6]=true,
- [7]=true
- }
- --heavily modified freecam resource's core
- function freecamFrame()
- local cameraAngleX = rotX
- local cameraAngleY = rotY
- local freeModeAngleZ = math.sin(cameraAngleY)
- local freeModeAngleY = math.cos(cameraAngleY) * math.cos(cameraAngleX)
- local freeModeAngleX = math.cos(cameraAngleY) * math.sin(cameraAngleX)
- local camPosX, camPosY, camPosLastZ = getPedBonePosition(localPlayer, 31)
- if(isPedInVehicle(localPlayer)) then
- camPosX, camPosY, camPosLastZ = getElementPosition(getPedOccupiedVehicle(localPlayer))
- end
- if(aim_start == true) then
- if(aim_done == false) then
- if(aim_zoom1 < 2) then
- aim_zoom1 = aim_zoom1+0.1
- aim_zoom2 = aim_zoom2+0.025
- end
- else
- if(aim_zoom1 > 0) then
- aim_zoom1 = aim_zoom1-0.1
- aim_zoom2 = aim_zoom2-0.025
- end
- end
- end
- local camPosZ = camPosLastZ + zOffset
- local mspeed = options.normalMaxSpeed
- -- Update the camera position based on the forwards/backwards speed
- PosX = camPosX + freeModeAngleX * speed
- PosY = camPosY + freeModeAngleY * speed
- camPosZ = camPosLastZ + freeModeAngleZ * speed
- -- calculate a target based on the current position and an offset based on the angle
- local camTargetX = PosX + freeModeAngleX * zoom
- local camTargetY = PosY + freeModeAngleY * zoom
- local camTargetZ = camPosZ + freeModeAngleZ * zoom
- camPosX = PosX - ( camTargetX - PosX ) / ratio
- camPosY = PosY - ( camTargetY - PosY ) / ratio
- camPosZ = camPosZ - ( camTargetZ - camPosZ ) / ratio
- camPosX = camPosX+aim_zoom1
- if not (isLineOfSightClear(PosX, PosY, camPosLastZ, camPosX, camPosY, camPosZ, true, false, false, false, false, false, false)) then
- _,camPosX,camPosY,camPosZ = processLineOfSight(PosX, PosY, camPosLastZ, camPosX, camPosY, camPosZ, true, false, false, false, false, false, false)
- end
- setCameraMatrix ( camPosX, camPosY, camPosZ, camTargetX, camTargetY, camTargetZ )
- if(isPedInVehicle(localPlayer)) then
- setGameSpeed(1)
- else
- setGameSpeed(1.1)
- end
- -- WAFFEN HUD --
- if(isPedInVehicle(localPlayer) == false) then
- local wep = getPedWeapon(localPlayer)
- if (wrongWeapons[wep] == true) or (wrongWeapons[wep] == nil) then
- local x1, y1, z1 = getPedTargetCollision( localPlayer )
- if not(x1) or not(y1) or not(z1) then
- x1, y1, z1 = getPedTargetEnd(localPlayer)
- end
- setPedAimTarget(localPlayer, x1, y1, z1)
- local x2, y2, z2 = getPedWeaponMuzzlePosition(localPlayer)
- local sx, sy = guiGetScreenSize()
- local x, y = getScreenFromWorldPosition(x1, y1, z1)
- local dis = getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2)
- if(x) and (y) then
- local thick = 3-dis*0.1
- if(thick < 1.5) then thick = 1.5 end
- -- Kreuz --
- local r, g, b
- if(getPedTarget(localPlayer)) then
- r, g, b = 255, 50, 50
- else
- r, g, b = 255, 255, 255
- end
- dxDrawLine(x, y, x, y-17, tocolor(r, g, b, 200), thick)
- dxDrawLine(x-17, y, x, y, tocolor(r, g, b, 200), thick)
- dxDrawLine(x+17, y, x, y, tocolor(r, g, b, 200), thick)
- dxDrawLine(x, y, x, y+17, tocolor(r, g, b, 200), thick)
- -- Kasten --
- dxDrawLine(x, y+5, x+5, y, tocolor(0, 255, 0, 200), thick)
- dxDrawLine(x, y+5, x-5, y, tocolor(0, 255, 0, 200), thick)
- dxDrawLine(x, y-5, x+5, y, tocolor(0, 255, 0, 200), thick)
- dxDrawLine(x, y-5, x-5, y, tocolor(0, 255, 0, 200), thick)
- end
- end
- end
- end
- bindKey("aim_weapon", "down", function()
- aim_start = true
- aim_done = false
- setPedControlState(localPlayer, "aim_weapon", true)
- end)
- bindKey("aim_weapon", "up", function()
- aim_start = true
- aim_done = true
- setPedControlState(localPlayer, "aim_weapon", false)
- end)
- function freecamMouse(_,_,aX,aY)
- if (isCursorShowing()) or (isMTAWindowActive()) then
- mouseFrameDelay = 5
- return
- elseif mouseFrameDelay > 0 then
- mouseFrameDelay = mouseFrameDelay - 1
- return
- end
- aX = aX - width / 2
- aY = aY - height / 2
- rotX = rotX + aX * 0.01745 * mouseSensetivity
- rotY = rotY - aY * 0.01745 * mouseSensetivity
- if rotX > PI then
- rotX = rotX - 2 * PI
- elseif rotX < -PI then
- rotX = rotX + 2 * PI
- end
- if rotY > PI then
- rotY = rotY - 2 * PI
- elseif rotY < -PI then
- rotY = rotY + 2 * PI
- end
- if rotY < -PI / 3 then
- rotY = -PI / 3
- elseif rotY > PI / 3 then
- rotY = PI / 3
- end
- end
- addEventHandler("onClientPreRender", root, freecamFrame)
- addEventHandler("onClientCursorMove", root, freecamMouse)
- local function checkMouserad()
- local richtung = getCursorMoveOn()
- if(richtung == "up") then
- if(zoom > 5) then
- zoom = zoom-1
- end
- elseif(richtung == "down") then
- if(zoom < 100) then
- zoom = zoom+1
- end
- end
- setCursorPosition(width/2, height/2)
- end
- -- KEY BINDS --
- bindKey("mouse3", "down", function()
- addEventHandler("onClientCursorMove", getRootElement(), checkMouserad)
- setCursorPosition(width/2, height/2)
- showCursor(true)
- end)
- bindKey("mouse3", "up", function()
- removeEventHandler("onClientCursorMove", getRootElement(), checkMouserad)
- showCursor(false)
- end)
- -- GET CURSOR MOVVE ON BY MTA WIKI --
- function getCursorMoveOn()
- if ( isCursorShowing() ) then
- left = "left"
- right = "right"
- up = "up"
- down = "down"
- zero = "nil"
- if getElementData(localPlayer,"movew") == right then
- return right
- elseif getElementData(localPlayer,"movew") == left then
- return left
- elseif getElementData(localPlayer,"movew") == up then
- return up
- elseif getElementData(localPlayer,"movew") == down then
- return down
- elseif getElementData(localPlayer,"movew") == zero then
- return false
- end
- end
- end
- function executeMoveOn(cursorX,cursorY)
- if ( isCursorShowing() ) then
- setElementData(localPlayer,"moveX",cursorX, false)
- setElementData(localPlayer,"moveY",cursorY, false)
- if cursorX > cX then
- setElementData(localPlayer,"movew",right, false)
- elseif cursorX < cX then
- setElementData(localPlayer,"movew",left, false)
- elseif cursorY > cY then
- setElementData(localPlayer,"movew",down, false)
- elseif cursorY < cY then
- setElementData(localPlayer,"movew",up, false)
- end
- end
- end
- addEventHandler("onClientCursorMove",root,executeMoveOn)
- setTimer( function()
- if ( isCursorShowing() ) then
- local curX = getElementData(localPlayer,"moveX")
- local curY = getElementData(localPlayer,"moveY")
- if cursorX == cX then
- setElementData(localPlayer,"movew",zero, false)
- elseif cursorY == cY then
- setElementData(localPlayer,"movew",zero, false)
- end
- end
- end ,50,-1)
- function previousM()
- if ( isCursorShowing() ) then
- cX = getElementData(localPlayer,"moveX")
- cY = getElementData(localPlayer,"moveY")
- end
- end
- setTimer(previousM,50,-1)
- -- VEHICLE --
- addEventHandler("onClientVehicleEnter", getRootElement(), function(p)
- if(p == localPlayer) then
- showCursor(false)
- end
- end)
- addEventHandler("onClientVehicleExit", getRootElement(), function(p)
- if(p == localPlayer) then
- showCursor(true)
- end
- end)
- -- RESOURCE START --
- addEventHandler("onClientResourceStart", getResourceRootElement(), function()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement