Galv’s Visibility Range V.1.1

Demo – Version 1.0 > (Demo uses old version)

#------------------------------------------------------------------------------#
#  Galv's Visibility Range
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.1
#------------------------------------------------------------------------------#
#  2014-02-11 - Version 1.1 - added z level setting
#  2013-05-31 - Version 1.0 - release
#------------------------------------------------------------------------------#
#  This script can make the player only able to see in a certain radius around
#  themself. The rest is darkness. This size and opacity of this darkness is
#  controlled using variables and turned on/off using a switch.
#
#  Put this script below Materials and above main.
#  Requires an image that can be found in the demo on galvs-scripts.com. Images
#  for this script go in your /Graphics/System folder.
#------------------------------------------------------------------------------#

#------------------------------------------------------------------------------#
#  SCRIPT CALL
#------------------------------------------------------------------------------#
#  visimage("ImageName")       # Can change the image used
#------------------------------------------------------------------------------#


($imported ||= {})["Galv_Vis_Range"] = true
module Galv_Vis

#------------------------------------------------------------------------------#
#  SETTINGS - Don't forget to set these to unused variables and switch!
#------------------------------------------------------------------------------#

  SWITCH = 5000      # This switch turns the visibility range on/off. Default OFF

  SIZEVAR = 5000     # This variable controls how far player can see. Default 100

  OPACITYVAR = 2  # This variable controls the darkness opacity.   Default 255
  
  
  Z_LEVEL = 0      # Make this higher or lower to change the z level 
                   # (to make it appear above or below other stuff)

#------------------------------------------------------------------------------#
#  END SETTINGS
#------------------------------------------------------------------------------#

end # Galv_Vis


class Spriteset_Map
  alias galv_vis_sm_initialize initialize
  def initialize
    create_visrange if $game_switches[Galv_Vis::SWITCH]
    galv_vis_sm_initialize
  end
  
  def create_visrange
    @visrange = Sprite.new
    @visrange.bitmap = Cache.system($game_system.visimage)
    @visrange.ox = @visrange.bitmap.width / 2
    @visrange.oy = @visrange.bitmap.height / 2
    @visrange.z = Galv_Vis::Z_LEVEL
  end
  
  alias galv_vis_sm_update update
  def update
    galv_vis_sm_update
    update_visrange
  end
  
  def update_visrange
    if $game_switches[Galv_Vis::SWITCH]
      create_visrange if !@visrange
      @visrange.x = $game_player.screen_x
      @visrange.y = $game_player.screen_y - 16
      @visrange.opacity = $game_variables[Galv_Vis::OPACITYVAR]
      zoom = [$game_variables[Galv_Vis::SIZEVAR].to_f * 0.01,0.5].max
      @visrange.zoom_x = zoom
      @visrange.zoom_y = zoom
    else
      dispose_visrange
    end
  end
  
  alias galv_vis_sm_dispose dispose
  def dispose
    galv_vis_sm_dispose
    dispose_visrange
  end
  
  def dispose_visrange
    return if !@visrange
    @visrange.bitmap.dispose
    @visrange.dispose
    @visrange = nil
  end
end # Spriteset_Map


module DataManager
  class << self
    alias galv_vis_dm_setup_new_game setup_new_game
  end
  
  def self.setup_new_game
    galv_vis_dm_setup_new_game
    $game_system.init_visvars
  end
end # DataManager


class Scene_Map
  attr_accessor :spriteset
end

class Game_System
  attr_accessor :visimage

  def init_visvars
    @visimage = "VisRange"
    $game_variables[Galv_Vis::OPACITYVAR] = 255
    $game_variables[Galv_Vis::SIZEVAR] = 100
  end
end


class Game_Interpreter
  def visimage(img)
    $game_system.visimage = img
    SceneManager.scene.spriteset.dispose_visrange
  end
end
Advertisements

13 thoughts on “Galv’s Visibility Range V.1.1

  1. arkhamvi says:

    I have a question, how do I get this to have a timer?

  2. Just added this in a project I am working on. Just happened to add my first cave into it, and decided to go looking through some random scripts and seen this. Loving it and the site so far. Keep up the good work.

  3. Does the visibility range turns off when an enemy jumped at you at random encounter? If no, I’m probably gonna have to ask your permission to “try” editing some things to your script 4 my game (only if I succeed). Sorry for bothering

  4. stannellc says:

    Can anyone tell me if this script will work with MV as well? Thanks.

  5. HeyZetsu says:

    Since I’m just a beginner. How can you resize the “SIZEVAR” :'( ?

  6. Can this be set on using specific switches?
    Like if i only wanted this to be used when i have a switch on?

    • Galv says:

      Yes, in the settings you choose which switch turns it on or off:
      SWITCH = 5000 # This switch turns the visibility range on/off. Default OFF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s