#=============================================================================== # # Yanfly Engine RD - Event Chase Player # Last Date Updated: 2009.06.28 # Level: Easy, Normal # # This is a relatively simplistic script. For those who would like their events # to chase after the player is within a specific distance of it, it can happen # now. All you would need to do is add a few commands to the event's move route # and it will function as it should. # #=============================================================================== # Updates: # ---------------------------------------------------------------------------- # o 2009.06.28 - Compatibility with Stop All Movement. # o 2009.06.19 - Efficiency update. # o 2009.06.18 - Started script and finished. #=============================================================================== # Instructions #=============================================================================== # # Open up the event's move route settings. Under the menu, there is an option # you can select called "Script..." Input either of the following: # # @chase_range = x Event will chase the player after reaching x range. # @flee_range = x Event will flee from player after reaching x range. # # To change the movement speed of the event when chasing or fleeing, input the # following tags: # # @chase_speed = x Event will move at x speed when chasing. # @flee_speed = x Event will move at x speed when fleeing. # # ----------------------------------------------------------------------------- # # For events that require them to see the player first, use the following tags # inside the movement boxes. This does not follow line of sight rules, which # means if there's a rock blocking you and the event, it will still see you. # # @see_player = true Event needs to see player before chasing/fleeing. # @sight_lock = x Event will chase/flee from player for x frames. # # ----------------------------------------------------------------------------- # # The next couple of options are a few extras. # @alert_balloon = x Event will show ballon ID x when chasing or fleeing. # #=============================================================================== # # Compatibility # - Alias: Game_Character: update_self_movement # #=============================================================================== $imported = {} if $imported == nil $imported["EventChasePlayer"] = true module YE module EVENT # The number of frames before a balloon can show up again on the same # event. This is to prevent a massive balloon spamming. 60 frames = 1 sec. ALERT_TIMER = 600 # This is the default number of frames for how long the event will chase or # flee from the player if used with @see_player = true. To change the amount # individually for each event, use @sight_lock = x where x is a number. # By default, 300 frames is 5 seconds. SIGHT_LOCK = 300 end # EVENT end # YE #=============================================================================== # Editting anything past this point may potentially result in causing computer # damage, incontinence, explosion of user's head, coma, death, and/or halitosis. # Therefore, edit at your own risk. #=============================================================================== #=============================================================================== # Game_Character #=============================================================================== class Game_Character #-------------------------------------------------------------------------- # alias update_self_movement #-------------------------------------------------------------------------- alias update_self_movement_ecp update_self_movement unless $@ def update_self_movement return if $imported["StopAllMovement"] and $game_switches[YE::EVENT::SWITCH::STOP_ALL] update_alert_balloon update_chase_distance update_flee_distance if (@stop_count > 0) and @chase_player move_type_toward_player elsif (@stop_count > 0) and @flee_player move_type_away_player else update_self_movement_ecp end end #-------------------------------------------------------------------------- # update_chase_distance #-------------------------------------------------------------------------- def update_chase_distance return if @erased @chase_range = false if @chase_range == nil @chase_player = false if @chase_range == false return if @chase_range == false dis = (distance_x_from_player.abs + distance_y_from_player.abs) if chase_conditions @chase_player = true @move_speed = @chase_speed if @chase_speed != nil else @chase_player = false @move_speed = @page.move_speed @alert_player = false if @alert_timer <= 0 end end #-------------------------------------------------------------------------- # chase_conditions #-------------------------------------------------------------------------- def chase_conditions dis = (distance_x_from_player.abs + distance_y_from_player.abs) return true if @alert_lock > 0 return true if dis <= @chase_range and see_player? if dis <= @chase_range and @see_player != true if @sight_lock != nil and @sight_lock > 0 @alert_lock = @sight_lock end return true end return false end #-------------------------------------------------------------------------- # update_flee_distance #-------------------------------------------------------------------------- def update_flee_distance return if @erased @flee_range = false if @flee_range == nil @flee_player = false if @flee_range == false return if @flee_range == false dis = (distance_x_from_player.abs + distance_y_from_player.abs) if flee_conditions @flee_player = true @move_speed = @flee_speed if @flee_speed != nil else @flee_player = false @move_speed = @page.move_speed @alert_player = false if @alert_timer <= 0 end end #-------------------------------------------------------------------------- # flee_conditions #-------------------------------------------------------------------------- def flee_conditions dis = (distance_x_from_player.abs + distance_y_from_player.abs) return true if @alert_lock > 0 return true if dis <= @flee_range and see_player? if dis <= @flee_range and @see_player != true if @sight_lock != nil and @sight_lock > 0 @alert_lock = @sight_lock end return true end return false end #-------------------------------------------------------------------------- # update_alert_balloon #-------------------------------------------------------------------------- def update_alert_balloon return if @erased @alert_timer = 0 if @alert_timer == nil @alert_lock = 0 if @alert_lock == nil @alert_lock -= 1 if @alert_lock >= 0 return if @alert_balloon == nil or @alert_balloon == 0 if (@chase_player or @flee_player) and !@alert_player @balloon_id = @alert_balloon @alert_player = true @alert_timer = YE::EVENT::ALERT_TIMER end return unless @alert_player @alert_timer -= 1 end #-------------------------------------------------------------------------- # see_player? #-------------------------------------------------------------------------- def see_player? return false if @see_player != true sx = distance_x_from_player sy = distance_y_from_player if sx.abs > sy.abs direction = sx > 0 ? 4 : 6 else direction = sy > 0 ? 8 : 2 end if direction == @direction if @sight_lock == nil or @sight_lock <= 0 @sight_lock = YE::EVENT::SIGHT_LOCK end @alert_lock = @sight_lock return true end return false end #-------------------------------------------------------------------------- # move_type_away_player #-------------------------------------------------------------------------- def move_type_away_player sx = @x - $game_player.x sy = @y - $game_player.y if sx.abs + sy.abs >= 20 move_random else case rand(5) when 0..3; move_away_from_player when 4; move_random end end end end # Game_Character #=============================================================================== # # END OF FILE # #===============================================================================