Character Sprite Correction

This script allows you to manipulate the sprite of any event (using characterset), by setting its horizontal/vertical position.
When is it usefull?
1 - When some of the objects in the map are characters, and you don't want them to look like they're placed on a gridlines.
2 - When you're using characters that require some space in the bottom (i.e. for steps animation). In that situation the graphic is ussually moved up, and it may cause some weird situations when calculatin passability or coordinates.
3 - When you want to place graphics from several events in one place, without moving them. This is helpful in making lanterns, torches, etc.
Screenshot:
http://www.eimg.org/images/745026corr.jpg[/IMG]

Script:
#==============================================================================
# ** Game_Character
#==============================================================================

class Game_Character

  attr_accessor :correction_x
  attr_accessor :correction_y
  #--------------------------------------------------------------------------
  alias normal_initialize initialize
 
  def initialize
    @correction_x = 0
    @correction_y = 0
    normal_initialize
  end

end
#==============================================================================
# ** Sprite_Character
#==============================================================================

class Sprite_Character < RPG::Sprite

  def update
    super
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue)
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @cw = bitmap.width / 4
        @ch = bitmap.height / 4
        self.ox = @cw / 2 - @character.correction_x
        self.oy = @ch - @character.correction_y
      end
    end
    self.visible = (not @character.transparent)
    if @tile_id == 0
      sx = @character.pattern * @cw
      sy = (@character.direction - 2) / 2 * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end
Expand to see the code.


Usage:
Paste the script above "Main". Set the first page of an event to parallel or autostart. Put a "Call Script" command with:
get_character(0).correction_x = 0
get_character(0).correction_y = 0
Expand to see the code.

Turn on any local switch, and make another page with the sam graphic.
Adjust the numbers (but not the ones in the brackets) to move the sprite left/right and up/down.
For example: the characters on the right side of the screenshot have a "Call script" command like this:
x = -8 + rand(16)
y = -8 + rand(16)
get_character(0).correction_x = x
get_character(0).correction_y = y
Expand to see the code.

This way the correction is different for each character, and you can still copy/paste ;)

Now, I know a lot of people are using scripts that already alter Game_Character and Sprite_Character, and I can't alias the Sprite_Character's def update to work properly so here's what you need to do if you want to add this method to, for example, pixelmovement:
Find the Sprite_Character class. In its 'def update' find:
self.ox = @cw / 2
self.oy = @ch
Expand to see the code.

and replace it with:
self.ox = @cw / 2 - @character.correction_x
self.oy = @ch - @character.correction_y
Expand to see the code.

The Game_Character class is aliased so there's no need to do anything with it.

Enjoy the script :)
Ohh that is so cool! I love the idea!
So this is basically proving to show that we can do the step animation in half squares.. essentially making the grid from 4x4 on a box, to a 8x8 box, in the same space as a 4x4. Making more of a smooth movement. Its a great idea, but some people will have to base their passability scripts around this formula.
Please, Show the Past (Without Script) and the Future (With Script) for me see the diference =D
He already has, the girl in the top right is normal, then check out the other girl who is halfway down and notice Arshes is halfway above the bottom grid line.
This is great for breaking the monotony of gridlines. Good job, man.
Sorry to bump like this, but recently I saw a few projects, where there were quite large groups of characters (most likely armies), and I thought that it's a great place to use my script. I'm adding a screenshot of this situation:
http://www.eimg.org/images/745026corr.jpg[/img]
The chars on the right side have a "Call script" command:
x = -8 + rand(16)
y = -8 + rand(16)
get_character(0).correction_x = x
get_character(0).correction_y = y
Expand to see the code.
This is amazing!

So, did that lag?
No. Not if you use a "Self switch", and ma ke a new blank page :)
Cool, thanks! Nice script! Im using this! :)
does this script only affects events? or can it be used on the lead player also? (arshes, in your screenshot)
Yes, it can be used to affect the player. From any event, call a script:
get_character(-1).correction_x = blabla
Expand to see the code.

"-1" in the bracket stands for the player, "0" stands for "this event", and numbers > 0 stand for the IDs of the events on the map.
nice, thanks for this scripts
Very nice, I had already implemented vertical correction in my own script before I knew this one existed :P I already intended to add horizontal as well, so congrats for beating me to the punch.

As an aside, I remember another script topic which offered the same functionality - it might have been yours or it might not have been (or you might just have edited this one), either way it is indeed useful :)
great :D i was searching for it :D
Just a question XD it's possible to change the position of the player? or of all the character in a map whitout set it in all the event in the map?

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=9708