phnx2

BL3 Python Camera Mod

Feb 8th, 2026 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.25 KB | Source Code | 0 0
  1. from typing import Any
  2. from mods_base import build_mod, get_pc, keybind, hook, EInputEvent, SliderOption
  3. from unrealsdk import find_all
  4. from unrealsdk.hooks import Type
  5. from unrealsdk.unreal import BoundFunction, UObject, WrappedStruct
  6. from ui_utils import show_hud_message
  7. from threading import Timer
  8.  
  9. assert __import__("mods_base").__version_info__ >= (1, 1), "Please update the SDK"
  10. __version__: str
  11. __version_info__: tuple[int, ...]
  12.  
  13. firstpersoncamera = None
  14. thirdpersoncamera = None
  15. orbitcamera = None
  16. lastCamWasFp = True
  17. cameraTimer = None
  18. walkingActive = False
  19.  
  20. PickupDistanceSlider: SliderOption = SliderOption("Loot Pickup Distance", 500.0, 450.0, 1000.0, 1.0, False, description="Sets how far away you can be to interact with ground loot.")
  21. InteractionDistanceSlider: SliderOption = SliderOption("Object Interaction Distance", 430.0, 330.0, 1000.0, 1.0, False, description="Sets how far away you can be to interact with objects.")
  22. TPCamOffsetXSlider: SliderOption = SliderOption("TP Camera forwards(+)/backwards(-)", -256.0, -500.0, 500.0, 1.0, False, description="Moves the third person camera forwards with positive values and backwards with negative ones.")
  23. TPCamOffsetYSlider: SliderOption = SliderOption("TP Camera left(-)/right(+)", 0.0, -500.0, 500.0, 1.0, False, description="Moves the third person camera right with positive values and left with negative ones.")
  24. TPCamOffsetZSlider: SliderOption = SliderOption("TP Camera up(+)/down(-)", -25.0, -500.0, 500.0, 1.0, False, description="Moves the third person camera up with positive values and down with negative ones.")
  25. OrbitCamOffsetXSlider: SliderOption = SliderOption("Orbit Camera forwards(+)/backwards(-)", -300.0, -500.0, 500.0, 1.0, False, description="Moves the orbit camera forwards with positive values and backwards with negative ones.")
  26. OrbitCamOffsetYSlider: SliderOption = SliderOption("Orbit Camera left(-)/right(+)", 0.0, -500.0, 500.0, 1.0, False, description="Moves the orbit camera right with positive values and left with negative ones.")
  27. OrbitCamOffsetZSlider: SliderOption = SliderOption("Orbit Camera up(+)/down(-)", 0.0, -500.0, 500.0, 1.0, False, description="Moves the orbit camera up with positive values and down with negative ones.")
  28.  
  29. @keybind("Third Person Mode ADS", event_filter=EInputEvent.IE_Released, description="Switches to Third Person on key release.")
  30. def thirdPersonModeAim() -> None:
  31.     modeName = get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode.Data.ModeName
  32.     if modeName == "Default" and modeName != "Orbit" and lastCamWasFp == False:
  33.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = thirdpersoncamera
  34.         #lastCamWasFpStr = str(lastCamWasFp)
  35.         #print("lastCamWasFp = " + lastCamWasFpStr)
  36.         #show_hud_message("lastCamWasFp", lastCamWasFpStr, 1.5)
  37.  
  38. @keybind("First Person Mode ADS", description= "Switches to First Person on key press.")
  39. def firstPersonMode() -> None:
  40.     modeName = get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode.Data.ModeName
  41.     if modeName == "ThirdPerson" and modeName != "Orbit" and lastCamWasFp == False:
  42.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = firstpersoncamera
  43.  
  44. @keybind("TP-FP Camera Mode Toggle", description="Toggles third person camera mode.")
  45. def toggleTpFp() -> None:
  46.     global lastCamWasFp
  47.     modeName = get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode.Data.ModeName
  48.     if modeName == "ThirdPerson" and modeName != "Orbit" and lastCamWasFp == False:
  49.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = firstpersoncamera
  50.         lastCamWasFp = True
  51.     elif modeName == "Default" and modeName != "Orbit":
  52.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = thirdpersoncamera
  53.         lastCamWasFp = False
  54.  
  55. @keybind("Orbit Camera Mode", description="Toggles orbit camera mode.")
  56. def orbitMode() -> None:
  57.     global lastCamWasFp
  58.     modeName = get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode.Data.ModeName
  59.     if modeName != "Orbit":
  60.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = orbitcamera
  61.     elif lastCamWasFp == True:
  62.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = firstpersoncamera
  63.     else:
  64.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = thirdpersoncamera
  65.         lastCamWasFp = False
  66.  
  67. def backToTp() -> None:
  68.     global lastCamWasFp
  69.     modeName = get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode.Data.ModeName
  70.     if modeName == "Default" and lastCamWasFp == False:
  71.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = thirdpersoncamera
  72.     elif modeName == "Melee" and lastCamWasFp == False:
  73.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = thirdpersoncamera
  74.     elif modeName == "GroundSlamHighExit" and lastCamWasFp == False:
  75.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = thirdpersoncamera
  76.     elif modeName == "Slide" and lastCamWasFp == False:
  77.         get_pc().OakPlayerCameraManager.CameraModesManager.CurrentMode = thirdpersoncamera
  78.  
  79. def SetTimer() -> None:
  80.     global cameraTimer
  81.     if cameraTimer and cameraTimer.is_alive():
  82.         print("Timer already running!")
  83.         return
  84.     cameraTimer = Timer(2.0, backToTp)
  85.     cameraTimer.start()
  86.  
  87. @hook("/Game/PlayerCharacters/_Shared/_Design/GroundSlam/High/Action_GroundSlam_High_Exit.Action_GroundSlam_High_Exit_C:OnEnd", Type.PRE)
  88. def GroundSlam(obj: UObject, args: WrappedStruct, _3: Any, _4: BoundFunction) -> None:
  89.     SetTimer()
  90.  
  91. @hook("/Game/PlayerCharacters/_Shared/_Design/Sliding/ControlledMove_Global_Sliding.ControlledMove_Global_Sliding_C:OnStop", Type.PRE)
  92. def slidingStop(obj: UObject, args: WrappedStruct, _3: Any, _4: BoundFunction) -> None:
  93.     SetTimer()
  94.  
  95. @hook("/Game/PlayerCharacters/_Shared/_Design/Ladder/Action_ExitLadderTop.Action_ExitLadderTop_C:OnBegin", Type.PRE)
  96. def exitLadderTop(obj: UObject, args: WrappedStruct, _3: Any, _4: BoundFunction) -> None:
  97.     SetTimer()
  98.  
  99. @hook("/Game/PlayerCharacters/_Shared/_Design/Ladder/Action_ExitLadderBottom.Action_ExitLadderBottom_C:OnBegin", Type.PRE)
  100. def exitLadderBottom(obj: UObject, args: WrappedStruct, _3: Any, _4: BoundFunction) -> None:
  101.     SetTimer()
  102.  
  103. @hook("/Game/PlayerCharacters/_Shared/_Design/Ladder/Action_LadderSlideLanding.Action_LadderSlideLanding_C:OnBegin", Type.PRE)
  104. def ladderSlideLanding(obj: UObject, args: WrappedStruct, _3: Any, _4: BoundFunction) -> None:
  105.     SetTimer()
  106.  
  107. @hook("/Game/PlayerCharacters/_Shared/_Design/Melee/Action_Melee_Base.Action_Melee_Base_C:OnEnd", Type.PRE)
  108. def Action_Melee_Base_C_OnEnd(obj: UObject, args: WrappedStruct, _3: Any, _4: BoundFunction) -> None:
  109.     SetTimer()
  110.  
  111. @keybind("Toggle Walking", description="Toggles walking.")
  112. def toggleWalking() -> None:
  113.     global walkingActive
  114.     if walkingActive == False:
  115.         get_pc().Character.CharacterMovement.MaxWalkSpeed.Value = 200.0
  116.         walkingActive = True
  117.     else:
  118.         get_pc().Character.CharacterMovement.MaxWalkSpeed.Value = 470.0
  119.         walkingActive = False
  120.  
  121. @hook("/Script/OakGame.GFxExperienceBar:extFinishedDim", Type.POST)
  122. def extFinishedDim(obj: UObject, args: WrappedStruct, _3: Any, _4: BoundFunction) -> None:
  123.     global firstpersoncamera, thirdpersoncamera, orbitcamera
  124.     firstpersoncamera = None
  125.     thirdpersoncamera = None
  126.     orbitcamera = None
  127.  
  128.     for camera in find_all("CameraMode")[1:]:
  129.         if camera.Data.ModeName == "ThirdPerson":
  130.             thirdpersoncamera = camera
  131.         elif camera.Data.ModeName == "Default":
  132.             firstpersoncamera = camera
  133.         elif camera.Data.ModeName == "Orbit":
  134.             orbitcamera = camera
  135.  
  136.     # Loot pickup, item card and object interaction distance Values
  137.     try:
  138.         pickupvalue = PickupDistanceSlider.value
  139.         objectvalue = InteractionDistanceSlider.value
  140.         widgets = find_all("BPWidget_GFxItemCard_C")[1:]
  141.  
  142.         for widget in widgets:
  143.             widget.ShowItemCardDistance = pickupvalue
  144.             widget.HideItemCardDistance = pickupvalue + 2
  145.  
  146.         get_pc().UseComponent.PickupInteractionDistance = pickupvalue
  147.         get_pc().UseComponent.InteractDistance = objectvalue
  148.         get_pc().UseComponent.LeaveInteractionDistance = objectvalue + 2
  149.  
  150.     except Exception as e:
  151.         print(f"Could not update distances: {e}")
  152.  
  153.     # Apply third person camera offset
  154.     try:
  155.         if thirdpersoncamera is not None:
  156.             # Get the third person camera location and add the offsets
  157.             offset = thirdpersoncamera.Behaviors[4].LocationOffset
  158.             offset.x = TPCamOffsetXSlider.value
  159.             offset.y = TPCamOffsetYSlider.value
  160.             offset.z = TPCamOffsetZSlider.value
  161.  
  162.     except Exception as e:
  163.         print(f"Could not update third person camera offset: {e}")
  164.  
  165.         # Apply orbit camera offset
  166.     try:
  167.         if orbitcamera is not None:
  168.             # Get the orbit camera location and add the offsets
  169.             offset = orbitcamera.Behaviors[5].LocationOffset
  170.             offset.x = OrbitCamOffsetXSlider.value
  171.             offset.y = OrbitCamOffsetYSlider.value
  172.             offset.z = OrbitCamOffsetZSlider.value
  173.  
  174.     except Exception as e:
  175.         print(f"Could not update orbit camera offset: {e}")
  176.  
  177. build_mod()
Advertisement
Add Comment
Please, Sign In to add comment