Advertisement
EvilEagles

Untitled

Apr 7th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.44 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Yanfly Engine RD - Event Chase Player
  4. # Last Date Updated: 2009.06.19
  5. # Level: Easy, Normal
  6. #
  7. # This is a relatively simplistic script. For those who would like their events
  8. # to chase after the player is within a specific distance of it, it can happen
  9. # now. All you would need to do is add a few commands to the event's move route
  10. # and it will function as it should.
  11. #
  12. #===============================================================================
  13. # Updates:
  14. # ----------------------------------------------------------------------------
  15. # o 2009.06.19 - Efficiency update.
  16. # o 2009.06.18 - Started script and finished.
  17. #===============================================================================
  18. # Instructions
  19. #===============================================================================
  20. #
  21. # Open up the event's move route settings. Under the menu, there is an option
  22. # you can select called "Script..." Input either of the following:
  23. #
  24. # @chase_range = x Event will chase the player after reaching x range.
  25. # @flee_range = x Event will flee from player after reaching x range.
  26. #
  27. # To change the movement speed of the event when chasing or fleeing, input the
  28. # following tags:
  29. #
  30. # @chase_speed = x Event will move at x speed when chasing.
  31. # @flee_speed = x Event will move at x speed when fleeing.
  32. #
  33. # -----------------------------------------------------------------------------
  34. #
  35. # For events that require them to see the player first, use the following tags
  36. # inside the movement boxes. This does not follow line of sight rules, which
  37. # means if there's a rock blocking you and the event, it will still see you.
  38. #
  39. # @see_player = true Event needs to see player before chasing/fleeing.
  40. # @sight_lock = x Event will chase/flee from player for x frames.
  41. #
  42. # -----------------------------------------------------------------------------
  43. #
  44. # The next couple of options are a few extras.
  45. # @alert_balloon = x Event will show ballon ID x when chasing or fleeing.
  46. #
  47. #===============================================================================
  48. #
  49. # Compatibility
  50. # - Alias: Game_Character: update_self_movement
  51. #
  52. #===============================================================================
  53.  
  54. $imported = {} if $imported == nil
  55. $imported["EventChasePlayer"] = true
  56.  
  57. module YE
  58. module EVENT
  59.  
  60. # The number of frames before a balloon can show up again on the same
  61. # event. This is to prevent a massive balloon spamming. 60 frames = 1 sec.
  62. ALERT_TIMER = 900
  63.  
  64. # This is the default number of frames for how long the event will chase or
  65. # flee from the player if used with @see_player = true. To change the amount
  66. # individually for each event, use @sight_lock = x where x is a number.
  67. # By default, 300 frames is 5 seconds.
  68. SIGHT_LOCK = 300
  69.  
  70. end # EVENT
  71. end # YE
  72.  
  73. #===============================================================================
  74. # Editting anything past this point may potentially result in causing computer
  75. # damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
  76. # Therefore, edit at your own risk.
  77. #===============================================================================
  78.  
  79. #===============================================================================
  80. # Game_Character
  81. #===============================================================================
  82.  
  83. class Game_Character
  84.  
  85. #--------------------------------------------------------------------------
  86. # alias update_self_movement
  87. #--------------------------------------------------------------------------
  88. alias update_self_movement_ecp update_self_movement unless $@
  89. def update_self_movement
  90. update_alert_balloon
  91. update_chase_distance
  92. update_flee_distance
  93. if (@stop_count > 0) and @chase_player
  94. move_type_toward_player
  95. elsif (@stop_count > 0) and @flee_player
  96. move_type_away_player
  97. else
  98. update_self_movement_ecp
  99. end
  100. end
  101.  
  102. #--------------------------------------------------------------------------
  103. # update_chase_distance
  104. #--------------------------------------------------------------------------
  105. def update_chase_distance
  106. return if @erased
  107. @chase_range = false if @chase_range == nil
  108. @chase_player = false if @chase_range == false
  109. return if @chase_range == false
  110. dis = (distance_x_from_player.abs + distance_y_from_player.abs)
  111. if chase_conditions
  112. @chase_player = true
  113. @move_speed = @chase_speed if @chase_speed != nil
  114. else
  115. @chase_player = false
  116. @move_speed = @page.move_speed
  117. @alert_player = false if @alert_timer <= 0
  118. end
  119. end
  120.  
  121. #--------------------------------------------------------------------------
  122. # chase_conditions
  123. #--------------------------------------------------------------------------
  124. def chase_conditions
  125. dis = (distance_x_from_player.abs + distance_y_from_player.abs)
  126. return true if @alert_lock > 0
  127. return true if dis <= @chase_range and see_player?
  128. if dis <= @chase_range and @see_player != true
  129. if @sight_lock != nil and @sight_lock > 0
  130. @alert_lock = @sight_lock
  131. end
  132. return true
  133. end
  134. return false
  135. end
  136.  
  137. #--------------------------------------------------------------------------
  138. # update_flee_distance
  139. #--------------------------------------------------------------------------
  140. def update_flee_distance
  141. return if @erased
  142. @flee_range = false if @flee_range == nil
  143. @flee_player = false if @flee_range == false
  144. return if @flee_range == false
  145. dis = (distance_x_from_player.abs + distance_y_from_player.abs)
  146. if flee_conditions
  147. @flee_player = true
  148. @move_speed = @flee_speed if @flee_speed != nil
  149. else
  150. @flee_player = false
  151. @move_speed = @page.move_speed
  152. @alert_player = false if @alert_timer <= 0
  153. end
  154. end
  155.  
  156. #--------------------------------------------------------------------------
  157. # flee_conditions
  158. #--------------------------------------------------------------------------
  159. def flee_conditions
  160. dis = (distance_x_from_player.abs + distance_y_from_player.abs)
  161. return true if @alert_lock > 0
  162. return true if dis <= @flee_range and see_player?
  163. if dis <= @flee_range and @see_player != true
  164. if @sight_lock != nil and @sight_lock > 0
  165. @alert_lock = @sight_lock
  166. end
  167. return true
  168. end
  169. return false
  170. end
  171.  
  172. #--------------------------------------------------------------------------
  173. # update_alert_balloon
  174. #--------------------------------------------------------------------------
  175. def update_alert_balloon
  176. return if @erased
  177. @alert_timer = 0 if @alert_timer == nil
  178. @alert_lock = 0 if @alert_lock == nil
  179. @alert_lock -= 1 if @alert_lock >= 0
  180. return if @alert_balloon == nil or @alert_balloon == 0
  181. if (@chase_player or @flee_player) and !@alert_player
  182. @balloon_id = @alert_balloon
  183. @alert_player = true
  184. @alert_timer = YE::EVENT::ALERT_TIMER
  185. end
  186. return unless @alert_player
  187. @alert_timer -= 1
  188. end
  189.  
  190. #--------------------------------------------------------------------------
  191. # see_player?
  192. #--------------------------------------------------------------------------
  193. def see_player?
  194. return false if @see_player != true
  195. sx = distance_x_from_player
  196. sy = distance_y_from_player
  197. if sx.abs > sy.abs
  198. direction = sx > 0 ? 4 : 6
  199. else
  200. direction = sy > 0 ? 8 : 2
  201. end
  202. if direction == @direction
  203. if @sight_lock == nil or @sight_lock <= 0
  204. @sight_lock = YE::EVENT::SIGHT_LOCK
  205. end
  206. @alert_lock = @sight_lock
  207. return true
  208. end
  209. return false
  210. end
  211.  
  212. #--------------------------------------------------------------------------
  213. # move_type_away_player
  214. #--------------------------------------------------------------------------
  215. def move_type_away_player
  216. sx = @x - $game_player.x
  217. sy = @y - $game_player.y
  218. if sx.abs + sy.abs >= 20
  219. move_random
  220. else
  221. case rand(5)
  222. when 0..3; move_away_from_player
  223. when 4; move_random
  224. end
  225. end
  226. end
  227.  
  228. end # Game_Character
  229.  
  230. #===============================================================================
  231. #
  232. # END OF FILE
  233. #
  234. #=======================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement