Advertisement
Loque

Evento insegue eroe

Jun 18th, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.25 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Event Chase Player v1.00
  4. # -- Last Updated: 2012.01.05
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-EventChasePlayer"] = true
  12.  
  13. #==============================================================================
  14. # ▼ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2012.01.05 - Started Script and Finished.
  17. #
  18. #==============================================================================
  19. # ▼ Introduction
  20. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21. # This script allows you to make events that will chase the player or flee from
  22. # the player when the player enters within range of the event or when the event
  23. # sees the player.
  24. #
  25. #==============================================================================
  26. # ▼ Instructions
  27. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  28. # To install this script, open up your script editor and copy/paste this script
  29. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  30. #
  31. # -----------------------------------------------------------------------------
  32. # Move Script Call - Open up the script call in the event move menu and use:
  33. # -----------------------------------------------------------------------------
  34. # Add these variable changes to an event's move route to use them.
  35. #
  36. # @chase_range = x
  37. # Event will chase the player after reaching x range.
  38. #
  39. # @flee_range = x
  40. # Event will flee from player after reaching x range.
  41. #
  42. # @chase_speed = x
  43. # Event will move at x speed when chasing.
  44. #
  45. # @flee_speed = x
  46. # Event will move at x speed when fleeing.
  47. #
  48. # @sight_lock = x
  49. # Event will chase/flee from player for x frames.
  50. #
  51. # @alert_balloon = x
  52. # Event will show ballon ID x when chasing or fleeing.
  53. #
  54. # @see_player = true
  55. # For events that require them to see the player first, use this script call
  56. # inside the movement boxes. This does not follow line of sight rules, which
  57. # means if there's a rock blocking you and the event, it will still see you.
  58. #
  59. #==============================================================================
  60. # ▼ Compatibility
  61. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  62. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  63. # it will run with RPG Maker VX without adjusting.
  64. #
  65. #==============================================================================
  66.  
  67. module YEA
  68.   module EVENT_CHASE
  69.    
  70.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  71.     # - General Settings -
  72.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  73.     # These settings adjust some general settings regarding chasing and fleeing
  74.     # events. Adjust them as you see fit.
  75.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  76.     # The number of frames before a balloon can show up again on the same
  77.     # event. This is to prevent a massive balloon spamming. 60 frames = 1 sec.
  78.     # By default, 120 frames is 2 seconds.
  79.     ALERT_TIMER = 120
  80.    
  81.     # This is the default number of frames for how long the event will chase or
  82.     # flee from the player if used with @see_player = true. To change the amount
  83.     # individually for each event, use @sight_lock = x where x is a number.
  84.     # By default, 300 frames is 5 seconds.
  85.     SIGHT_LOCK = 300
  86.    
  87.   end # EVENT_CHASE
  88. end # YEA
  89.  
  90. #==============================================================================
  91. # ▼ Editting anything past this point may potentially result in causing
  92. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  93. # halitosis so edit at your own risk.
  94. #==============================================================================
  95.  
  96. #==============================================================================
  97. # ■ Game_Event
  98. #==============================================================================
  99.  
  100. class Game_Event < Game_Character
  101.  
  102.   #--------------------------------------------------------------------------
  103.   # alias method: update_self_movement
  104.   #--------------------------------------------------------------------------
  105.   alias game_event_update_self_movement_ecp update_self_movement
  106.   def update_self_movement
  107.     return if $imported["YEA-StopAllMovement"] && Switch.stop_npc_movement
  108.     update_chase_distance
  109.     update_flee_distance
  110.     if @stop_count > 0 && @chase_player
  111.       move_type_toward_player
  112.     elsif @stop_count > 0 && @flee_player
  113.       move_type_away_player
  114.     else
  115.       game_event_update_self_movement_ecp
  116.     end
  117.     update_alert_balloon
  118.   end
  119.  
  120.   #--------------------------------------------------------------------------
  121.   # new method: update_chase_distance
  122.   #--------------------------------------------------------------------------
  123.   def update_chase_distance
  124.     return if @erased
  125.     return if @chase_range.nil?
  126.     dis = distance_x_from($game_player.x).abs
  127.     dis += distance_y_from($game_player.y).abs
  128.     if chase_conditions
  129.       @chase_player = true
  130.       @move_speed = @chase_speed unless @chase_speed.nil?
  131.     else
  132.       @chase_player = false
  133.       @move_speed = @page.move_speed
  134.       @alert_player = false if @alert_timer <= 0
  135.     end
  136.   end
  137.  
  138.   #--------------------------------------------------------------------------
  139.   # new method: chase_conditions
  140.   #--------------------------------------------------------------------------
  141.   def chase_conditions
  142.     dis = distance_x_from($game_player.x).abs
  143.     dis += distance_y_from($game_player.y).abs
  144.     return true if @alert_lock > 0
  145.     return true if dis <= @chase_range and see_player?
  146.     if dis <= @chase_range && @see_player != true
  147.       @alert_lock = @sight_lock if @sight_lock != nil && @sight_lock > 0
  148.       return true
  149.     end
  150.     return false
  151.   end
  152.  
  153.   #--------------------------------------------------------------------------
  154.   # new method: update_flee_distance
  155.   #--------------------------------------------------------------------------
  156.   def update_flee_distance
  157.     return if @erased
  158.     return if @flee_range.nil?
  159.     dis = distance_x_from($game_player.x).abs
  160.     dis += distance_y_from($game_player.y).abs
  161.     if flee_conditions
  162.       @flee_player = true
  163.       @move_speed = @flee_speed unless @flee_speed.nil?
  164.     else
  165.       @flee_player = false
  166.       @move_speed = @page.move_speed
  167.       @alert_player = false if @alert_timer <= 0
  168.     end
  169.   end
  170.  
  171.   #--------------------------------------------------------------------------
  172.   # new method: flee_conditions
  173.   #--------------------------------------------------------------------------
  174.   def flee_conditions
  175.     dis = distance_x_from($game_player.x).abs
  176.     dis += distance_y_from($game_player.y).abs
  177.     return true if @alert_lock > 0
  178.     return true if dis <= @flee_range and see_player?
  179.     if dis <= @flee_range && @see_player != true
  180.       @alert_lock = @sight_lock if @sight_lock != nil && @sight_lock > 0
  181.       return true
  182.     end
  183.     return false
  184.   end
  185.  
  186.   #--------------------------------------------------------------------------
  187.   # new method: update_alert_balloon
  188.   #--------------------------------------------------------------------------
  189.   def update_alert_balloon
  190.     return if @erased
  191.     @alert_timer = 0 if @alert_timer.nil?
  192.     @alert_lock = 0 if @alert_lock.nil?
  193.     @alert_lock -= 1 if @alert_lock >= 0
  194.     return if @alert_balloon == nil || @alert_balloon == 0
  195.     if (@chase_player || @flee_player) && !@alert_player
  196.       @balloon_id = @alert_balloon
  197.       @alert_player = true
  198.       @alert_timer = YEA::EVENT_CHASE::ALERT_TIMER
  199.     end
  200.     @alert_timer -= 1 if @alert_player
  201.   end
  202.  
  203.   #--------------------------------------------------------------------------
  204.   # new method: see_player?
  205.   #--------------------------------------------------------------------------
  206.   def see_player?
  207.     return false if @see_player != true
  208.     sx = distance_x_from($game_player.x)
  209.     sy = distance_y_from($game_player.y)
  210.     if sx.abs > sy.abs
  211.       direction = sx > 0 ? 4 : 6
  212.     else
  213.       direction = sy > 0 ? 8 : 2
  214.     end
  215.     if direction == @direction
  216.       if @sight_lock == nil || @sight_lock <= 0
  217.         @sight_lock = YEA::EVENT_CHASE::SIGHT_LOCK
  218.       end
  219.       @alert_lock = @sight_lock
  220.       return true
  221.     end
  222.     return false
  223.   end
  224.  
  225.   #--------------------------------------------------------------------------
  226.   # new method: move_type_away_player
  227.   #--------------------------------------------------------------------------
  228.   def move_type_away_player
  229.     sx = @x - $game_player.x
  230.     sy = @y - $game_player.y
  231.     if sx.abs + sy.abs >= 20
  232.       move_random
  233.     else
  234.       case rand(6)
  235.       when 0..3;  move_away_from_player
  236.       when 4;     move_random
  237.       when 5;     move_forward
  238.       end
  239.     end
  240.   end
  241.  
  242. end # Game_Event
  243.  
  244. #==============================================================================
  245. #
  246. # ▼ End of File
  247. #
  248. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement