RPG Maker Forums

Hello,


I'm using Fomar0153's Line of Sight script.


Currently I'm creating an area where the player has to sneak past patrolling enemies and use the environment to hide from them. However, I noticed that the enemies can actually see through walls. I would like the enemies to not see the player if there's a tile between them that cannot be passed.


Does anyone know how to modify the script in such a way? I will post the script below - hope that is ok.

Code:
=begin
Line of Sight
by Fomar0153
Version 1.0
----------------------
Notes
----------------------
Allows you to have events trigger when they see the player
----------------------
Instructions
----------------------
Nametag events with:
<sight x>
where x is the range.

Also the events should be either player touch or event touch.
----------------------
Known bugs
----------------------
None
=end

class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # * Trigger Map Event
  #     triggers : Trigger array
  #     normal   : Is priority set to [Same as Characters] ?
  #--------------------------------------------------------------------------
  def start_sight_event(x, y, triggers, normal)
    return if $game_map.interpreter.running?
    $game_map.sight_xy(x, y).each do |event|
      if event.trigger_in?(triggers)
        event.start
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Determine if Same Position Event is Triggered
  #--------------------------------------------------------------------------
  alias sight_check_event_trigger_here check_event_trigger_here
  def check_event_trigger_here(triggers)
    sight_check_event_trigger_here(triggers)
    start_sight_event(@x, @y, [1,2], true) if triggers.include?(1)
  end
end

class Game_Map
  #--------------------------------------------------------------------------
  # * Get Array of Events at Designated Coordinates
  #--------------------------------------------------------------------------
  def sight_xy(x, y)
    @events.values.select {|event| event.see?(x, y) }
  end
end

class Game_CharacterBase
  #--------------------------------------------------------------------------
  # * Determine Coordinate Match
  #--------------------------------------------------------------------------
  def see?(x, y)
    s = sight
    xx = [x, x - (@direction == 6 ? 1 : @direction == 4 ? -1 : 0) * s]
    yy = [y, y - (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) * s]
    @x.between?(xx.min, xx.max) && @y.between?(yy.min, yy.max)
  end
  #--------------------------------------------------------------------------
  # * Determine Range of Sight
  #--------------------------------------------------------------------------
  def sight
    if @sight.nil?
      if !@event.nil? && @event.name =~ /<sight (.*)>/i
        @sight = $1.to_i
      else
        @sight = 0
      end
    end
    @sight
  end
end

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Change Direction to Designated Direction
  #     d : Direction (2,4,6,8)
  #--------------------------------------------------------------------------
  def set_direction(d)
    super
    check_player_spotted
  end
  #--------------------------------------------------------------------------
  # * Determine if the player is in sight
  #--------------------------------------------------------------------------
  def check_player_spotted
    return if $game_map.interpreter.running? || @starting
    if @trigger == 2 && self.see?($game_player.x,$game_player.y)
      start if !jumping? && normal_priority?
    end
  end
end

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,450
Members
137,820
Latest member
georg09byron
Top