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.

View Range (Radius) Script

Radius Script
(Otherwise known as View Range)

This script is made in it's entirety by Monsta. This script was located on a German website and is okay to use as long as you credit Monsta.

Overview
This script allows an event to "see" the player or another event within a certain number of tiles.

Original Script in German
Code:
#==========Radius Script=========#
#============by Monsta===========#
#=====Version 1.0===24.5.2007====#

# Aufrufen #
# in_radius?(id_sehendes_event,id_gesehendes_event,sichtweite,sichtform,testfenster_anzeigen)

# Der Player hat die ID 0, kann aber auch mit "Player" angegeben werden
# Mit "All" beim gesehenden Event, bekommt man einen Array mit allen gesehenden Events


class Interpreter
  RADIUS = [ [[],[0],[-1,0,1],[-1,0,1],[-2,-1,0,1,2],[-2,-1,0,1,2],[-3,-2,-1,0,1,2,3],[-3,-2,-1,0,1,2,3]],      # Sicktkegel 1
             [[-1,0,1],[-2,-1,0,1,2],[-3,-2,-1,0,1,2,3],[-4,-3,-2,-1,0,1,2,3,4],[-5,-4,-3,-2,-1,0,1,2,3,4,5]] ] # Sicktkegel 2
             
  def in_radius?(id1,id2,radius=7,radius_form=0,windows=false)
    @all = false
    if windows == true
     @radius_windows = {}
     delete_radius_windows
    end
    if (id1.is_a?(String) and id1.downcase == 'player') or id1 == 0
      char1 = $game_player
    else
      char1 = $game_map.events[id1]
    end
    if id2.is_a?(String)
     if id2.downcase == 'player'
      char2 = $game_player
    elsif id2.downcase == 'all'
       @all = []
     end
    else
      char2 = id2 == 0 ? $game_player : $game_map.events[id2]
    end
    if radius >= RADIUS[radius_form].size
      print ("Fehler im Skript: Radius Skript\n\nDer Radius ist größer als die Radiusangabe")
      return false
    end
    for i in 0..radius
      for r in RADIUS[radius_form][i]
       case char1.direction
       when 2 # Runter
        x = char1.x + r
        y = char1.y + i
       when 4 # Links
        x = char1.x - i
        y = char1.y - r
       when 6 # Rechts
        x = char1.x + i
        y = char1.y + r
       when 8 # Hoch
        x = char1.x + r
        y = char1.y - i
      end
       @radius_windows["#{i},#{r}"] = Radius_Color.new(x,y) if $DEBUG and windows
       id = $game_map.id_coordinates(x,y)
       if @all == false         
        return true if id == char2.id
       else
        @all += [id] if id != -1
       end
      end
    end
    if @all == false or @all == []
     return false
   else
    return @all
   end
  end
 
  def delete_radius_windows
    @radius_windows.each_value{|w|w.dispose if w != nil and w.disposed? == false} if @radius_windows != nil
  end
end

class Game_Map
  def id_coordinates(x=0,y=0)
    @events.each {|e|return e[1].id if e[1].x == x and e[1].y == y}
    return 0 if $game_player.x == x and $game_player.y == y
    return -1
  end
end

class Radius_Color < Window_Base
  def initialize(x,y)
    super(x * 32, y * 32, 20, 20)
    self.contents = Bitmap.new(width, height)
    self.opacity = 170
  end
end

Because it's in German, there may be quite a bit of confusion. Here's where I come in.

Instructions
Installing the script: Place it above "Main." Just like every other script.

Setting up an event:
1.) Make an event and set it to Parallel Process.
2.) Make a conditional Branch using the "Script" function.
3.) Insert this piece of code:
Code:
in_radius?(6,'Player',6,0)

The first "6" is the event ID that is "seeing." The next section is the thing that it sees. In this case it sees the Player. The next "6" is the number of tiles in which the event sees. Leave the "0."

To make an event see another event place this code in a Conditional Branch:
Code:
in_radius?(@event_id,2,7,0,true)

In this code, the "2" is the event that it's seeing. "7" is the number of tiles it can see.

It might sound a bit complicated, so for those people who don't want to read it, here's a demo.

Demo
http://www.mediafire.com/?zishkmzdgyt

Again, it's free to use and post, but make sure to credit Monsta completely. :wink:
 
Sounds interesting, but the event has to be a parallel process? Man, there's gotta be a better implementation of this idea.
 
You only really need one parallel process to make every event to want to see. It's even more user-friendly than Near_Fantastica's "Veiw Range."

But just a quick question, does the event see in a circle all the way around it? Do you think you could make a function so it only sees in a semi-circle in front?
 
It is very user friendly indeed.

The event sees in front of it only, which is more realistic. If you command the event to see 8 tiles in front of him the tiles slowly spread out.
 
can you use this to play sound effects such as water flowing, ect. when a player gets close to an object? or is there an easier script for that? and can you make it see more than like right in front of it? like what regi said, a circle or semi circle...
 

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