Here is the final script.
# ----------------------------------------------------------------------------
# FLAT SPRITES 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.
#
# --- EVENT NAME RELATED---
#
# EV001\z_flat
# EV001\z_flat[32]
# EV001\z_add[32]
#
# 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, add to its nane "\z_flat".
#
# 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).
#
# --- 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.
# ----------------------------------------------------------------------------
DISPLAY_DEVELOPER_ERRORS = true
#==============================================================================
# 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)
# If Error Reporting is On and not a Release Game
if $DEBUG && DISPLAY_DEVELOPER_ERRORS
if !new_z.is_a?(Numeric)
p "Warning! \"#{new_z}\" is not an Number!\n",
"set_flat(int) expects \"int\" to be a Number!\n\n",
"I.E. set_z(32) or set_z(-65)"
return
end
end
# Expects new_z as an Argument. It adds whatever that value is to new number
if new_z != 0
# 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 and Edit Event -> Set Move Route -> Scripts are DIFFERENT!
#==============================================================================
class Interpreter
# DEBUG Msg here indicates Mapper needs to call from the right window, however...
def reset_z(*args)
if $DEBUG && DISPLAY_DEVELOPER_ERRORS
p "Please call \"reset_z\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
end
# DEBUG Msg here indicates Mapper needs to call from the right window, however...
def set_flat(*args)
if $DEBUG && DISPLAY_DEVELOPER_ERRORS
p "Please call \"set_flat\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
end
# DEBUG Msg here indicates Mapper needs to call from the right window, however...
def set_z(*args)
if $DEBUG and DISPLAY_DEVELOPER_ERRORS
p "Please call \"set_z(#{args})\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
end
# DEBUG Msg here indicates Mapper needs to call from the right window, however...
def clear_z(*args) #args prevents any args from being used
if $DEBUG and DISPLAY_DEVELOPER_ERRORS
p "Please call \"clear_z\" from\n",
"\"Edit Event\" -> \"Set Move Route\" -> Scripts Window\n",
"instead of \n\"Edit Event\" -> Scripts Window"
end
end
end
There are a few things I want you to know before you go ahead and check everything:
1. I have changed only one feature. In the instructions it was mentioned that using z_add would force a sprite to be rendered flat which makes no sense as z_add only is supposed to alter the Z on a specific event while z_flat was supposed to alter the Z automatically in such a way that it appears flat on the floor.
2. Technically it is enough to return a Z of 1 if you want flat sprites. But this is your implementation so I have left the code like in the original.
3. Previously z_flat and z_add were working together in a kind of weird and confusing way. Honestly, I was not exactly able to tell when one overrides the other. I have changed that. They now work independently and they can work together.
4. If you now use \z_flat[Int], it works just like \z_flat with \z_add[Int] together.
5. Your method naming (reset_z, clear_z, set_z) is ambiguous. IMO you should have just added set_z_flat(Bool), set_z_add(Int) and reset_flat_sprites. This is much more congruent with your script as it is exactly clear what parameters are being modified. set_z might be confused with changing some other Z values. Also, set_z is functionally incoherent as the execution depends on the parameters, especially since both z_flat and z_add are being modified in a way that they are mutually exclusive. If you set it to 0, a "completely different" execution path is executed. That's why I suggested set_z_flat and set_z_add since it's exactly clear what they do to someone who doesn't understand the script.
6. You have a note in the instructions that say that event names or events don't copy-paste properly. I have never experienced such a problem in all my years while working in RMXP. Are you 100% that you didn't accidentally mess up something and you actually just didn't copy-paste it right?
7. I have left your developer errors even though I feel they are kind of overkill for such a simple script. The ones at the bottom in Interpreter I can understand, but I don't really see the point of the one in set_z.
8. I would actually remove the optional parameter DISPLAY_DEVELOPER_ERRORS completely and the if-condition with $DEBUG. If somebody's game isn't working right, it would be good that certain error message stay in the release build as well and are displayed to the user if things go haywire. There's nothing worse than somebody reporting a bud without any kind of error message.
9. Other than that I have retained all the functionality in your script. Even though the name is actually inaccurate as this script does not only make sprites flat. "Event Z-Index Controller" or something like that would be a more accurate name for the script. It may not sound as fancy, but it tells you what it does.
Alright, this is all. Once we have solved these issues, I can finalize the script and add it to Tons.
EDIT: @F0: Your script alters the Z in absolute values. Making a sprite flat would require you to simply set its Z to 1, but your script doesn't allow to alter the current Z, e.g. add 32 to an event's Z. Of course, your script could be altered to support that as well. But then it would look almost like Heretic's script since you need one Z value for relative adding and one that would force absolute values. And you still wouldn't be able to combine these two functionalities. In Heretic's script you can do that (or at least in the version I have edited).