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.

SephirothSpawn's Encounter Control Script

Status
Not open for further replies.
I was looking for a script to use in my main game and I ran across SephirothSpawn's Encounter Control Script but when I clicked both links I get a 404 Error. Why is that? I it because that script and demo no longer in on the server or is it off for updates?
If anyone could repost it that would save me alot of pain from using events for monsters.
 
Code:
#==============================================================================
# ** Encounter Control
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1.01
# 2006-10-23
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- (2006-08-12)
#    Version 1.01 ------------------------------------------------ (2006-10-23)
#     - Bug Fix : Fixed Erase Event
#------------------------------------------------------------------------------
# * Requirements :
#
#   Near Fantastica's View Range Module
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to give you more control of Random Encounters
#   Encounter Control allows you give terrain tags, circular regions and
#   rectangular regions groups of enemies, instead of just map encounters.
#   Additionally, it allows you to view in the debugger the regions on the map
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#
#   Setting Up Terrain Groups (Game_Map::Terrain_Tag_Groups)
#   TTG = { map_id => { terrain_tag => [troop_id, ...], ... }, ... }
#   (Use 0 for map_id as a default for all maps, unless specified)
#
#   Setting Up Encounter Regions
#   Adds a Comment Line with this format:
#   Comment : Enc Ctrl <type>(<params>)[group_id, ...]
#
#   <type> = Circ (Circluar Region) or Rect (Rectangular Region)
#   Circular <params> = center_x, center_y, radius
#   Rectangular <params> = upper_left_x, upper_left_y, rect_width, rect_height
#------------------------------------------------------------------------------
# * Credits :
#
#   Thanks to Near Fantastica For His View Range Module
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Encounter Control', 'SephirothSpawn', 1.01, '2006-10-23')

#------------------------------------------------------------------------------
# * View Range Test
#------------------------------------------------------------------------------
unless SDK.state('View Range')
  # Print Error
  p 'View Range Module Not Found. Encounter Control Disabled.'
  # Disable Encounter Control
  SDK.disable('Encounter Control')
end

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state('Encounter Control')

#==============================================================================
# ** View Range Module Extension
#==============================================================================

module VR
  #--------------------------------------------------------------------------
  # * In Rect Range?
  #--------------------------------------------------------------------------
  def self.in_rect_range?(rect, object)
    return object.x.between?(rect.x, rect.x + rect.width) &&
       object.y.between?(rect.y, rect.y + rect.height)
  end
end

#==============================================================================
# ** Circle
#==============================================================================

class Circle
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :x
  attr_accessor :y
  attr_accessor :radius
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(x, y, r)
    @x, @y, @radius = x, y, r
  end
end

#==============================================================================
# ** Color
#==============================================================================

class Color
  #--------------------------------------------------------------------------
  # * To Hexidecimal
  #--------------------------------------------------------------------------
  def to_hex
    n = (self.red.to_i * 100) + (self.green.to_i * 10) + self.blue.to_i
    return eval "0x#{n.to_s(16)}"
  end
end

#==============================================================================
# ** Game_Event
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Circle Encounter Areas
  #--------------------------------------------------------------------------
  def seph_circle_enconter_areas
    # Starts Enc Areas
    enc_areas = {}
    # Return Enc Areas If No List
    return enc_areas if @list.nil? || @erased
    # Checks All Event Commands
    for i in 0...@list.size
      # Checks For Comment Line
      if @list[i].code == 108
        # If Parameters Include 'Enc Ctrl'
        if @list[i].parameters[0].upcase.include?('ENC CTRL')
          # Collect Encounter List For Area
          @list[i].parameters[0].dup.gsub(/\[(.+?)\]/, '')
          list = $1.split.collect! {|x| x.to_i}
          # Test For Circular Range
          if @list[i].parameters[0].upcase.include?('CIRC')
            @list[i].parameters[0].dup.gsub(/\((.+?)\)/, '')
            unless $1.nil?
              circ = eval "Circle.new(#{$1})"
              # Stores Enc List
              enc_areas[circ] = list
            end
          end
        end
      end
    end
    # Return Encounter List
    return enc_areas
  end
  #--------------------------------------------------------------------------
  # * Rect Encounter Areas
  #--------------------------------------------------------------------------
  def seph_rect_encounter_areas
    # Starts Enc Areas
    enc_areas = {}
    # Return Enc Areas If No List
    return enc_areas if @list.nil?
    # Checks All Event Commands
    for i in 0...@list.size
      # Checks For Comment Line
      if @list[i].code == 108
        # If Parameters Include 'Enc Ctrl'
        if @list[i].parameters[0].upcase.include?('ENC CTRL')
          # Collect Encounter List For Area
          @list[i].parameters[0].dup.gsub(/\[(.+?)\]/, '')
          list = $1.split.collect! {|x| x.to_i}
          # Test For Rect Boundaries
          if @list[i].parameters[0].upcase.include?('RECT')
            @list[i].parameters[0].dup.gsub(/\((.+?)\)/, '')
            unless $1.nil?
              rect = eval "Rect.new(#{$1})"
              # Stores Enc List
              enc_areas[rect] = list
            end
          end
        end
      end
    end
    # Return Encounter List
    return enc_areas
  end
end


#==============================================================================
# ** Game_Map
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # * Terrain Tags
  #   ~ map_id = > {terrain_tag => [troop_id, ...] }
  # * Use 0 For Default For All Maps
  # * To Overwrite Default, Include Map ID And Define or Leave Blank Terrain
  #--------------------------------------------------------------------------
  Terrain_Tag_Groups = {
    0 => {
    }
  }
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_enccntrl_gmmap_el encounter_list  
  #--------------------------------------------------------------------------
  # * Get Encounter List
  #--------------------------------------------------------------------------
  def encounter_list
    # Checks Terrain Tag Groups
    if Terrain_Tag_Groups.has_key?(@map_id)
      # Test For Player Terrain Tag
      if Terrain_Tag_Groups[@map_id].has_key?($game_player.terrain_tag)
        # Return List
        return Terrain_Tag_Groups[@map_id][$game_player.terrain_tag]
      end
    # Checks For Default
    elsif Terrain_Tag_Groups[0].has_key?($game_player.terrain_tag)
      # Return List
      return Terrain_Tag_Groups[0][$game_player.terrain_tag]
    end
    # Checks All Events
    for event in $game_map.events.values
      # Checks Circular Ranges Of Event
      circ_ranges = event.seph_circle_enconter_areas
      circ_ranges.each do |circle, list|
        # If Player In Range of Circle
        if VR.in_range?(circle, $game_player, circle.radius)
          # Return List
          return list
        end
      end
      # Checks Rect Ranges
      rect_ranges = event.seph_rect_encounter_areas
      rect_ranges.each do |rect, list|
        # If Player In Range of Rect
        if VR.in_rect_range?(rect, $game_player)
          # Return List
          return list
        end
      end
    end
    # Return Original Encounter List
    return seph_enccntrl_gmmap_el
  end
end

#==============================================================================
# ** Spriteset_Map
#==============================================================================

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_encctrl_gmmap_init initialize
  alias seph_encctrl_gmmap_update update
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Original Initialization
    seph_encctrl_gmmap_init
    # Creates Flash Data Table & Flash Tile Flag
    @tilemap.flash_data = Table.new($game_map.width, $game_map.height)
    @seph_encctrl_tilesflashing = false
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Original Update
    seph_encctrl_gmmap_update
    # If Debugging
    if $DEBUG
      # If A Button Is Pressed
      if Input.trigger?(Input::A)
        # If Tiles Flashing
        if @seph_encctrl_tilesflashing
          # Unflashes All Map Tiles
          for x in 0...$game_map.width
            for y in 0...$game_map.height
              @tilemap.flash_data[x, y] = 0
            end
          end
          # Turns Flashing Flag Off
          @seph_encctrl_tilesflashing = false
        # If Tiles Not Flashing
        else
          # Sets Up Colors Array (To Prevent Matching Colors
          @flashtile_colors = []
          # Checks All Events
          for event in $game_map.events.values
            # Flashes All Circular Ranges
            event.seph_circle_enconter_areas.keys.each do |circle|
              seph_flash_circular_range(circle, circle.radius)
            end
            # Flashes All Rect Ranges
            event.seph_rect_encounter_areas.keys.each do |rect|
              seph_flash_rect_range(rect)
            end
            # Turns Flashing Flag On
            @seph_encctrl_tilesflashing = true
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Flash Circular Range
  #--------------------------------------------------------------------------
  def seph_flash_circular_range(object, range)
    # Gets Flash Color
    color = get_random_color while color.nil? || 
            @flashtile_colors.include?(color)
    # Flashes Tiles Within Range
    x = object.x
    for i in (x - range)..(x + range)
      sa = (x - i).abs
      x_ = i < x ? x - sa : i == x ? x : x + sa
      y_ = Integer((range ** 2 - sa ** 2) ** 0.5)
      for j in (object.y - y_)..(object.y + y_)
        @tilemap.flash_data[i, j] = color.to_hex
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Flash Rect Range
  #--------------------------------------------------------------------------
  def seph_flash_rect_range(rect)
    color = get_random_color while color.nil? || 
            @flashtile_colors.include?(color)
    for x in 0...rect.width
      for y in 0...rect.height
        @tilemap.flash_data[rect.x + x, rect.y + y] = color.to_hex
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Get Random Color
  #--------------------------------------------------------------------------
  def get_random_color
    return Color.new(rand(18) * 15, rand(18) * 15, rand(18) * 15)
  end
end

#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end
 
Status
Not open for further replies.

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