Advertisement
VernonKun

fix_rat_climb_teleport

Nov 27th, 2020
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.85 KB | None | 0 0
  1. -- Fix for rats skipping climb animations, which visually becomes a teleport (TP) and allows the rats to instantly attack players when they should finish climbing up ledges first.
  2. -- This may also fix gutter runners from doing instant pounce after skipping climb animations. Note that instant pounce is a game design, but now with the fix they will have to wait until the end of the climb animations to do instant pounce.
  3. -- This doesn't fix visual TP for clients due to lag or rat position desync.
  4. --
  5. -- Xq & VernonKun 2020
  6. --
  7. -- This adjustment is intended to work with QoL modpack
  8. -- To "install" copy the file to "steamapps\common\Warhammer End Times Vermintide\binaries\mods\patch"
  9.  
  10. local mod_name = "fix_rat_climb_teleport"
  11.  
  12.  
  13. local clear_jump_climb_finished = function(blackboard)
  14.     -- EchoConsole("jump_climb_finished set to nil")
  15.     blackboard.jump_climb_finished = nil
  16.     return
  17. end
  18.  
  19. local set_jump_climb_finished = function(blackboard)
  20.     -- EchoConsole("jump_climb_finished set to true")
  21.     blackboard.jump_climb_finished = true
  22.     return
  23. end
  24.  
  25. local JUMP_CLIMB_FINISHED_DELAY = 0.3   -- seconds
  26. local JUMP_CLIMB_FAILSAFE_TIME  = 4     -- seconds
  27. local mod_climb_data = {}
  28.  
  29. Mods.hook.set(mod_name , "BTClimbAction.enter", function(func, self, unit, blackboard, t)
  30.     local ret = func(self, unit, blackboard, t)
  31.    
  32.     --From testing: This fixes climb TP for single climb right after a fall; set the flag to nil if climb action hasn't start yet
  33.     clear_jump_climb_finished(blackboard)
  34.    
  35.     mod_climb_data[unit] = nil
  36.    
  37.     return ret
  38. end)
  39.  
  40. Mods.hook.set(mod_name , "BTClimbAction.run", function(func, self, unit, blackboard, t, dt)
  41.    
  42.     if not mod_climb_data[unit] then
  43.         mod_climb_data[unit] =
  44.         {
  45.             climb_start_time    = nil,
  46.             last_climb_state    = "",
  47.             last_climb_state_1  = "",
  48.         }
  49.     end
  50.    
  51.     --From testing: This fixes climb TP for double climb; set the flag to nil if climb animation hasn't start yet
  52.     if blackboard.climb_state ==  "moving_to_to_entrance" and blackboard.jump_climb_finished then
  53.         clear_jump_climb_finished(blackboard)
  54.     end
  55.  
  56.     --This marks the beginning of the climb animation (could be off by 1-2 frames)
  57.     if blackboard.climb_state == "waiting_for_finished_climb_anim" and mod_climb_data[unit].last_climb_state_1 == "moving_to_to_entrance" then
  58.         mod_climb_data[unit].climb_start_time = t
  59.     end
  60.    
  61.     local climb_started     = mod_climb_data[unit].climb_start_time
  62.     local climb_duration    = climb_started and t - climb_started
  63.    
  64.     --Fix for rat potentially getting stuck in the climb loop, but it doesn't happen in testing so far
  65.     if climb_started and climb_duration > JUMP_CLIMB_FAILSAFE_TIME then
  66.         -- EchoConsole("stuck in climb loop:" .. tostring(unit))   
  67.         set_jump_climb_finished(blackboard)
  68.     end
  69.  
  70.     --From testing: This fixes climb TP for triple climb (or more?); set the flag to nil if it set to true too early (i.e. within 0.3 second) because of previously unfinished climb animations
  71.     if climb_started and blackboard.climb_state == "waiting_for_finished_climb_anim" and blackboard.jump_climb_finished then
  72.         -- EchoConsole(climb_duration)
  73.         if climb_duration < JUMP_CLIMB_FINISHED_DELAY then
  74.             -- EchoConsole("bugged climb found")
  75.             clear_jump_climb_finished(blackboard)
  76.         else
  77.             mod_climb_data[unit].climb_start_time = nil
  78.         end
  79.     end
  80.  
  81.     local ret = func(self, unit, blackboard, t, dt)
  82.    
  83.     mod_climb_data[unit].last_climb_state_1 = mod_climb_data[unit].last_climb_state
  84.     mod_climb_data[unit].last_climb_state = blackboard.climb_state
  85.    
  86.     --Clear data for dead rats
  87.     for loop_unit,_ in pairs(mod_climb_data) do
  88.         if not Unit.alive(loop_unit) then
  89.             mod_climb_data[loop_unit] = nil
  90.         end
  91.     end
  92.    
  93.     return ret
  94. end)
  95.  
  96. -- Mods.hook.set(mod_name , "BTClimbAction.leave", function(func, self, unit, blackboard, t)
  97.     -- if mod_climb_data[unit] then
  98.         -- mod_climb_data[unit].climb_start_time = nil
  99.     -- end
  100.  
  101.     -- func(self, unit, blackboard, t)
  102. -- end)
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement