Guest User

Simple Exit Arrows, v21

a guest
Sep 10th, 2023
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.46 KB | None | 0 0
  1. ################################################################################
  2. # Simple Exit Arrows - by Tustin2121
  3. #
  4. # To use, set the graphic of your exit warp event to an arrow with
  5. # the desired hue and name it "ExitArrow" (without the quotes).
  6. #
  7. # The below code will do the work of hiding and showing the arrow when needed.
  8. ################################################################################
  9.  
  10. class Game_Player < Game_Character
  11. alias __original__pbCheckEventTriggerAfterTurning pbCheckEventTriggerAfterTurning
  12.   # Run when the player turns.
  13.   # The default version of this method is empty, so replacing it outright
  14.   # like this is fine. You may want to double check, just in case, however.
  15.   # Derx: It is no longer empty, the method needs to be aliased.
  16.   def pbCheckEventTriggerAfterTurning
  17.     __original__pbCheckEventTriggerAfterTurning
  18.     pxCheckExitArrows
  19.   end
  20. end
  21.  
  22. class Game_Character
  23.   # Add accessors for some otherwise hidden options
  24.   attr_accessor :step_anime
  25.   attr_accessor :direction_fix
  26. end
  27.  
  28. # Checks if the player is standing next to the exit arrow, facing it.
  29. def pxCheckExitArrows(init=false)
  30.   px = $game_player.x
  31.   py = $game_player.y
  32.   for event in $game_map.events.values
  33.     next if !event.name[/^ExitArrow$/]
  34.     case $game_player.direction
  35.       when 2 #down
  36.         event.transparent = !(px==event.x && py==event.y-1)
  37.       when 8 #up
  38.         event.transparent = !(px==event.x && py==event.y+1)
  39.       when 4 #left
  40.         event.transparent = !(px==event.x+1 && py==event.y)
  41.       when 6 #right
  42.         event.transparent = !(px==event.x-1 && py==event.y)
  43.     end
  44.     if init
  45.       # This homogenizes the Exit Arrows to all act the same, that is
  46.       # a slow flashing arrow. If you want to change the behavior,
  47.       # change the values below.
  48.       event.move_speed = 1
  49.       event.walk_anime = false
  50.       event.step_anime = true
  51.       event.direction_fix = true
  52.     end
  53.   end
  54. end
  55.  
  56. # Run on scene change, init them as well
  57. #Events.onMapSceneChange+=proc{|sender,e|
  58. #  pxCheckExitArrows(true)
  59. #}
  60.  
  61. # Run on scene change, init them as well. v20 edition.
  62. EventHandlers.add(:on_enter_map, :check_arrow_on_transfer,
  63.   proc { |old_map_id|
  64.     pxCheckExitArrows(true)
  65.   }
  66. )
  67.  
  68.  
  69. # Run on every step taken
  70. #Events.onLeaveTile+=proc {|sender,e|
  71. #  pxCheckExitArrows
  72. #}
  73.  
  74. # Run on every step taken. v20 edition.
  75. EventHandlers.add(:on_leave_tile, :check_arrow_on_move,
  76.   proc { pxCheckExitArrows }
  77. )
Advertisement
Add Comment
Please, Sign In to add comment