Actually, I think you have a point Z0.
It could be kind of useful to have an event with a < 0 Z-Index with Panoramas. For example, standing on top of a cliff with a Panorama, and an event sails off into the distance might need a negtive Z-Index. I dont want to try implementing at this
time because Panoramas move differently, and doing it like that may require messing with event movement. Over my head at this point. Might be useful for background birds, but not for Boats without more event movement stuff.
The 0 bug I came across I found happened while the player moved around on a bit larger maps. Events were disappearing as soon as I stepped below them, but reappeared when I walked back to my original position. Again, it could be useful in specific cutscenes with Panoramas.
I think Blizzard has a better idea of just returning 1 for flat sprites, way faster, but again, it takes away control of the stack order, like 2 flat sprites that stack on top of each other would revert to no direct control for the mapper to adjust, and it would be controlled by the Event ID for which ever one got the higher Event ID would be on top. What I wanted to accomplish was to give mappers more control than just surrendering to Event ID order.
In regards to comment #6 bug, got an example.
http://www.775.net/~heretic/downloads/rmxp/cat.php Map #4, Event at 9, 15, cut and paste, name disappears.
Im confused on the names bit. I'll trust your experience if you feel like renaming them to be less confusing to others.
Change Log:
Updated Comments for better explanations.
Pulled out set_z error msg, but left in error msgs in interpreter.
Pulled out developer errors. Errors just display in non Debug games as well.
Changed Title to "Event Z-Index Controller"
Revised Version
# ----------------------------------------------------------------------------
# Event Z-Index Controller by Heretic
# ----------------------------------------------------------------------------
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# - code reviewed, optimized, integrated into Tons of Add-ons, freed from
# potential bugs and beta tested by Blizzard
# - this add-on is part of Tons of Add-ons with full permission of the original
# author(s)
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Flat Sprites allows you to make large sprites look like they are laying flat
# on the ground. All EVENTS cover flat sprites. Non priority tiles will
# appear beneath a Flat Sprite Event.
#
# Added Controls added to allow Mappers more control over Event Z-Index, which
# is useful for Stacking Events or Event Layering. Event ID's used to determine
# which event would render on top of another. The Z-Index controls allow a
# mapper to determine which event will be on top of another without needing to
# fight with Event ID's.
#
# 32: Each Tile in RMXP is 32 pixels tall. If you need to adjust an
# events Z-Index, I recommend trying increments of 32 at first to get you
# closer to your goal. If you need to, you can specify any whole number
# that you wish.
#
# --- EVENT NAME RELATED---
#
# EV001\z_flat
# EV001\z_flat[32]
# EV001\z_add[32]
#
# To make an Event always render as flat, add to its nane "\z_flat".
#
# To make an Event always have an adjusted Z-Index, add to its name "\z_add[Int]".
#
# To make an Event always render as flat, but with an altered Z-Index,
# add to its name "\z_flat[Int]" (this is an equivalent to using \z_flat and
# \z_add[Int] together). Imagine having one graphic that has flat parts and
# other parts that should be standing.
#
# --- SCRIPTED EVENT RELATED ---
#
# To change a Standing Sprite to render as flat, use a Move Route Script
# for that event "set_flat". Useful for when changing graphics of Events.
#
# To specify a higher or lower Z-Index, use the optional parameter:
# such as "set_flat(Int)".
#
# To Reset a Sprite that is flat to stand up use a Move Route Script "reset_z".
# "reset_z" will check the name again for special name related Z-Index commands.
#
# To make a Manual Adjustment to a sprites Z-Index, use set_z(Int)
# and I recommend incrementing the Int by 32 either way.
#
# To clear any special Z-Index Related properties, run a script "clear_z".
#
# NOTE \z_add[0] will NOT be treated as a request for a FLAT SPRITE.
#
# NOTE 2: Special Properties like "\foo" in an Events Name appear
# to NOT COPY AND PASTE CORRECTLY at all times in RMXP Editor
# if you COPY AND PASTE an Event.
#
# This bug is difficult to reproduce. One project this bug occurs all the time
# but other projects it never occurs. Just be aware when moving events.
# ----------------------------------------------------------------------------
#==============================================================================
# Game_Event
#==============================================================================
class Game_Event
#----------------------------------------------------------------------------
# * Redefine initialize for new variables
#----------------------------------------------------------------------------
unless self.method_defined?(:flat_sprite_initialize)
alias :flat_sprite_initialize :initialize
end
def initialize(map_id, event, *args)
@z_flat = false
@z_add = 0
check_flat_sprites(event)
flat_sprite_initialize(map_id, event, *args)
end
#----------------------------------------------------------------------------
# * Check Each Event for a \z_flat and \z_add flag
#----------------------------------------------------------------------------
def check_flat_sprites(event)
# Initialize
@z_flag = false
@z_add = 0
# Check z_flat and use z_add if necessary
@z_flat = (event.name.clone.sub!(/\\z_flat\[[-]{0,1}(\d+)\]/i) {@z_add = $1.to_i} != nil)
# If z_flat was not defined with optional z
if !@z_flat
# Check default z_flat
@z_flat = (event.name.match(/\\z_flat/i) != nil)
# Check default z_add
event.name.sub(/\\z_add\[[-]{0,1}(\d+)\]/i) {@z_add = $1.to_i}
end
end
#----------------------------------------------------------------------------
# * Sets a sprite to render as Flat by saying its screen_z is 0 by default
#----------------------------------------------------------------------------
def set_flat(new_z = nil)
# Always Render as Flat regardless of size
@z_flat = true
# Set optional Z-Index override
@z_add = new_z if new_z.is_a?(Numeric)
end
#----------------------------------------------------------------------------
# * Sets the Z-Index of an Event via a Script instead of a Name
#----------------------------------------------------------------------------
def set_z(new_z)
# Expects new_z as an Argument. It adds whatever that value is to new number
if new_z != 0 and new_z.is_a?(Numeric)
# Manual Adjustment to Z-Index
@z_flat = false
@z_add = new_z
else
# Always Render as Flat regardless of size
set_flat
end
end
#----------------------------------------------------------------------------
# * Resets the Z-Index of an Event via a Script to get Name Properties
#----------------------------------------------------------------------------
def reset_z
check_flat_sprites(@event)
end
#----------------------------------------------------------------------------
# * Clears all Z-Index Related Properties. Will reset when a map is reloaded
#----------------------------------------------------------------------------
def clear_z
@z_flat = false
@z_add = 0
end
#----------------------------------------------------------------------------
# * Redefine screen_z for Flat Sprites
#----------------------------------------------------------------------------
unless self.method_defined?(:flat_sprite_screen_z)
alias :flat_sprite_screen_z :screen_z
end
def screen_z(height = 0)
# Just skip the whole thing if always-on-top is on
return flat_sprite_screen_z(height) if @always_on_top
# If using z_flag or z_add
if @z_flat || @z_add != 0
# Consider the Sprites Size and Adjust for it, check nil for no graphic
height = (height != 0 && height != nil) ? height : 0
end
# If using z_flag or z_add
z = flat_sprite_screen_z(height)
# Add flat correction value if using z_flat
z -= 32 + height if @z_flat
# Add Z-Index adjustment
z += @z_add
# Make sure those Characters stay Visible, < 0 they Disappear!
return (z >= 0 ? z : 0)
end
end
#==============================================================================
# Interpreter
#==============================================================================
# I use this section to let the developer know if they are using the script
# incorrectly, usually by calling a command from the wrong Script Window
# since there are two of them.
#
# Edit Event -> Scripts
# Edit Event -> Set Move Route -> Scripts
# are DIFFERENT! Edit Event -> Scirpts doesnt specify the Event.
#==============================================================================
class Interpreter
# DEBUG Msg here indicates Mapper needs to call from the right window.
def reset_z(*args)
p "Please call \"reset_z\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
# DEBUG Msg here indicates Mapper needs to call from the right window.
def set_flat(*args)
p "Please call \"set_flat\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
# DEBUG Msg here indicates Mapper needs to call from the right window
def set_z(*args)
p "Please call \"set_z(#{args})\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
# DEBUG Msg here indicates Mapper needs to call from the right window
def clear_z(*args) #args prevents any args from being used
p "Please call \"clear_z\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
end
Off Topic, do you have anything in TONS for Fading Events in and out like a Fog can do? If you dont, would that be another worthwhile addition?