Aussiemon

FreeFlight.lua

Apr 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. --[[
  2. author: Aussiemon
  3.  
  4. -----
  5.  
  6. Copyright 2018 Aussiemon
  7.  
  8. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  9.  
  10. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  11.  
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13.  
  14. -----
  15.  
  16. Allows the user to fly freely around the map.
  17.  
  18. Press F9 to start freeflight, then press F7 to start orthographic perspective. Press F7 again to disable. Press F9 again to disable freeflight. When freeflight is disabled, you can press F8 to start cinematic freeflight, where your character is visible and the camera has acceleration. Don't press F9 or F8 while in the other mode to prevent weirdness. Q and E are up/down in all modes. Scroll changes speed in regular freeflight, elevation in orthographic perspective.
  19. --]]
  20.  
  21. FreeFlight = FreeFlight or {}
  22. local mod = FreeFlight
  23. local mod_name = "FreeFlight"
  24.  
  25. -- ##########################################################
  26. -- ################## Variables #############################
  27.  
  28. -- Initialize variables
  29. local Camera = Camera
  30. local EchoConsole = EchoConsole
  31. local FreeFlightManager = FreeFlightManager
  32. local GameSettingsDevelopment = GameSettingsDevelopment
  33. local ScriptViewport = ScriptViewport
  34. local ScriptWorld = ScriptWorld
  35. local Managers = Managers
  36. local Mods = Mods
  37.  
  38. mod.first_run_fov_changed = false
  39.  
  40. -- ##########################################################
  41. -- ################## Functions #############################
  42.  
  43. -- ##########################################################
  44. -- #################### Hooks ###############################
  45.  
  46. -- Freeflight Manager --
  47.  
  48. -- Initialize input service
  49. Mods.hook.set(mod_name, "FreeFlightManager._enter_global_free_flight", function (func, self, data, ...)
  50.  
  51. if not self.input_manager then
  52. -- Register free flight input manager/service
  53. local input_manager = Managers.input
  54. self.register_input_manager(self, input_manager)
  55. end
  56.  
  57. -- Original Function
  58. local result = func(self, data, ...)
  59. return result
  60. end)
  61.  
  62. -- Leave unit detached
  63. Mods.hook.set(mod_name, "FreeFlightManager.drop_player_at_camera_pos", function (func, ...) return end)
  64.  
  65. -- Prevent crash when trying to freeze camera frustum
  66. Mods.hook.set(mod_name, "FreeFlightManager._exit_frustum_freeze", function (func, ...) return end)
  67. Mods.hook.set(mod_name, "FreeFlightManager._enter_frustum_freeze", function (func, ...) return end)
  68.  
  69. -- Input Manager --
  70.  
  71. -- Prevent error when taking control of devices without debug console active
  72. Mods.hook.set(mod_name, "InputManager.device_unblock_service", function (func, self, device_type, device_index, service_name, ...)
  73.  
  74. if service_name == "Debug" or service_name == "DebugMenu" then
  75. return
  76. end
  77.  
  78. -- Original Function
  79. local result = func(self, device_type, device_index, service_name, ...)
  80. return result
  81. end)
  82.  
  83. -- ##########################################################
  84. -- ################### Script ###############################
  85.  
  86. Managers.free_flight = Managers.free_flight or FreeFlightManager:new()
  87. GameSettingsDevelopment.disable_free_flight = false
  88.  
  89. -- ##########################################################
Add Comment
Please, Sign In to add comment