j_sat

SprayFix

Jan 6th, 2018
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. local mod_name = "SprayFix"
  2.  
  3. local user_setting = Application.user_setting
  4.  
  5. local MOD_SETTINGS = {
  6.     ENABLED = {
  7.         ["save"] = "cb_spray_fix",
  8.         ["widget_type"] = "stepper",
  9.         ["text"] = "Drake And Beam Fix",
  10.         ["tooltip"] = "Drake And Beam Fix\n" ..
  11.             "Drake and beam will prioritize nearer rats.",
  12.         ["value_type"] = "boolean",
  13.         ["options"] = {
  14.             {text = "Off", value = false},
  15.             {text = "On", value = true},
  16.         },
  17.         ["default"] = 1, -- Off
  18.     },
  19. }
  20.  
  21. local POSITION_TWEAK = -1
  22. local SPRAY_RANGE = math.abs(POSITION_TWEAK) + 5
  23. local SPRAY_RADIUS = 3.5
  24. local PLAYER_SPRAY_RADIUS = 2
  25. local MAX_TARGETS = 10
  26. local NODES = {
  27.     "j_leftshoulder",
  28.     "j_rightshoulder",
  29.     "j_spine"
  30. }
  31.  
  32. Mods.hook.set(mod_name, "ActionBulletSpray._select_targets", function (func, self, world, show_outline)
  33.     if not user_setting(MOD_SETTINGS.ENABLED.save) then
  34.         func(self, world, show_outline)
  35.         return
  36.     end
  37.  
  38.     local owner_unit_1p = self.owner_unit_first_person
  39.     local player_position = POSITION_LOOKUP[owner_unit_1p]
  40.     local player_rotation = Unit.world_rotation(owner_unit_1p, 0)
  41.     local player_direction = Vector3.normalize(Quaternion.forward(player_rotation))
  42.  
  43.     local start_point = player_position + player_direction*POSITION_TWEAK + player_direction*SPRAY_RADIUS
  44.  
  45.     local original_PhysicsWorld_linear_sphere_sweep = PhysicsWorld.linear_sphere_sweep
  46.     PhysicsWorld.linear_sphere_sweep = function(...)
  47.         local results = original_PhysicsWorld_linear_sphere_sweep(...)
  48.  
  49.         table.sort(results,
  50.             function(hit1, hit2)
  51.                 return Vector3.distance(player_position, Unit.local_position(Actor.unit(hit1.actor), 0)) < Vector3.distance(player_position, Unit.local_position(Actor.unit(hit2.actor), 0))
  52.             end
  53.         )
  54.  
  55.         return results
  56.     end
  57.  
  58.     func(self, world, show_outline)
  59.  
  60.     PhysicsWorld.linear_sphere_sweep = original_PhysicsWorld_linear_sphere_sweep
  61. end)
  62.  
  63. --- options
  64. local function create_options()
  65.     Mods.option_menu:add_group("spray_fix_group", "Drake And Beam Fix")
  66.     Mods.option_menu:add_item("spray_fix_group", MOD_SETTINGS.ENABLED, true)
  67. end
  68.  
  69. safe_pcall(create_options)
Advertisement
Add Comment
Please, Sign In to add comment