Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Follow/Chase ((When in view)) Script?

I know that this script exists, I just can't find it. I looked up View Range, etc. and I can't seem to find what I'm looking for.

The script basically has it so that when you come into view of a character/monster on the map, they'll begin to chase you.

The reason I want this script, is because I am working on a zombie game and when I use the regular path finding event ((I think that's what it's called)), the zombies start to chase the player even if they are behind a wall or facing the other direction.

Thanks!
 
LoL, its not a script. When you go to event, at autonomous movements on the side click there where seas fixed and then select approach. All done!!! They will follow you. But if you want them to follow you at hight friqu. click there where is 3:Low, and select 5:Very Hight.
 
That's not what I'm looking for. When I do that event, no matter where your character is on the screen... the monster will follow you. I want it to be so that the monster won't start to chase you until it SEES you.

The point of this is, it chases you... touches you... and you fight.
 

Jason

Awesome Bro

NemanjaT":2rvjsokr said:
LoL, its not a script. When you go to event, at autonomous movements on the side click there where seas fixed and then select approach. All done!!! They will follow you. But if you want them to follow you at hight friqu. click there where is 3:Low, and select 5:Very Hight.

I don't think you understand what he means, let me give you an example that doesn't involve zombies;

Have you ever played WoW or Guildwars ? If so, you'll know what an aggro bubble is, it's pretty much that,

If not;

Basically, he is able to give an enemy an "Aggro bubble" which could be a 5 tile radius around the enemy, if the player enters tha 5 tile radius, the enemy will proceed to chasing the player until either A) The player is dead, or B) The player has escaped the aggro bubble.

@ OP
viewtopic.php?f=12&t=30648&hilit=Near+Fantastica

Second post down has the script.

However, I have no idea how to use it.
 
jbrist":1fwbnteb said:
NemanjaT":1fwbnteb said:
LoL, its not a script. When you go to event, at autonomous movements on the side click there where seas fixed and then select approach. All done!!! They will follow you. But if you want them to follow you at hight friqu. click there where is 3:Low, and select 5:Very Hight.

I don't think you understand what he means, let me give you an example that doesn't involve zombies;

Have you ever played WoW or Guildwars ? If so, you'll know what an aggro bubble is, it's pretty much that,

If not;

Basically, he is able to give an enemy an "Aggro bubble" which could be a 5 tile radius around the enemy, if the player enters tha 5 tile radius, the enemy will proceed to chasing the player until either A) The player is dead, or B) The player has escaped the aggro bubble.

@ OP
viewtopic.php?f=12&t=30648&hilit=Near+Fantastica

Second post down has the script.

However, I have no idea how to use it.

Exactly what I was looking for! Thanks so much! Now I just need to play around with it and get it to work.

Thanks again!
 
Sorry for the double post... but does anybody know how to set it up?

I pasted the script into the script database.

I made an event with a character graphic and changed the movement to "Custom" and I entered the name of the script.

But... unedited, when I get close to the event, the script has an error and the game crashes. I can only assume it's because I need to do something in order for it to work.

What do I need to edit? The script doesnt tell me.
 

Yin

Member

I use this one.

Code:
#--------------------------------------------------------------------------

#             Enemy Detection System

#             by Gubid - 8/12/07

#             v 1.2.2 Updated 10/2/07

#--------------------------------------------------------------------------

#Description:

#This system allows events that are named something including "ENEMY" then

#that event will be told to approach Game_Player, until Game_Player has gotten

#a specified distance away. At that time event will return to its original

#position if desired. If you happen to get close enough to the returning event

#it will begin to follow you again.

#

#Thanks to Near Fantasia for supplying the slightly modified path finding script.

#--------------------------------------------------------------------------

#if there are any questions as to the use of this script or

#modifications/additions/etc, please post it to the thread on CreationAyslum.net

#--------------------------------------------------------------------------

 

#--------------------------------------------------------------------------

#Update_Detect - How to Stop Detection if desired

#--------------------------------------------------------------------------

#1. Within a event, add a SCRIPT (3rd page)

#2. type "update_detect(EVENT_ID, TRUE/FALSE)" -Note: it defaults to false

 

#--------------------------------------------------------------------------

#RETURN TO POSITION

#--------------------------------------------------------------------------

#Use this to determine if you would like the event to return to its original

#position or not.

#--------------------------------------------------------------------------

RETURN_TO_POSITION = true

 

#--------------------------------------------------------------------------

#CHASE_SPEED and ENABLE_SPEED_CHANGE

#--------------------------------------------------------------------------

#Use this to set the speed in which enemies will approach after spotting you

#and whether or not their speed will change.

#--------------------------------------------------------------------------

CHASE_SPEED = 3

ENABLE_SPEED_CHANGE = true

 

#--------------------------------------------------------------------------

#VIEW_RANGE

#--------------------------------------------------------------------------

#Use this to set the distance in which you must be in order to start the detection

#process, or escape to stop.

#--------------------------------------------------------------------------

VIEW_RANGE = 5

 

#--------------------------------------------------------------------------

#ESCAPE_RANGE

#--------------------------------------------------------------------------

#Use this to set the distance in which you must escape to stop the detection process

#--------------------------------------------------------------------------

ESCAPE_RANGE = 9

 

#--------------------------------------------------------------------------

#Other Notes

#--------------------------------------------------------------------------

#If the event has a custom move route, they will resume that route when finished

#chasing you, but if you dont set RETURN_TO_POSITION, then they will resume

#their custom route at the location they stopped chasing you.

 

class Game_Map

#--------------------------------------------------------------------------

# * Frame Update

#--------------------------------------------------------------------------

  alias en_detect_gm_update update

  def update

    en_detect_gm_update

    

    # Update map event

    for event in @events.values

      if !event.name.include?("enemy")

        next

      else

        if event.character_name != ""

          if event.stop_detect? 

            next

          end

          if check_distance(event.id) == true

            if event.exclamation == false

              event.old_type = event.move_type

              event.move_type = 2

              if ENABLE_SPEED_CHANGE

                event.old_speed = event.move_speed

                event.move_speed = CHASE_SPEED

              end

              event.exclamation = true

              event.animation_id = 98 #98 happens to be the exclamation animation

              event.f_route.clear

            end

          else

            if event.exclamation == true

              event.exclamation = false

              if RETURN_TO_POSITION == true

                if event.x != @map.events[event.id].x or event.y != @map.events[event.id].y

                  route = get_route(event, @map.events[event.id].x, @map.events[event.id].y)

                  event.run_route(route)

                end

              else

                event.restore_route

              end

            end

          end

        end

      end

    end

  end

  

  def check_distance(id = nil)

    unless id == nil

      event = $game_map.events[id]

      range = ($game_player.x - event.x).abs + ($game_player.y - event.y).abs

      

      if range <= VIEW_RANGE and range > 0

        return true

      elsif range <= ESCAPE_RANGE and range > 0 and event.exclamation

        return true

      end

    end

  end

 

  def get_route(event, x=0, y=0)

    target_x = x

    target_y = y

    max = (target_x - event.x).abs + (target_y - event.y).abs + 5

    position = [[event.x, event.y]]

    route = [[]]

    more_step = [0]

    for i in more_step

      x = position[i][0]

      y = position[i][1]

      if !position.include?([x, y + 1]) and event.passable?(x, y, 2)

        position.push([x, y + 1])

        route.push(route[i] + [2])

        if route[i].size + 1 < max

          more_step.push(route.index(route[i] + [2]))

        end

      end

  

      if !position.include?([x - 1, y]) and event.passable?(x, y, 4)

        position.push([x - 1, y])

        route.push(route[i] + [4])

        if route[i].size + 1 < max

          more_step.push(route.index(route[i] + [4]))

        end

      end

 

      if !position.include?([x + 1, y]) and event.passable?(x, y, 6)

        position.push([x + 1, y])

        route.push(route[i] + [6])

        if route[i].size + 1 < max

          more_step.push(route.index(route[i] + [6]))

        end

      end

 

      if !position.include?([x, y - 1]) and event.passable?(x, y, 8)

        position.push([x, y - 1])

        route.push(route[i] + [8])

        if route[i].size + 1 < max

          more_step.push(route.index(route[i] + [8]))

        end

      end

    end

    if position.index([target_x, target_y]) == false

      return [2]

    else

      return route[position.index([target_x, target_y])]

    end

  end

end

 

 

class Game_Event

  attr_accessor :move_type

  attr_accessor :move_speed

  attr_accessor :old_speed

  attr_accessor :exclamation

  attr_accessor :old_type

  attr_accessor :stop_trigger

  attr_reader   :f_route

 

  def initialize(map_id, event)

    super()

    @map_id = map_id

    @event = event

    @id = @event.id

    @erased = false

    @starting = false

    @through = true

    @name = @event.name

    @exclamation = false

    @f_route = []

    @step = 0

    @old_type = @move_type

    @old_move_route =  @move_route

    @old_speed = @move_speed

    @stop_trigger = false

    moveto(@event.x, @event.y)

    refresh    

  end

  

  def stop_detect? 

    return @stop_trigger

  end

    

  def restore_route

    @move_type = @old_type

    @move_route_index = @original_move_route_index

    @move_speed = @old_speed

    refresh

    return

  end

  

  def name

    return @name

  end

 

  alias en_det_update update

  def update

    if @f_route.size > 0

      run_path unless self.moving?

      if @f_route.size == 0

        restore_route

      end

    end    

    en_det_update

  end

  

  def run_route(route)

    @f_route = route

    @step = 0

  end

  

  def run_path

    if @f_route.size > 0

      if @f_route[@step] == nil

        @f_route = []

      end

      action = @f_route[@step]

      @step += 1

      case action

      when 2

        self.move_down

      when 4

        self.move_left

      when 6

        self.move_right

      when 8

        self.move_up

      end

    end

  end  

end

 

class Interpreter

  def update_detect(id, set = false)

    $game_map.events[id].stop_trigger = set

  end

 

  def spotted?

    is_true = 0

    for event in $game_map.events.values

      if event.exclamation

        is_true += 1

      end

    end

    if is_true > 0

      return true

    else

      return false

    end

  end

 

  def change_switch(id = 0, value = false, type = 0, switch = "A")

    if id > 0

      if type == 0 #for use of main switches

        #id is switch_id and value should set to true or false

        $game_switches[id] = value

      elsif type == 1 #For use of self switches

        #id is event.id and switch is the desired selfswitch. It must be text!

        #value is true or false

        key = [$game_map.map_id, id, switch]

        # Updates self switch

        $game_self_switches[key] = value

      end

      # Refresh map

      $game_map.need_refresh = true

      return true

    end

  end

end

 

All you have to do is put enemy in the event name. It works wonders. But it has a range, so I don't know if it's what you want. I think the enemy can see you even if you are behind it, but you can set the range.

EDIT: I put it in code.
 
Use code tags.

I also have this:
[rgss]#==============================================================================
# ** Encounter Detection Chaser
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1.01
# 2007-08-29
# SDK : Version 2.0+, Part I, II
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- (2007-08-16)
#    Version 1.01 ------------------------------------------------ (2007-08-29)
#     - Update : Moved move_toward_target method to MACL
#------------------------------------------------------------------------------
# * Requirements :
#
#   Method & Class Library 2.11+
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to allow you to make quick events chase your
#   player (or another event) with a simple comment line. You selete a target,
#   a chase speed and a start and stop range (when the target gets x distance).
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#
#   Comment : ENCOUNTER DETECTION a b c d e f
#
#   a : target (0 - player, event_id - event)
#   b : speed (movement speed)
#   c : start range (range when event starts chasing player)
#   d : stop range (range when event stops chasing player) (should be > c)
#   e : Animation id to display when in sight (optional)
#   f : animation id to display when giving up (optional, but requires e)
#------------------------------------------------------------------------------
# * Syntax :
#
#   You may change the chaser values, but when an event is refreshed, the
#   instance @encdet_is_chaser is reset to false and if any comment lines
#   are read, it will reset the instances as well.
#
#   Instance List : encdet_is_chaser, encdet_is_chasing, encdet_chase_target
#                   encdet_chase_speed, encdet_chase_start_range,
#                   encdet_chase_stop_range, encdet_chase_start_aid,
#                   encdet_chase_stop_aid
#
#   All instances of Game_Event
#------------------------------------------------------------------------------
# * Special Thanks :
#
#   Thanks to Khatharr for helping me debug the chaser bug.
#==============================================================================
 
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Encounter Detection Chaser', 'SephirothSpawn', 1.01, '2007-08-29')
SDK.check_requirements(2.0, [2], {'Method & Class Library' => 2.11})
 
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Encounter Detection Chaser')
 
#==============================================================================
# ** Game_Event
#==============================================================================
 
class Game_Event
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :encdet_is_chaser
  attr_accessor :encdet_is_chasing
  attr_accessor :encdet_chase_target
  attr_accessor :encdet_chase_speed
  attr_accessor :encdet_chase_start_range
  attr_accessor :encdet_chase_stop_range
  attr_accessor :encdet_chase_start_aid
  attr_accessor :encdet_chase_stop_aid
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_encdet_gmevt_init, :initialize
  alias_method :seph_encdet_gmevt_rsp,  :refresh_set_page
  alias_method :seph_encdet_gmevt_um,   :update_movement
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(*args)
    # Original Initialization
    seph_encdet_gmevt_init(*args)
    # Sets Enc Chaser Off if not on
    @encdet_is_chaser = false unless @encdet_is_chaser
  end
  #--------------------------------------------------------------------------
  # * Refresh Set Page
  #--------------------------------------------------------------------------
  def refresh_set_page
    # Original Set Page
    seph_encdet_gmevt_rsp
    # Sets Enc Chaser Off
    @encdet_is_chaser         = false
    @encdet_chase_start_aid   = nil
    @encdet_chase_stop_aid    = nil
    # Pass Through Event Commands
    for ec in @list
      # Skip if Not Comment Code
      next unless [108, 408].include?(ec.code)
      # Skip if Comment Doesn't Include Encounter Detection
      next unless ec.parameters[0].upcase.include?('ENCOUNTER DETECTION')
      # Gets Parameters
      pm = ec.parameters[0].split
      # Turn Chaser Flag On
      @encdet_is_chaser = true
      # Set Chasing Paramters
      t = pm[2].to_i
      @encdet_chase_target      = t == 0 ? $game_player : $game_map.events[t]
      @encdet_chase_speed       = pm[3].to_i
      @encdet_chase_start_range = pm[4].to_i
      @encdet_chase_stop_range  = pm[5].to_i
      @encdet_chase_start_aid   = pm[6].to_i if pm.size > 6
      @encdet_chase_stop_aid    = pm[7].to_i if pm.size > 7
      # Gets Range to Target
      range = VR.range(self, @encdet_chase_target)
      # Gets Chasing Status
      b = @encdet_is_chasing
      # Fix Chasing Status - If Chasing, Turn off if past stop range
      #                      If not chasing, turn on if within start range
      @encdet_is_chasing = b ? range > @encdet_chase_stop_range :
                               range <= @encdet_chase_start_range
      # If was chasing, but isn't anymore
      if b && @encdet_is_chasing == false && @encdet_chase_stop_aid != nil
        # Set to Non-chasing animation id
        @animation_id = @encdet_chase_stop_aid
      end
      # If wasn't chasing, but is now
      if b == false && @encdet_is_chasing && @encdet_chase_start_aid != nil
        # Set to chasing animation id
        @animation_id = @encdet_chase_start_aid
      end
      # Update Encounter Detection Movespeed
      update_encdet_movespeed
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Update Movement
  #--------------------------------------------------------------------------
  def update_movement
    # If Chaser
    if @encdet_is_chaser && moving? == false
      # Gets Range to Target
      range = VR.range(self, @encdet_chase_target)
      # If Chasing - Turn off if Range is greater than stop range
      if @encdet_is_chasing && range > @encdet_chase_stop_range
        @encdet_is_chasing = false
        # Set to Non-chasing animation id
        unless @encdet_chase_stop_aid.nil?
          @animation_id = @encdet_chase_stop_aid
        end
      # If Not Chasing But Range is Less that start range
      elsif !@encdet_is_chasing && range <= @encdet_chase_start_range
        # Turn Chasing On
        @encdet_is_chasing = true
        # Set to chasing animation id
        unless @encdet_chase_start_aid.nil?
          @animation_id = @encdet_chase_start_aid
        end
      end
      # If On, Move Toward Player
      if @encdet_is_chasing
        move_toward_target(@encdet_chase_target.x, @encdet_chase_target.y)
      end
    end
    # Update Enc Det Movespeed
    update_encdet_movespeed
    # Original Update Movement
    seph_encdet_gmevt_um
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Enc Det Movespeed
  #--------------------------------------------------------------------------
  def update_encdet_movespeed
    # If Chasing and Chase Speed isn't nil
    if @encdet_is_chasing && @encdet_chase_speed != nil &&
       @encdet_chase_old_speed.nil?
      # Save Old Speed
      @encdet_chase_old_speed = @move_speed
      # Set Move Speed to Chase Speed
      @move_speed             = @encdet_chase_speed
    # If Not Chasing and Old Speed has been set
    elsif @encdet_is_chasing == false && @encdet_chase_old_speed != nil
      # Restore Movespeed
      @move_speed = @encdet_chase_old_speed
      # Set Old Speed to nil
      @encdet_chase_old_speed = nil
    end
  end
  #--------------------------------------------------------------------------
  # * Move object toward target
  #--------------------------------------------------------------------------
  def move_toward_target(x, y)
    # Get difference in player coordinates
    sx = @x - x
    sy = @y - y
    # If coordinates are equal
    return if sx == 0 and sy == 0
    # Get absolute value of difference
    abs_sx = sx.abs
    abs_sy = sy.abs
    # If horizontal and vertical distances are equal
    if abs_sx == abs_sy
      # Increase one of them randomly by 1
      rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
    end
    # If horizontal distance is longer
    if abs_sx > abs_sy
      # Move towards player, prioritize left and right directions
      sx > 0 ? move_left : move_right
      if not moving? and sy != 0
        sy > 0 ? move_up : move_down
      end
    # If vertical distance is longer
    else
      # Move towards player, prioritize up and down directions
      sy > 0 ? move_up : move_down
      if not moving? and sx != 0
        sx > 0 ? move_left : move_down
      end
    end
  end
end
 
#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
end
[/rgss]
 
Yin":tku3hr5p said:
I use this one.

All you have to do is put enemy in the event name. It works wonders. But it has a range, so I don't know if it's what you want. I think the enemy can see you even if you are behind it, but you can set the range.

EDIT: I put it in code.

I Added a tiny Tweak to this script many moons ago that allows for Frequency change as well, so monsters will chase you at a set speed (basically giving them a fighting chance of actually catching up with you) This little edit allows you to set monster frequencies at anything you want by default, but when they spot you they speed up!

Code:
 

#--------------------------------------------------------------------------

#             Enemy Detection System

#             by Gubid - 8/12/07

#             v 1.2.2 Updated 10/2/07

#--------------------------------------------------------------------------

#Description:

#This system allows events that are named something including "ENEMY" then

#that event will be told to approach Game_Player, until Game_Player has gotten

#a specified distance away. At that time event will return to its original

#position if desired. If you happen to get close enough to the returning event

#it will begin to follow you again.

#

#Thanks to Near Fantasia for supplying the slightly modified path finding script.

#--------------------------------------------------------------------------

#if there are any questions as to the use of this script or

#modifications/additions/etc, please post it to the thread on CreationAyslum.net

#--------------------------------------------------------------------------

 

#--------------------------------------------------------------------------

#Update_Detect - How to Stop Detection if desired

#--------------------------------------------------------------------------

#1. Within a event, add a SCRIPT (3rd page)

#2. type "update_detect(EVENT_ID, TRUE/FALSE)" -Note: it defaults to false

 

#--------------------------------------------------------------------------

#RETURN TO POSITION

#--------------------------------------------------------------------------

#Use this to determine if you would like the event to return to its original

#position or not.

#--------------------------------------------------------------------------

RETURN_TO_POSITION = false

 

#--------------------------------------------------------------------------

#CHASE_SPEED and ENABLE_SPEED_CHANGE

#--------------------------------------------------------------------------

#Use this to set the speed in which enemies will approach after spotting you

#and whether or not their speed will change.

#--------------------------------------------------------------------------

CHASE_SPEED = 4

ENABLE_SPEED_CHANGE = true

CHASE_FREQUENCY = 6

ENABLE_FREQUENCY_CHANGE = true

 

#--------------------------------------------------------------------------

#VIEW_RANGE

#--------------------------------------------------------------------------

#Use this to set the distance in which you must be in order to start the detection

#process, or escape to stop.

#--------------------------------------------------------------------------

VIEW_RANGE = 12

 

#--------------------------------------------------------------------------

#ESCAPE_RANGE

#--------------------------------------------------------------------------

#Use this to set the distance in which you must escape to stop the detection process

#--------------------------------------------------------------------------

ESCAPE_RANGE = 14

 

#--------------------------------------------------------------------------

#Other Notes

#--------------------------------------------------------------------------

#If the event has a custom move route, they will resume that route when finished

#chasing you, but if you dont set RETURN_TO_POSITION, then they will resume

#their custom route at the location they stopped chasing you.

 

class Game_Map

#--------------------------------------------------------------------------

# * Frame Update

#--------------------------------------------------------------------------

  alias en_detect_gm_update update

  def update

    en_detect_gm_update

   

    # Update map event

    for event in @events.values

      if !event.name.include?("enemy")

        next

      else

        if event.character_name != ""

          if event.stop_detect?

            next

          end

          if check_distance(event.id) == true

            if event.exclamation == false

              event.old_type = event.move_type

              event.move_type = 2

              if ENABLE_SPEED_CHANGE

                event.old_speed = event.move_speed

                event.move_speed = CHASE_SPEED

              end

                if ENABLE_FREQUENCY_CHANGE

                  event.old_frequency = event.move_frequency

                  event.move_frequency = CHASE_FREQUENCY

                end

 

              event.exclamation = true

              event.animation_id = 98 #98 happens to be the exclamation animation

              event.f_route.clear

            end

          else

            if event.exclamation == true

              event.exclamation = false

              if RETURN_TO_POSITION == true

                if event.x != @map.events[event.id].x or event.y != @map.events[event.id].y

                  route = get_route(event, @map.events[event.id].x, @map.events[event.id].y)

                  event.run_route(route)

                end

              else

                event.restore_route

              end

            end

          end

        end

      end

    end

  end

 

  def check_distance(id = nil)

    unless id == nil

      event = $game_map.events[id]

      range = ($game_player.x - event.x).abs + ($game_player.y - event.y).abs

     

      if range <= VIEW_RANGE and range > 0

        return true

      elsif range <= ESCAPE_RANGE and range > 0 and event.exclamation

        return true

      end

    end

  end

 

  def get_route(event, x=0, y=0)

    target_x = x

    target_y = y

    max = (target_x - event.x).abs + (target_y - event.y).abs + 5

    position = [[event.x, event.y]]

    route = [[]]

    more_step = [0]

    for i in more_step

      x = position[i][0]

      y = position[i][1]

      if !position.include?([x, y + 1]) and event.passable?(x, y, 2)

        position.push([x, y + 1])

        route.push(route[i] + [2])

        if route[i].size + 1 < max

          more_step.push(route.index(route[i] + [2]))

        end

      end

 

      if !position.include?([x - 1, y]) and event.passable?(x, y, 4)

        position.push([x - 1, y])

        route.push(route[i] + [4])

        if route[i].size + 1 < max

          more_step.push(route.index(route[i] + [4]))

        end

      end

 

      if !position.include?([x + 1, y]) and event.passable?(x, y, 6)

        position.push([x + 1, y])

        route.push(route[i] + [6])

        if route[i].size + 1 < max

          more_step.push(route.index(route[i] + [6]))

        end

      end

 

      if !position.include?([x, y - 1]) and event.passable?(x, y, 8)

        position.push([x, y - 1])

        route.push(route[i] + [8])

        if route[i].size + 1 < max

          more_step.push(route.index(route[i] + [8]))

        end

      end

    end

    if position.index([target_x, target_y]) == false

      return [2]

    else

      return route[position.index([target_x, target_y])]

    end

  end

end

 

 

class Game_Event

  attr_accessor :move_type

  attr_accessor :move_speed

  attr_accessor :move_frequency 

  attr_accessor :old_speed

  attr_accessor :old_frequency

  attr_accessor :exclamation

  attr_accessor :old_type

  attr_accessor :stop_trigger

  attr_reader   :f_route

 

  def initialize(map_id, event)

    super()

    @map_id = map_id

    @event = event

    @id = @event.id

    @erased = false

    @starting = false

    @through = true

    @name = @event.name

    @exclamation = false

    @f_route = []

    @step = 0

    @old_type = @move_type

    @old_move_route =  @move_route

    @old_speed = @move_speed

    @old_frequency = @move_frequency

    @stop_trigger = false

    moveto(@event.x, @event.y)

    refresh    

  end

 

  def stop_detect?

    return @stop_trigger

  end

   

  def restore_route

    @move_type = @old_type

    @move_route_index = @original_move_route_index

    @move_speed = @old_speed

    @move_frequency = @old_frequency

    refresh

    return

  end

 

  def name

    return @name

  end

 

  alias en_det_update update

  def update

    if @f_route.size > 0

      run_path unless self.moving?

      if @f_route.size == 0

        restore_route

      end

    end    

    en_det_update

  end

 

  def run_route(route)

    @f_route = route

    @step = 0

  end

 

  def run_path

    if @f_route.size > 0

      if @f_route[@step] == nil

        @f_route = []

      end

      action = @f_route[@step]

      @step += 1

      case action

      when 2

        self.move_down

      when 4

        self.move_left

      when 6

        self.move_right

      when 8

        self.move_up

      end

    end

  end  

end

 

class Interpreter

  def update_detect(id, set = false)

    $game_map.events[id].stop_trigger = set

  end

 

  def spotted?

    is_true = 0

    for event in $game_map.events.values

      if event.exclamation

        is_true += 1

      end

    end

    if is_true > 0

      return true

    else

      return false

    end

  end

 

  def change_switch(id = 0, value = false, type = 0, switch = "A")

    if id > 0

      if type == 0 #for use of main switches

        #id is switch_id and value should set to true or false

        $game_switches[id] = value

      elsif type == 1 #For use of self switches

        #id is event.id and switch is the desired selfswitch. It must be text!

        #value is true or false

        key = [$game_map.map_id, id, switch]

        # Updates self switch

        $game_self_switches[key] = value

      end

      # Refresh map

      $game_map.need_refresh = true

      return true

    end

  end

end

 

Hope that Helps!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top