Erm.. Charlie could you help me please? I have a question.
So, I want to show the NPCs in the Mini-Map. But I only see Enemy and Teleport commands to use through comments. Is it possible to show the NPCs through comments too?
I have a newer version in my HD. Although it isn't really ready to be released, I'm posting it here:
version 0.4.4
Code:
#==============================================================================
# ** Passability Mini-map by Charlie Fleed
#
# Version: 0.4.4
# Author: Charlie Fleed
#==============================================================================
#
# Instructions: use the commands show_passmap and hide_passmap to make the
# minimap appear and disappear, the last setting will be saved in your savefile.
#
#==============================================================================
PASSABILITY_MAP_H=48*2
PASSABILITY_MAP_W=64*2
PASSABILITY_MAP_X=16 #640-PASSABILITY_MAP_W-16
PASSABILITY_MAP_Y=480-PASSABILITY_MAP_H-16 #480-PASSABILITY_MAP_H-32-16
PASSABILITY_MAP_OPACITY=150
MAP_ZOOM=1
PASSMAP_BACKGROUND_IMAGE="passmap bg" # Put "" if not used
PASSMAP_BACKGROUND_OPACITY=255
PASSMAP_PLAYER_IMAGE=""
PASSMAP_ALLY_IMAGE=""
PASSMAP_ENEMY_IMAGE=""
PASSMAP_BG_COLOR=Color.new(102,90,66,255)
PASSMAP_FG_COLOR=Color.new(179,158,116,255)
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def redraw_passmap
$game_temp.redraw_passmap=true
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def hide_passmap
$game_system.minimap_visible=false
return
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def show_passmap
$game_system.minimap_visible=true
return
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Game_System
attr_accessor :minimap_visible
attr_accessor :minimap_opacity
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias minimap_initialize initialize
def initialize
minimap_initialize
@minimap_visible=true
@minimap_opacity=PASSABILITY_MAP_OPACITY
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Passability_Map < Sprite
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
@objects=Map_Objects.new(viewport)
self.opacity=$game_system.minimap_opacity
self.visible = ($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def renew
@map=Bitmap.new(4*$game_map.width,4*$game_map.height)
for x in 0...$game_map.width
Graphics.update
for y in 0...$game_map.height
temp=0
@map.fill_rect(x*4,y*4,4,4,PASSMAP_FG_COLOR)
if !$game_map.passable?(x,y,2) # DOWN
@map.fill_rect(x*4,y*4+3,4,1,PASSMAP_BG_COLOR)
temp+=1
end
if !$game_map.passable?(x,y,4) # LEFT
@map.fill_rect(x*4,y*4,1,4,PASSMAP_BG_COLOR)
temp+=1
end
if !$game_map.passable?(x,y,6) # RIGHT
@map.fill_rect(x*4+3,y*4,1,4,PASSMAP_BG_COLOR)
temp+=1
end
if !$game_map.passable?(x,y,8) # UP
@map.fill_rect(x*4,y*4,4,1,PASSMAP_BG_COLOR)
temp+=1
end
if temp==4
@map.fill_rect(x*4+1,y*4+1,2,2,PASSMAP_BG_COLOR)
end
end
end
@map.make_png(@name_map)
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def redraw
self.visible=false
renew
self.bitmap=Bitmap.new(@map.width/MAP_ZOOM,@map.height/MAP_ZOOM)
self.bitmap.stretch_blt(self.bitmap.rect,@map,@map.rect,255)
self.visible=($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def refresh
begin
Dir.mkdir 'Graphics/Pictures/pass_maps'
rescue
begin
Dir.mkdir 'Graphics/Pictures'
Dir.mkdir 'Graphics/Pictures/pass_maps'
rescue
begin
Dir.mkdir 'Graphics'
Dir.mkdir 'Graphics/Pictures'
Dir.mkdir 'Graphics/Pictures/pass_maps'
rescue
end
end
end
@name_map="Graphics/Pictures/pass_maps/pass_map_"+$game_map.map_id.to_s
begin
@map=Bitmap.new(@name_map)
rescue
renew
end
self.bitmap=Bitmap.new(@map.width/MAP_ZOOM,@map.height/MAP_ZOOM)
self.bitmap.stretch_blt(self.bitmap.rect,@map,@map.rect)
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def update
return unless @map!=nil
self.visible = ($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
@objects.visible=self.visible
return if not self.visible
player_x=(4*$game_player.real_x/128.0)/MAP_ZOOM
player_y=(4*$game_player.real_y/128.0)/MAP_ZOOM
tilesize=4/MAP_ZOOM
self.ox=[[0, player_x - self.viewport.rect.width/2 + tilesize/2].max,
@map.width/MAP_ZOOM-self.viewport.rect.width].min
self.oy=[[0, player_y - self.viewport.rect.height/2+ tilesize/2].max,
@map.height/MAP_ZOOM-self.viewport.rect.height].min
@objects.update
self.opacity=$game_system.minimap_opacity
@objects.opacity=self.opacity
# $scene.debug_window.draw_text(0,0,460,30,"map_w="+(@map.width/MAP_ZOOM).to_s+" h="+(@map.height/MAP_ZOOM).to_s+" viewport_w"+(self.viewport.rect.width).to_s+" viewport_h"+(self.viewport.rect.height).to_s,true)
# $scene.debug_window.draw_text(0,30,460,30,"ox="+self.ox.to_s+"\toy="+self.oy.to_s)
# $scene.debug_window.draw_text(0,60,460,30,"player_x="+player_x.to_s+"\tplayer_y="+player_y.to_s)
# $scene.debug_window.draw_text(0,90,460,30,(self.viewport.rect.height/2).to_s)
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def height
return [@map.height/MAP_ZOOM,self.viewport.rect.height].min
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def width
return [@map.width/MAP_ZOOM,self.viewport.rect.width].min
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Map_Objects < Sprite
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def update
if self.bitmap!=nil
self.bitmap.dispose
end
self.bitmap=Bitmap.new(4*$game_map.width/MAP_ZOOM,4*$game_map.height/MAP_ZOOM)
player_x=(4*$game_player.real_x/128.0)/MAP_ZOOM
player_y=(4*$game_player.real_y/128.0)/MAP_ZOOM
tilesize=4/MAP_ZOOM
self.ox=[[0, player_x - self.viewport.rect.width/2 + tilesize/2].max,
4*$game_map.width/MAP_ZOOM-self.viewport.rect.width].min
self.oy=[[0, player_y - self.viewport.rect.height/2+ tilesize/2].max,
4*$game_map.height/MAP_ZOOM-self.viewport.rect.height].min
# ENEMIES
for object in $game_map.events.values
if object.is_enemy?
object_x=(4*object.real_x/128.0)/MAP_ZOOM
object_y=(4*object.real_y/128.0)/MAP_ZOOM
if PASSMAP_ENEMY_IMAGE != ""
enemy_bitmap=RPG::Cache.picture(PASSMAP_ENEMY_IMAGE)
self.bitmap.blt([0,object_x-0.5*enemy_bitmap.width].max,
[0,object_y-0.5*enemy_bitmap.height].max,
enemy_bitmap,enemy_bitmap.rect,128)
else
self.bitmap.fill_rect(object_x+tilesize/4,object_y+tilesize/4,2/MAP_ZOOM,2/MAP_ZOOM,Color.new(255,0,0))
end
end
if object.is_teleport?
object_x=(4*object.real_x/128.0)/MAP_ZOOM
object_y=(4*object.real_y/128.0)/MAP_ZOOM
self.bitmap.fill_rect(object_x,object_y,4/MAP_ZOOM,4/MAP_ZOOM,Color.new(255,0,255,200))
end
end
# EVENTS
for object in $game_map.events.values
if KEYWORDS[object.event.name]
object_x=(4*object.real_x/128.0)/MAP_ZOOM
object_y=(4*object.real_y/128.0)/MAP_ZOOM
self.bitmap.fill_rect(object_x+tilesize/4,object_y+tilesize/4,2/MAP_ZOOM,
2/MAP_ZOOM,KEYWORDS[object.event.name]) unless object.no_map?
end
end
# ALLIES
unless $game_allies==nil
for ally in $game_allies.values
ally_x=(4*ally.real_x/128.0)/MAP_ZOOM
ally_y=(4*ally.real_y/128.0)/MAP_ZOOM
if PASSMAP_ALLY_IMAGE != ""
ally_bitmap=RPG::Cache.picture(PASSMAP_ALLY_IMAGE)
self.bitmap.blt([0,ally_x-0.5*ally_bitmap.width].max,
[0,ally_y-0.5*ally_bitmap.height].max,
ally_bitmap,ally_bitmap.rect,128)
else
self.bitmap.fill_rect(ally_x+tilesize/4,ally_y+tilesize/4,2/MAP_ZOOM,2/MAP_ZOOM,Color.new(150,150,0))
end
end
end
# HERO
if PASSMAP_PLAYER_IMAGE != ""
player_bitmap=RPG::Cache.picture(PASSMAP_PLAYER_IMAGE)
self.bitmap.blt([0,player_x-0.5*player_bitmap.width].max,
[0,player_y-0.5*player_bitmap.height].max,
player_bitmap,player_bitmap.rect,128)
else
self.bitmap.fill_rect(player_x+tilesize/4, player_y+tilesize/4,2/MAP_ZOOM,2/MAP_ZOOM,Color.new(0,0,255))
end
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def height
return [4*$game_map.height/MAP_ZOOM,self.viewport.rect.height].min
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def width
return [4*$game_map.width/MAP_ZOOM,self.viewport.rect.width].min
end
end
#class Window_Debug < Window_Base
# def draw_text(a,b,c,d,e,clean=false)
# if clean
# self.contents=Bitmap.new(width-32,height-32)
# end
# self.contents.draw_text(a,b,c,d,e)
# end
#end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Scene_Map
attr_accessor :map
# attr_accessor :debug_window
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias passmap_main main
def main
@map_viewport=Viewport.new(PASSABILITY_MAP_X,PASSABILITY_MAP_Y,
PASSABILITY_MAP_W,PASSABILITY_MAP_H)
@map_viewport.z=9999
@map_viewport.visible=true
@map=Passability_Map.new(@map_viewport)
@map.refresh
if PASSMAP_BACKGROUND_IMAGE != ""
@map_bg_viewport=Viewport.new(PASSABILITY_MAP_X+PASSABILITY_MAP_W-@map.width-8,
PASSABILITY_MAP_Y+PASSABILITY_MAP_H-@map.height-8,
@map.width+16,@map.height+16)
# p "width: %d, height: %d",@map.width,@map.height
@map_bg_viewport.z=9998
@map_bg_viewport.visible=($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
@map_bg=Sprite.new(@map_bg_viewport)
@map_bg.bitmap=RPG::Cache.picture(PASSMAP_BACKGROUND_IMAGE)
@map_bg.opacity=PASSMAP_BACKGROUND_OPACITY
@map_bg.zoom_x = 1.0*(@map_bg_viewport.rect.width)/@map_bg.bitmap.width
@map_bg.zoom_y = 1.0*(@map_bg_viewport.rect.height)/@map_bg.bitmap.height
end
# @debug_window=Window_Debug.new(0,0,640,180)
passmap_main
if PASSMAP_BACKGROUND_IMAGE != ""
@map_bg.dispose
@map_bg_viewport.dispose
end
@map.dispose
@map_viewport.dispose
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias passmap_update update
def update
passmap_update
if PASSMAP_BACKGROUND_IMAGE != ""
@map_bg_viewport.visible=($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
end
if $game_temp.redraw_passmap
@map.redraw
$game_temp.redraw_passmap=false
end
if $game_temp.refresh_passmap
@map.refresh
if PASSMAP_BACKGROUND_IMAGE != ""
@map_bg_viewport.rect.width=@map.width+16
@map_bg_viewport.rect.height=@map.height+16
@map_bg_viewport.rect.x=PASSABILITY_MAP_X+PASSABILITY_MAP_W-@map.width-8
@map_bg_viewport.rect.y=PASSABILITY_MAP_Y+PASSABILITY_MAP_H-@map.height-8
@map_bg.zoom_x = 1.0*(@map_bg_viewport.rect.width)/@map_bg.bitmap.width
@map_bg.zoom_y = 1.0*(@map_bg_viewport.rect.height)/@map_bg.bitmap.height
end
$game_temp.refresh_passmap=false
end
@map.update
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias passmap_setup setup
def setup(id)
passmap_setup(id)
$game_temp.refresh_passmap=true
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Game_Temp
attr_accessor :redraw_passmap
attr_accessor :refresh_passmap
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias passmap_initialize initialize
def initialize
passmap_initialize
@redraw_passmap=false
@refresh_passmap=false
end
end
def make_idat
header = "\x49\x44\x41\x54"
data = make_bitmap_data
data = Zlib::Deflate.deflate(data, 8)
crc = [Zlib.crc32(header + data)].pack("N")
size = [data.length].pack("N")
return size + header + data + crc
end
def make_bitmap_data
gz = Zlib::GzipWriter.open('hoge.gz')
t_Fx = 0
w = @bitmap_Fx.width
h = @bitmap_Fx.height
data = []
for y in 0...h
data.push(0)
for x in 0...w
t_Fx += 1
if t_Fx % 10000 == 0
Graphics.update
end
if t_Fx % 100000 == 0
s = data.pack("C*")
gz.write(s)
data.clear
end
color = @bitmap_Fx.get_pixel(x, y)
red = color.red
green = color.green
blue = color.blue
alpha = color.alpha
data.push(red)
data.push(green)
data.push(blue)
data.push(alpha)
end
end
s = data.pack("C*")
gz.write(s)
gz.close
data.clear
gz = Zlib::GzipReader.open('hoge.gz')
data = gz.read
gz.close
File.delete('hoge.gz')
return data
end
def make_iend
ie_size = [0].pack("N")
ie_sign = "IEND"
ie_crc = [Zlib.crc32(ie_sign)].pack("N")
return ie_size + ie_sign + ie_crc
end
end
end
class Bitmap
def make_png(name="Gui_Img_Save", path="",mode=0)
make_dir(path) if path != ""
Zlib::Png_File.open("temp.gz") {|gz|
gz.make_png(self)
}
Zlib::GzipReader.open("temp.gz") {|gz|
$read = gz.read
}
f = File.open(path + name + ".png","wb")
f.write($read)
f.close
File.delete('temp.gz')
end
def make_dir(path)
dir = path.split("/")
for i in 0...dir.size
unless dir == "."
add_dir = dir[0..i].join("/")
begin
Dir.mkdir(add_dir)
rescue
end
end
end
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def is_enemy?
if no_map?
return false
end
for p in @event.pages
for command in p.list
if command.code == 108
if command.parameters[0]=="Enemy"
return true
end
end
end
end
return false
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def is_teleport?
if no_map?
return false
end
for p in @event.pages
for command in p.list
if command.code == 108
if command.parameters[0]=="Teleport"
return true
end
end
end
end
return false
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def no_map?
if @page==nil
return true
end
for command in @page.list
if command.code == 108
if command.parameters[0]=="No Map"
return true
end
end
end
return false
end
end
As you can see, there's a new section in the configuration,
which allows you to define keywords to identify any event you want to be displayed on the map. You just need to put a comment in the first page of this event You have to name the event with that same keyword. Try it.
I copy-pasted the script. But at first it showed me could not find file passmap bg. I fixed it renaming my background image to that. But then when I play tested the game, it showed me another error. Here is a screenshot attached. (Click to view full size)
I guess there's a little piece missing. Sorry about that.
Code:
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
class Game_Event
attr_reader :event
end
Hi. Great work on your minimap. It's pretty cool. I have a suggestion that others may try if they don't want the drab gray map. Now there could be a flaw in this, but so far, it's worked for me. What I did is take screenshots of my map in the editor and stitch them together to make a full image of the map level. Then I play tested both maps. The script automatically generates the gray blocky map the first time you enter that map and then saves a pic of the map. From then on, if I understand it right, it uses the saved pick, named "passmapX" where x is the number index of your level map. So what I did was open those maps in Photoshop, and paste the pretty screenshot maps into the appropriate files. Then I scaled those to fit the small size of the image. From there I flattened the image, saved it with the exact same name, and wa la. In the game the script uses the pretty mini maps.
Is there any way the script might accidentally regenerate a map and save over the nice minimap pics? So far it hasn't but I haven't fully tested it. I think if I made changes to the passibility of the map it might generate a new gray map. So what do you all think?
I do have a question though? I want to make it so that when I hit the Y key it toggles the minimap. But every attempt I've tried doesn't seem to work. I don't know what I'm doing wrong. Could someone show how to do that? Thanks so much.
Let me include a screen shot of the fancy minimap using the default code, an image for the player, and a pretty map background.
That's a very good idea, outlandish. The image is not re-generated unless you delete it or specifically call the command for it, so your map will be used throughout the whole game.
In order to make the map appear/disappear you can either
1) call the commands "hide_passmap" and "show_passmap"
2) change the value of the boolean variable "$game_system.minimap_visible"
3) only in version 0.4.4, use a switch, the one configured at the line "HIDE_SWITCH_NUMBER=nn".
Of course you will have to do that in a common event that checks when the Y key is pressed and bla bla bla, i guess you know how to manage that part.
Thanks! I'm glad you like the idea about switching the passmap pics. By the same token you could take the minimap image that you've stitched together and make it a sepia tone to give it an old fashioned look. Skies really the limit.
Now I know you can add things like npcs and monsters to your mini map. But I can't seem to get it to work. I've added the graphics in the config and I've tried naming the events according to the Keywords, I've tried adding the keyword to the comment of the event. But I can't seem to make anything show up on the mini map except the player. I'm just not sure how it works. I'd really appreciate some help on that.
Also I keep trying to get the code to trigger the map on and off, and I don't seem to be doing it right. I've looked at other scripts and I'm just not sure what I'm doing wrong. Maybe you could correct my code to help me see what I have to do. Here's the code.
Code:
if Input.trigger?(Input::Y)
if $game_system.minimap_visible==true
hide_passmap
else
show_passmap
end
end
Edit: Ok, I'm stupid. I just reread your post and figured out how to make the various events appear on the map, though I'm still trying to figure out how to use images for the Keywords instead of the colored pixels. Also, I enlarged the pixel size of the blips to 4x4 so they show up better. Thant seems to help. As for the toggle switch, I figured out how to event it though it works kind of sketchy. I really want to figure out what I'm doing wrong with this trigger code. It's very much like code I've seen in other scripts, so I'm not sure where I messed it up. Anyway, thanks for making such a great script!
Any help would be appreciated. I must be doing something wrong but I can't figure what. Thanks so much.