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.

Help with the View Range script

Hello, I have a problem with near fantastica's view range script

I can't seem to let it work so that they only detect me in their line of sight, or a cone like so: /?\

I'd also like to know if there's any way to make it so that if you stand behind an object the enemie can't see you

Thanks in advance

(ps: I don't use SDK)
 
Well, nears view range I don't think has anything built in to stop enemies seeing through objects, instead you have to use a massive parallel process event with lots of x and y variables. I use the non SDK nears view range for a stealth game and have it all functioning.

You set it up like this:

$view_range.enemies_view(42, 5, 40)

42 = event ID, 5 = tiles distance they can see, 40 = the switch to turn on.
 
You need to use SDK v2.2 script to make it work properly. AND you should be using the anti-lag script as well. I'll explain this later.
Also, I recommend using the script ive put on this post instead of Near's. It's the same script but I've edited it so that the activating switch is a regular switch instead of a local switch.

I've labeled the switch IDs that you must change to whichever switches you want them to be in red and orange. The red switch is the switch that activates the event's action, such as follow. The orange switch is the switch that activates the circle around the event.
So, for example:

Notice how the event it set to custom. Inside custom, put turn switch 162 on. (remember to turn repeat action OFF) This is so that the event's circle only activates when it comes on screen. This prevents lag when there are several other events like this on the map. This is the reason to add the anti-lag script.
http://img161.imageshack.us/img161/7370/page1gp2.png[/IMG]
Now set page 2 to parallel process. The circle is now on. When the player enters the circle the switch 161 will turn on.
NOTE: In this image I've used "4" where the local switch number would previously be. This number does nothing and it does not matter what number you choose.
http://img406.imageshack.us/img406/9128/page2dk8.png[/IMG]
Now, enter what you want the event to do. If you want it to follow you, put approach on or use a custom movement. This page will constantly refresh as long as the player remains in the event's circle. At the end of custom movement make sure that you turn switch 161 off. Remember to keep repeat action off.
http://img504.imageshack.us/img504/6722/page3vf1.png[/IMG]

You don't want to use Near's default script because the self switch modifier enables all A, B, C, or D switches, and not just the one in the event itself, which can seriously complicate things.

Code:
#==============================================================================
#   Veiw Range Script
#------------------------------------------------------------------------------
#    By: Near Fantastica
#    Date: 25/11/04
#==============================================================================

class View_Range
#--------------------------------------------------------------------------
# ??? Range system works by sereching the area of a circle for the Player's xy
#    The Veiw is set in each event and is the radius of the circle
#    The Eaquation used is (Px-EX)^2 + (Py-Ey)^2 = radius^2
#    If the Radius is less than or equal to the View the Player is inside the circle
#--------------------------------------------------------------------------
attr_accessor :event_num
attr_accessor :view_range
#--------------------------------------------------------------------------
# ??? Initialization
#--------------------------------------------------------------------------
def initialize(event_num,veiw_range,els)
  @event_num = event_num
  @event_locial_switch = els
  @view_range = veiw_range
  @playerx = $game_player.x
  @playery = $game_player.y
  @eventx = $game_map.events[@event_num].x
  @eventy = $game_map.events[@event_num].y
  @event_direction = $game_map.events[@event_num].direction
end
#--------------------------------------------------------------------------
# ??? Event Veiw
#--------------------------------------------------------------------------
def event_view
  @playerx-=@eventx
  @playerx*=@playerx
  @playery-=@eventy
  @playery*=@playery
  @playerx+=@playery
  @view_range*=@view_range
  if @playerx <= @view_range
    $game_switches[[color=red]161[/color]] = true
    $game_map.need_refresh = true
  else
    $game_switches[[color=orange]162[/color]] = false
    $game_map.need_refresh = true
  end
end
#--------------------------------------------------------------------------
# ??? Enemies veiw
#--------------------------------------------------------------------------
def enemies_view    
  if @event_direction == 2
    if @playery >= @eventy
      @playerx-=@eventx
      @playerx*=@playerx
      @playery-=@eventy
      @playery*=@playery
      @playerx+=@playery
      @view_range*=@view_range
      if @playerx <= @view_range
        $game_switches[161] = true
        $game_system.timer = 420
        $game_system.timer_working = true
        $game_map.need_refresh = true
      end
    end
  end
  if @event_direction == 4
    if @playerx <= @eventx
      @playerx-=@eventx
      @playerx*=@playerx
      @playery-=@eventy
      @playery*=@playery
      @playerx+=@playery
      @view_range*=@view_range
      if @playerx <= @view_range
        $game_switches[161] = true
        $game_system.timer = 420
        $game_system.timer_working = true
        $game_map.need_refresh = true
      end
    end
  end
  if @event_direction == 6
    if @playerx >= @eventx
      @playerx-=@eventx
      @playerx*=@playerx
      @playery-=@eventy
      @playery*=@playery
      @playerx+=@playery
      @view_range*=@view_range
      if @playerx <= @view_range
        $game_switches[161] = true
        $game_system.timer = 420
        $game_system.timer_working = true
        $game_map.need_refresh = true
      end
    end
  end
  if @event_direction == 8
    if @playery <= @eventy
      @playerx-=@eventx
      @playerx*=@playerx
      @playery-=@eventy
      @playery*=@playery
      @playerx+=@playery
      @view_range*=@view_range
      if @playerx <= @view_range
        $game_switches[161] = true
        $game_system.timer = 420
        $game_system.timer_working = true
        $game_map.need_refresh = true
      end
    end
  end
end
#--------------------------------------------------------------------------
# ??? check = View_Range.new(EventID, Veiw Range, Local Switch)
#    check.enemies_straight_view
#--------------------------------------------------------------------------
def enemies_straight_view
 # checks the x direction
 if @playerx == @eventx
   $game_switches[161] = true
   $game_map.need_refresh = true
 end
 # checks the y direction
 if @playery == @eventy
   $game_switches[161] = true
   $game_map.need_refresh = true
 end
end
end

I also recommend using the Pixel Movement script with this script. To make the 2 compatible with each other, you need to add this into the script:

Code:
  @playerx /= 32
  @playery /= 32
  @eventx /= 32
  @eventy /= 32

inbetween "@eventy = $game_map.events[@event_num].y" and "@event_direction = $game_map.events[@event_num].direction" in the Initialization set near the top of the script.
 

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