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
I have a question, how do I get this to have a timer?
Use eventing. I recommend asking in an rpgmaker forum for help with that.
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.
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
Oh, nevermind. I’m probably gonna use an event call (only if I could). Sorry for bothering
I was saying if the visibility range would turned off on random encounter. Once again, sorry
Nice for Horror Games!
Can anyone tell me if this script will work with MV as well? Thanks.
Ace scripts are not compatible with MV, but I have made an MV version of this that can be found here:
Since I’m just a beginner. How can you resize the “SIZEVAR” :'( ?
The size var refers to a variable number that you change using event command “Control Variables”
Can this be set on using specific switches?
Like if i only wanted this to be used when i have a switch on?
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
i put the script under materials but i’m getting this error message.
—————————
game
—————————
Script ‘Cache’ line 88: NoMethodError occurred.
undefined method `empty?’ for nil:NilClass
—————————
OK
—————————
Here’s a list of things to try and error trap what happened:
Hello i do the same as you required and check all errors using script you post
i still got this
Script ‘Game_Interpreter’ line 450: NoMethodError occurred.
undefined method `x’ for nil:NilClass
—————————
OK
Check your syntax for errors (use demo for example). Make sure you start a new game, don’t load a save file that was saved prior to adding the script.
I hate to be the one to ask, but how do you use this script exactly?
To use the script you need to read the instructions at the top of the script and also download the demo and examine the examples of how it works.
I tried to use this script, but this caused the Message Box to get squashed, making all of the text unreadable.
I used the Yanfly’s Message System script and is there a fix for that?
That’s odd – this plugin shouldn’t affect message boxes.