Fog of War
Version: 1.0
Author: modern algebra
Date: July 6, 2010
Version History
- <Version 1.0> 07.06.2010 - Original Release
Description
This script allows you to create "fog of war" on specified maps. This is a concept familiar to RTS games as it is used to hide the movement of enemy units when they are not in range of your own units. This script brings that concept to RMVX, and allows for two layers: a permanent one that is cleared forever once a unit explores the area, and a temporary one that is clear only for as long as it is within range of a unit. You can use either layer or both for any given map.
This script also allows for other events (not just the player) to have vision, and will hide other events not within direct vision of a unit unless you specify that event to show anyway.
Features
- Allows you to give any map you want a fog of war, a great feature for dungeons
- Has the ability to use two layers of fog of war, one that is cleared permanently once it comes in to sight, and one that is only cleared for as long as it is within sight
- Uses separate autotiles for each layer, with the ability to change the opacity of each
- You can use either or both layers for any given map
- Events that are under the fog of war will not be shown, unless the current page of it is tagged with a special comment (for using events as a third map layer)
- Sight is not limited to the player - you can also give an event sight by including a special comment on its page
- Can use diamond shaped clear or circular clear for any unit with sight
Screenshots
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg716.imageshack.us%2Fimg716%2F5136%2Ffowscreenshot.png&hash=2dbfd5f2ec517992779d40fccd6cd311920e1e6d)
Instructions
Please see the header of the script for instructions.
Script
Script is very long. Please retrieve it either from the text document (http://rmrk.net/index.php?action=dlattach;topic=39271.0;attach=20868) or demo (http://rmrk.net/index.php?action=dlattach;topic=39271.0;attach=20867).
Bug Fixes
[spoiler=Exit Site Uncleared]
If you re-enter a fog of war map at a different place than you exited, the sight radius will still be cleared at the site you exited. This patch fixes that:
#==============================================================================
# Clear Temporary Layer Patch
# Bug fix for Fog of War 1.0
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Description:
#
# There was a bug in the previous version where if you re-entered a map with
# fog of war at a different location than you exited, the sight radius from
# when the player exited would still be there. This patch fixes that bug.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Instructions:
#
# Paste this into its own slot below Fog of War but still above Main.
#==============================================================================
class Tilemap_FogofWar
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_hos_initz_fow_6yh2 initialize
def initialize (*args)
# Eliminate the top layer
$game_system.paint_fog ($game_map.map_id, 0, 2816)
$game_player.update_fow
ma_hos_initz_fow_6yh2 (*args) # Run original method
end
end
[/spoiler]
Credit
Thanks
- Wachunga, for the RMXP script that inspired the creation of this one
- Zeriab, for the Table Printout script
- Heartofshadow, for a bug report
Support
Please post in this topic at RMRK if you require support, no matter when this topic was last posted in. Do not PM me.
Known Compatibility Issues
No currently known compatibility issues, but it may interact strangely with some fog scripts.
Demo
See attached (http://rmrk.net/index.php?action=dlattach;topic=39271.0;attach=20867)
Graphics
I have attached a few fog of war autotiles as samples and free for use. "FogOfWar" (http://rmrk.net/index.php?action=dlattach;topic=39271.0;attach=20869) and "FogOfWar2" (http://rmrk.net/index.php?action=dlattach;topic=39271.0;attach=20870) I made myself, while "FogOfWar Wachunga" (http://rmrk.net/index.php?action=dlattach;topic=39271.0;attach=20871) is a resized version of the sample autotile Wachunga used in his RMXP script. All FogOfWar autotiles must be saved in System.
Also, the script has "FogOfWar2" built into it, and it will use that autotile if you have no fog of war autotiles in the System folder.
Author's Notes
I remember using Wachunga's Fog of War script when I first started using RMXP. It's a nice idea, so I figured I'd write my own RMVX one.
Holy cow... You even made your own default auto-tile through script...
I would never go so far for my scripts :P Great job. Could someone be working on an RTS Script?
It's also useful for TBS games in the vein of Fire Emblem, etc.
Awe-inspiring step forward yet again, Modern.
Quote from: Mikhail Faulken on July 06, 2010, 11:20:35 PM
It's also useful for TBS games in the vein of Fire Emblem, etc.
Awe-inspiring step forward yet again, Modern.
Speaking of which, do your forsee any compatability problems with any Tactical Battle System?
Quote from: cozziekuns on July 07, 2010, 12:05:12 AM
Speaking of which, do your forsee any compatability problems with any Tactical Battle System?
Not with GTBS, but I'll have to take a look-see.
I've never used any TBS, so I couldn't say for sure. It would depend on if it uses or inherits from Spriteset_Map, and you could only set vision for player units if it uses events to denote them. Assuming those two factors are present, it would probably work.
And, definitely not working on an RTS script. That could only have terrible application to RM :P
You are a genius if there ever was one. You could probably make a cleaner version than the GTBS (since GubiD used a large portion the XP version of his script, which made customisation kind of tedious in some ways).
I was wondering if you were interested in taking on a dynamic random dungeon generation script, if anything (there is one out already, but it has some problems). A Roguelike script, if you will ;)
Hmm i got an interesting idea. Don't know if something like this has already been made... (sorry if such thing already exists)
Is it hard to make two temporary 'fog of war' layers with possibility to set two independent sight radiuses? And i guess there must be a way to check if the player is in the 'darkness' or not.
I'm just still dreaming of realtime lighting&stealth system)
I've already seen a stealth script, but it felt incomplete without hiding-in-the-shadows routine)
I also tried to make stealth levels with parallax shadows. But the amount of eventing there was horrifying - to check all tiles on the map, if player is lit enough, whether or not the guards see him etc etc... And the main problem was that no matter how pretty hand-drawn shadows are, they were static.
So now its possible to make light sources, walking guards with torches and stuff like that)
That does sound like a really neat idea and a great idea that could probably use this script to the fullest of its capabilities. This does sound like it would be very hard to do with out any scripts.
oh and modern this is a really cool script you never seize to amazing any one with your scripts, and im sure like me every one is always looking foreword to that next one.
So what do you say, MA?
How much of the script needs to be changed? Two temporary layers, two radius, transparency and circular/diamond shape settings.
--edit--
like that) [spoiler](https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg594.imageshack.us%2Fimg594%2F9530%2Fexampleo.jpg&hash=284f33a245763e67faea23dcee93f203ef6704eb)[/spoiler]
It wouldn't be hard to do; if I get some time in the future I might do it, but I don't think it would look like that map - it looks like the parts with the fire are tinted. Are you actually wanting the fire layer to use a tinted autotile over the parts that it lights?
No-no, i just photoshop'd it like that) The glow effect around the light sources can be done separately with appropriate charsets or pictures, no need to do that with script.
Actually it can be enough with only one shadow layer, but with two layers shading will be smooth and not so blocky. Also i think that it can be used to determine the intensity of character lighting - is he fully, partially lit or in total darkness.
Gosh, if you'll manage to achieve that, it will be real masterpiece!
I really hope I don't get crunched into a little ball for necro-posting......
Anyway......I love this Fog of War system. I just can't get it to work with GTBS v1.5.1.4 (The most current)
If there's anyway you can find it in you heart to make a patch, or at least point me in the right direction, I would be most grateful......Thank You!
I am in the middle of exams right now so cannot do anything, but remind me after April and I will see if I'm not busy then.
Roger that.....
I'm getting married in a couple of weeks, so I'll probably bug you sometime in late May.....
Thank You!
Congratulations! Three cheers for marriage!
Just three though :P I'll cheer more for it when I'm not bitter and single.
HAHAHAHA.....My NOOB skills rock......
I copied the method used to make Wortona's Light effects, and multiple fogs Patches for GTBS.....
This patch will allow the Fog of War to work with GTBS......All I need now is a way to make the player view effect work......because GTBS is NOT run by events, but by sprite_sets....and it's really confusing... :(
At least this cuts down on future work.....and I'll try and find a way around this in the meantime.....
The power of NOOB runs strong within me!!!
#===============================================================================
# This Script is made specfically for usage with GTBS version 1.5.1.4 by GubiD.
#===============================================================================
#--------------------------------------------------------------
# Fog of War (modern_algebra) Patch
#--------------------------------------------------------------
if defined? (Tilemap_FogofWar)
class Spriteset_Battle_GTBS
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Create Tilemap
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modrnb_fow_crttilmp_5tf2 create_tilemap
def create_tilemap (*args)
modrnb_fow_crttilmp_5tf2 (*args) # Run Original Method
# Create viewport between tile and picture layers
@fow_viewport = Viewport.new (0, 0, Graphics.width, Graphics.height)
@fow_viewport.z = 40
data = $game_system.fow_data
$game_system.fow_reset_data ($game_map.map_id) if @tilemap.map_data.xsize != data.xsize || @tilemap.map_data.ysize != data.ysize
@fow_tilemap = Tilemap_FogofWar.new(@fow_viewport)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Dispose of Tilemap
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias malgbr_fow_dispmap_7yh2 dispose_tilemap
def dispose_tilemap (*args)
malgbr_fow_dispmap_7yh2 (*args) # Run Original Method
for i in 0...9 do @fow_tilemap.bitmaps[i].dispose end
@fow_tilemap.dispose
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update Tilemap
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias monaba_fogwar_tilmup_2fu8 update_tilemap
def update_tilemap (*args)
monaba_fogwar_tilmup_2fu8 (*args) # Run Original Map
@fow_tilemap.ox = @tilemap.ox
@fow_tilemap.oy = @tilemap.oy
@fow_viewport.visible = $game_map.fow_active
@fow_tilemap.update
end
end
end
Oh, its not dead? Nice!
I have come back from the awesomeness that is the Bahamas!!!!!! 8)
Anyway....back to reality.......
Ok....so I figured out how to show the Fog of War (FOW) on GTBS battles with the little scriplet I conjured up. The problem now becomes integrating FOW with the players on the GTBS map. Actors are spritesets instead of events......which makes the problem harder (at least for me it does).....
I don't think we have to worry about the enemies too much, because you probably don't want them to show if the players haven't found them.....I tried fiddling around with both your script and GTBS, and failed miserably....
I humbly ask for your help modern_algebra.....your status in the rpgmaker world is legendary.......any help would be most appreciated!
So, if the fog creates lag on the map, how do i fix this?
Well, does the fog create lag on the map? You could grab an anti-lag script to help prevent lag from other sources, but to reduce lag from the FOW I would need to take a look; there probably are ways I could make it more efficient than it is. But why the hypothetical? Is it causing lag or not?
Sorry cippy, I forgot all about you. If you still want it, send the demo you have to me and I will take a look
EDIT: If you experience lag using show_fow (0) change it to show_fow (1) and the script settings for opacity should be Permanant layer 255 temp layer 55 or whatever desired.
No worries modern.....I figured out how to implement it a few weeks ago......
I actually have taught myself ruby(With GubiD's awesome tutorial series) and have been scripting for a little bit....I usually go by Nelderson, not sure why I chose cippy for this site.....
Anyway......here it is:
Crap it exceeds the maximum characters.......just download this demo, it has it in there......
http://www.mediafire.com/?vqpas1a9uxruf2y
BTW: Your script does cause some lag, especially when dashing..... ::)
Have you thought of a way to create complete encapsulating darkness until explored, and in the wake leaves the 'post-shadow' that is the current default?
I'll look into ways of reducing the lag.
@Anski - I might be misunderstanding the question, but I think that's how it is now.
I meant like, that you can't see what's ahead at all. No tile set, no events, nothing, and when you explore it and leave it, it's left with that gray area with no events visible.
You can do that. Just fill the Fog of War tile with black and set the sight to 1. Or am I missing something?
Yeah, that's in the script I think - the screenshot might be a little confusing since I had cleared all the walkable tiles, but the white stuff is everything within visibility, the grey stuff is where you have explored but is no longer visible (hides events too) and the black stuff along the borders would cover the whole map and only go away once you've brought it into visibility.
Hey modern algebra, I just started using this script and I love it.
I did run into what appears to be a slight bug, however, when transferring maps. Using the scripted auto-tile, and the temporary vision type (where you have a sight radius and nothing is "permanently" revealed), if you hit a transfer player event and then return to that same map at any given time, the spot where you left is still revealed.
So, example, exit a map on the right side via a Transfer Player event and then come back to that map. The right side where you hit the event will still be revealed as if the player were standing there.
Did I explain that well enough? If not, I can add a screenshot for you. Keep up the awesome work!
I'm using it as a torch type thing for a maze, is there any way I can set the bright area to 3x3 square(non-diamond) and then switch back and forth between that and basic 2-square-dist diamond at random?
X
XXX XXX
XXX <--> XXXXX
XXX XXX
X
btw heart, I copied and pasted script and am only initiating with event and I don't have that prob :P
it only does it for me for like a split second then moves back to me
@Scalinger - yes, you can use the following code in a script call:
$game_player.create_vision_field (sight, circular?)
Ie. the following:
$game_player.create_vision_field (3, true)
would create the 3 radius circle while:
$game_player.create_vision_field (2, false)
would change it to 2 radius diamond.
I don't know what you mean by at random - you will need to event it so it's not totally random, but you could add some randomness through eventing.
@HoS - I see what you mean. I will whip up a fix.
sry, it's all good now lol
@HoS:
The fix:
#==============================================================================
# Clear Temporary Layer Patch
# Bug fix for Fog of War 1.0
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Description:
#
# There was a bug in the previous version where if you re-entered a map with
# fog of war at a different location than you exited, the sight radius from
# when the player exited would still be there. This patch fixes that bug.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Instructions:
#
# Paste this into its own slot below Fog of War but still above Main.
#==============================================================================
class Tilemap_FogofWar
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_hos_initz_fow_6yh2 initialize
def initialize (*args)
# Eliminate the top layer
$game_system.paint_fog ($game_map.map_id, 0, 2816)
$game_player.update_fow
ma_hos_initz_fow_6yh2 (*args) # Run original method
end
end
I spoke too soon.
This is what I tried..
var 16 and 17 are random, when they are equal it makes size1 diamond, when not equal, a circle
when your in the dark room it's suposed to active the circle and daimond pattern switch.
On the map I posted, the left side is like a lit room and the right side you use lantern but the problem is
when your in right side it stays to one shadow type then splotches it instead of doing a
random shadow pattern switch between circle and diamond.
http://dl.dropbox.com/u/33252047/Project2.zip
About the lag.
The script runs 60 times in a second, right?
Isn't there a way to make it run less times in a second? Maybe 40~50 times per second... ?
download this kgc library
the 'maplightening' decreases the number of events being processed on a map therefor decreasing lag
I have mine set to 65 events
http://www.mediafire.com/?jxouo3iebco
Thanks modern algebra!
Works like a charm now.
Been fiddling with the script. Great work. Being able to swap your own fog tileset in is a godsend.
Is there a quick way to adjust the player's sight range in-game? Say I have a player touch a magical rock, and it increases the sight range to 5, from the default 3?
Edit: if not, there's a very easy workaround by having various events with fog sight above the character at all times. So if the player's "fog sight" skill is 10, just turn the "10 fog sight" event on and have it follow above the player at all times.
THat would work, but there is a way to change it in game too:
Quote from: Instruction
# 2) Use the following code in a script command:
# set_unit_vision (event_id, radius, circular?)
# event_id : ID of the event you want to change. If 0, sets the
# vision of the current event; if -1, sets the player vision.
# radius : same as at line 71
# circular? : same as at line 73
Sothe following in a script call should do it:
set_unit_vision (-1, 5)
Ah, see, this is why they should have taught reading when I was in school :P
Thanks lol
Hey MA, not sure if you are still working with this or not, but a couple of questions. Is there a way to keep both the permanent and temporary layers on, but still make all current graphic events visible without having to code it with
\fow_vision[3, true]
Basically, I want to use the temporary fog layer more for decorative, as in, I can still see my event moving, and when it's in my line of vision it's clear, but when it's in the temporary layer it's a bit obscure but still visible, and of course when it's in a place I haven't explored yet it's hidden.
I imagine it's a minor adjustment in how this script reveals events, but not sure how that would be changed.
My second question was if you had plans porting this over to VX-Ace, unless you already had and I'm missing it? Seeing as it's been a benefit with the last two makers, I think this would be great in Ace.
Thanks!
Well, you can put a comment on the first line of an event page which has the following code:
\ignore_fow
If you really wanted to do it for every event, then you could also go to the following line in the script:
@ignore_fow = !comment[/\\IGNORE_FOW/i].nil?
And change it to:
@ignore_fow = true
You, my friend, are a genius!
can someone help i keep getting this error
Script 'Fog of War' line 175: SyntaxError occurred.
unexpected ',', expecting ')'
ma_fow_systm_2fk9 (filename, *args)
This script is for VX. You are trying to insert it in to RMVX Ace.
I'm probably just blind, but is there a way to register whether or not another event is within your sight range? If so, I'm not seeing it. I would very much like to use this as a stealth system. It's perfect for simulating dim lighting combined with distance to your target. I realized recently that a game based around assassination should probably include at least one stealth feature.
EDIT: Also, is it possible to simply change the opacity of other events that are out of your sight range, or do they have to turn completely invisible?
If you have the x and y coordinates of the events, then you can check:
$game_system.square_visible?(x, y)
As for whether you can just reduce the opacity instead of making it fully transparent, the answer is no, that's not a feature built into this script. You can, however, have events ignore the fog of war altogether by placing the \ignore_fow code into the first comment of the event. That won't reduce the opacity, but it will make them visible at least under the temporary fog.
Oh well. Thanks anyway, this does help a lot.