Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- -- Author --
- Christian (dev_cmedina)
- -- Key Configurations --
- Feel free to change these to whatever you like.
- A list of all valid keys can be found here:
- https://raw.githubusercontent.com/UE4SS-RE/RE-UE4SS/ccfe4a45d0ea5aa5f8fc0b27b11d582ad51ae242/docs/lua-api/table-definitions/key.md
- --]]
- MOVE_IN = Key.NUM_EIGHT
- MOVE_OUT = Key.NUM_TWO
- MOVE_LEFT = Key.NUM_FOUR
- MOVE_RIGHT = Key.NUM_SIX
- MOVE_UP = Key.NUM_NINE
- MOVE_DOWN = Key.NUM_THREE
- RESET_CAMERA = Key.MULTIPLY
- SAVE_CAMERA = Key.DIVIDE
- --------------------
- isInitialized = false
- CameraController = nil
- AimController = nil
- Character = nil
- offsetX = -15
- offsetY = 15
- offsetZ = 65
- DEFAULT_CAMERA_OFFSET_X = -15
- DEFAULT_CAMERA_OFFSET_Y = 15
- DEFAULT_CAMERA_OFFSET_Z = 90
- local function SetOffsetX(offsetDelta)
- offsetX = offsetX + offsetDelta
- end
- local function SetOffsetY(offsetDelta)
- offsetY = offsetY + offsetDelta
- end
- local function SetOffsetZ(offsetDelta)
- offsetZ = offsetZ + offsetDelta
- end
- local function RefreshCameraOffsets()
- -- Versuch 1: normale Syntax
- local ok = pcall(function()
- AimController:ChangeIsAiming(true)
- AimController:ChangeIsAiming(false)
- end)
- if not ok then
- -- Versuch 2: mit explizitem Self-Parameter (UE4 erwartet 2 Parameter)
- pcall(function()
- AimController:ChangeIsAiming(AimController, true)
- AimController:ChangeIsAiming(AimController, false)
- end)
- end
- end
- local function SetCameraOffsets(Camera)
- Camera.WalkCameraOffset.X = offsetX
- Camera.WalkCameraOffset.Y = offsetY
- Camera.WalkCameraOffset.Z = offsetZ
- Camera.HipShootCameraOffset.X = offsetX
- Camera.HipShootCameraOffset.Y = offsetY
- Camera.HipShootCameraOffset.Z = offsetZ
- Camera.AimCameraOffset.X = offsetX
- Camera.AimCameraOffset.Y = offsetY
- Camera.AimCameraOffset.Z = offsetZ
- Camera.AirCameraOffset.X = offsetX
- Camera.AirCameraOffset.Y = offsetY
- Camera.AirCameraOffset.Z = offsetZ
- Camera.AirHipShootCameraOffset.X = offsetX
- Camera.AirHipShootCameraOffset.Y = offsetY
- Camera.AirHipShootCameraOffset.Z = offsetZ
- Camera.FlyCameraOffset.X = offsetX
- Camera.FlyCameraOffset.Y = offsetY
- Camera.FlyCameraOffset.Z = offsetZ
- Camera.FlyHipShootCameraOffset.X = offsetX
- Camera.FlyHipShootCameraOffset.Y = offsetY
- Camera.FlyHipShootCameraOffset.Z = offsetZ
- Camera.FlyAimCameraOffset.X = offsetX
- Camera.FlyAimCameraOffset.Y = offsetY
- Camera.FlyAimCameraOffset.Z = offsetZ
- Camera.CrouchCameraOffset.X = offsetX
- Camera.CrouchCameraOffset.Y = offsetY
- Camera.CrouchCameraOffset.Z = offsetZ
- Camera.CrouchHipShootCameraOffset.X = offsetX
- Camera.CrouchHipShootCameraOffset.Y = offsetY
- Camera.CrouchHipShootCameraOffset.Z = offsetZ
- Camera.CrouchAimCameraOffset.X = offsetX
- Camera.CrouchAimCameraOffset.Y = offsetY
- Camera.CrouchAimCameraOffset.Z = offsetZ
- Camera.SlidingCameraOffset.X = offsetX
- Camera.SlidingCameraOffset.Y = offsetY
- Camera.SlidingCameraOffset.Z = offsetZ
- Camera.SlidingHipShootCameraOffset.X = offsetX
- Camera.SlidingHipShootCameraOffset.Y = offsetY
- Camera.SlidingHipShootCameraOffset.Z = offsetZ
- Camera.SlidingAimCameraOffset.X = offsetX
- Camera.SlidingAimCameraOffset.Y = offsetY
- Camera.SlidingAimCameraOffset.Z = offsetZ
- end
- local function ResetCameraOffsets()
- offsetX = DEFAULT_CAMERA_OFFSET_X
- offsetY = DEFAULT_CAMERA_OFFSET_Y
- offsetZ = DEFAULT_CAMERA_OFFSET_Z
- SetCameraOffsets(CameraController)
- RefreshCameraOffsets()
- end
- local function SaveCameraOffsets()
- local file = io.open("./Mods/AdjustableCamera/CameraSettings.lua", "w")
- if not file then error("[AdjustableCamera] Unable to save camera settings to system.") end
- local cameraConfig = {
- X = offsetX,
- Y = offsetY,
- Z = offsetZ,
- }
- file:write("return {\n")
- for k, v in pairs(cameraConfig) do
- file:write(string.format(" %s = %s,\n", k, tostring(v)))
- end
- file:write("}\n")
- file:close()
- print("[AdjustableCamera] Camera offsets saved to CameraSettings.lua.")
- end
- local function LoadCameraOffsets()
- local ok, config = pcall(dofile, "./Mods/AdjustableCamera/CameraSettings.lua")
- if not ok then return nil end
- return config
- end
- local function InitializeCameraOffsets(cameraConfig)
- if cameraConfig then
- offsetX = cameraConfig.X
- offsetY = cameraConfig.Y
- offsetZ = cameraConfig.Z
- end
- end
- NotifyOnNewObject("/Script/Pal.PalPlayerCharacter", function(Character)
- print(Character:GetFullName())
- CameraController = Character.CameraBoom
- AimController = Character.ShooterComponent
- if not AimController:IsValid() then error("[AdjustableCamera] Error loading Aim Component.\n") end
- if not CameraController:IsValid() then error("[AdjustableCamera] Error loading Camera Controller.\n") end
- if not isInitialized then
- local cameraConfig = LoadCameraOffsets()
- InitializeCameraOffsets(cameraConfig)
- end
- SetCameraOffsets(CameraController)
- isInitialized = true
- print("[AdjustableCamera] Initialization complete.")
- end)
- RegisterKeyBind(MOVE_IN, function()
- if isInitialized then
- ExecuteAsync(function()
- SetOffsetX(20)
- SetCameraOffsets(CameraController)
- RefreshCameraOffsets()
- end)
- end
- end)
- RegisterKeyBind(MOVE_OUT, function()
- if isInitialized then
- ExecuteAsync(function()
- SetOffsetX(-20)
- SetCameraOffsets(CameraController)
- RefreshCameraOffsets()
- end)
- end
- end)
- RegisterKeyBind(MOVE_LEFT, function()
- if isInitialized then
- ExecuteAsync(function()
- SetOffsetY(-10)
- SetCameraOffsets(CameraController)
- RefreshCameraOffsets()
- end)
- end
- end)
- RegisterKeyBind(MOVE_RIGHT, function()
- if isInitialized then
- ExecuteAsync(function()
- SetOffsetY(10)
- SetCameraOffsets(CameraController)
- RefreshCameraOffsets()
- end)
- end
- end)
- RegisterKeyBind(MOVE_UP, function()
- if isInitialized then
- ExecuteAsync(function()
- SetOffsetZ(10)
- SetCameraOffsets(CameraController)
- RefreshCameraOffsets()
- end)
- end
- end)
- RegisterKeyBind(MOVE_DOWN, function()
- if isInitialized then
- ExecuteAsync(function()
- SetOffsetZ(-10)
- SetCameraOffsets(CameraController)
- RefreshCameraOffsets()
- end)
- end
- end)
- RegisterKeyBind(RESET_CAMERA, function()
- if isInitialized then
- ExecuteAsync(function()
- ResetCameraOffsets()
- end)
- end
- end)
- RegisterKeyBind(SAVE_CAMERA, function()
- if isInitialized then
- ExecuteAsync(function()
- SaveCameraOffsets()
- end)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment