RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

XP Script - Flat Sprites Render as Flat!

Started by Heretic86, February 28, 2012, 10:23:58 PM

0 Members and 2 Guests are viewing this topic.

Heretic86

Anyone ever try to use this Graphic for an Event?



Your Character has a problem of "Walking Behind or Under" that Graphic. Like this:



That isnt what we want. I wont bother to explain the problem in technical terms, but I will offer a FIX.



THAT is what we want! Did you notice the Characters are now on TOP of the Graphic?

The problem is that the engine "Thinks" that the Graphic is a Character that is standing up and not laying on the ground. This script tells the Engine to just render it as "Flat" instead of as "Standing Up".

[spoiler]# Heretic Fix Flat Sprites
#
# People stand up straight off the ground, but
# Rugs lay flat on the ground.
#
# The intention of this script is to allow a quick fix for
# Sprites that are supposed to look like they should lay flat
# Namely, the "Support 7" Graphics.  They look like they should
# lay flat, and not stack in front of the characters EVER.
#
# The "Support 7" Graphic, make an event, give it a Graphic
# and find "Support 7", it is one up from the bottom of the list.
#
# ALWAYS_ON_TOP MUST BE OFF!!!
#
# To define an event to be FLAT, change the NAME of the EVENT
# and add \z_flat, so a Rug would be "Rug\z_flat"
#
# If you have trouble with your Event stacking correctly
# you can try using the optional parameter field to specify a Z-Index to add
# I.E. - "Sign\z_flat[32]", 32 per tile you want higher.
#
# This is useful if you have TWO EVENTS you want to stack, like a TREE
# I sometimes use EVENTS to hold GRAPHICS when I need to put more
# than Three Layers of Graphics
#
# Another option is "Name\z_add[32]" which REQUIRES a Number
#
# This is intended also for fixing things like Graphic Events.  To make it
# stack on top of Characters, give it a nice high number, but less than 999
# as 999 is the Z-Index for "Always On Top", thus allowing even more
# Graphic Events to stack on top of that.  500 is a good number to work with.
#
# This whole thing gives you MUCH MORE CONTROL over the way that events stack
# when they occupy the same space.  Normally, the engine just cycles through
# Events in order, so if you have 3 Graphic Events stacked on top of one another
# the Event with the LOWEST EVENT ID will be on Bottom of that Stack.
#
# Needless to say, if you are fighting with the Stacking Order and trying to
# figure out Event ID's, then change tons of other stuff, this script will
# save you time from heavy modifications.
#
#
# Shouldnt affect performance because it is only called when the map is loaded
# which would be the only place you might take a performance hit.
#
# If you use my revision of Zeriab's Caterpillar, place this BELOW that script
# and above MAIN


class Game_Event < Game_Character
 
  unless self.method_defined?('flat_sprite_initialize')
    alias flat_sprite_initialize initialize
  end
 
  def initialize(map_id, event, *args)
    flat_sprite_check(event)
    flat_sprite_initialize(map_id, event, *args)
  end

  unless self.method_defined?('flat_sprite_screen_z')
    alias flat_sprite_screen_z screen_z
  end
 
  def screen_z (height = 0)
    if not @z_flat.nil? and !@always_on_top
      return z = (@real_y - $game_map.display_y + 3) / 4 + @z_flat
    end
   
    if not @z_add.nil? and !@always_on_top
      return z = (@real_y - $game_map.display_y + 3) / 4 + 32 + @z_add
    end

    #Run Original screen_z
    flat_sprite_screen_z(height)
   
  end
 
  def flat_sprite_check(event)
    # Options
    #
    # "Name\z_flat"
    # "Name\z_flat[32]" for characters manual adjustments, for whatever reason
    # "Name\z_add[32]" for characters higher than 32 pixels high

    event.name.gsub(/\\z_flat\[([-]?[0-9]+)\]|\\z_flat/i) {@z_flat = $1.to_i }
    return if @z_flat   
   
    event.name.gsub(/\\z_add\[([-]?[0-9]+)\]/i) {@z_add = $1.to_i }
    return if @z_add
  end
end
[/spoiler]

edit: cleaned up the Regular Expressions a little bit.

To do this, change the Name of the event to include \z_flat, so "Rug\z_flat" will force the engine to render characters on top of it correctly.

There are a couple other options in there in case you are having trouble with Event Stacking.  \z_add renders sprites with a higher z_index based on the graphics height.  If it is taller than 32 pixels, it adds 31 to the z_index, plus, whatever you specify.  The optional argument for \z_flat[int] does NOT consider height, and sets the Z_index to include your x.  Thus, you want the z_index to be 32 higher (32 per pixel), put in \z_flat[32], or \z_flat[1] if you want one event to stack in front of another without using @always_on_top.
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!