[XP] Sprite offset script?

Hello!
I'm looking a script that adjusts the position of a sprite. I'm currently adjusting it by defining a name for the event in Sprite_Character, for example
Ruby:
if event.name = "lower"
    self.y = @character.screen_y - 8
else
    self.y = @character.screen_y
end

if event.name = "right"
    self.x = @character.screen_x + 12
else
    self.x = @character.screen_x
end
It's not effective if I have to define a new name for each new offset. And it would be great if it could be setup via comment/command code 108 for faster config, i.e
Code:
\ox[12]
\oy[-8]

Thank you for considering my request.
So, I managed to solve this problem 😅 Here's what I did (in case someone need it)
Ruby:
# Sprite_Offset Script (1 Sep 2022)

class Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :off_x, :off_y
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias sprite_offset_initialize initialize
  def initialize
    sprite_offset_initialize
    @off_x = 0
    @off_y = 0
  end
  #--------------------------------------------------------------------------
  # * Get Screen X-Coordinates
  #--------------------------------------------------------------------------
  def screen_x
    # Get screen coordinates from real coordinates and map display position
    @off_x + (@real_x - $game_map.display_x + 3) / 4 + 16
  end
  #--------------------------------------------------------------------------
  # * Get Screen Y-Coordinates
  #--------------------------------------------------------------------------
  def screen_y
    # Get screen coordinates from real coordinates and map display position
    y = (@real_y - $game_map.display_y + 3) / 4 + 32
    return y + @off_y if !jumping?
    # Make y-coordinate smaller via jump count
    if @jump_count >= @jump_peak
      n = @jump_count - @jump_peak
    else
      n = @jump_peak - @jump_count
    end
    return y - (@jump_peak * @jump_peak - n * n) / 2
  end
end

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Event Page Setup
  #--------------------------------------------------------------------------
  def setup_page(new_page)
    @page = new_page
    if @page
      setup_page_settings
      check_comment_config
    else
      clear_page_settings
    end
    clear_starting
    check_event_trigger_auto
  end
  #--------------------------------------------------------------------------
  # * Comment Data
  #--------------------------------------------------------------------------
  def check_comment_config
    comment_config = []

    @list.each{ |line|
      next if line.code != 108
      if line.parameters[0].include?('\\')
        comment_config.push(line.parameters[0].split(" "))
      end
    }
    
    comment_config.each{ |data|
      case data[0]
        when '\\ox'
          @off_x = data[1].to_i
        when '\\oy'
          @off_y = data[1].to_i
      end
    }
  end 
end
Any suggestion to improve this is welcome. (Because I'm not good at programming at all 😅)
Btw, it won't work without some edit to the Game_Event. I did break it into smaller blocks of code as in VXA.
Spoiler: Game_Event (Edited)
Ruby:
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
#  This class deals with events. It handles functions including event page
#  switching via condition determinants, and running parallel process events.
#  It's used within the Game_Map class.
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :trigger                  # trigger
  attr_reader   :list                     # list of event commands
  attr_reader   :starting                 # starting flag
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     map_id : map ID
  #     event  : event (RPG::Event)
  #--------------------------------------------------------------------------
  def initialize(map_id, event)
    super()
    @map_id = map_id
    @event = event
    @id = @event.id
    @erased = false
    @starting = false
    @through = true
    # Move to starting position
    moveto(@event.x, @event.y)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Clear Starting Flag
  #--------------------------------------------------------------------------
  def clear_starting
    @starting = false
  end
  #--------------------------------------------------------------------------
  # * Determine if Over Trigger
  #    (whether or not same position is starting condition)
  #--------------------------------------------------------------------------
  def over_trigger?
    # If not through situation with character as graphic
    if @character_name != "" && !@through
      # Starting determinant is face
      return false
    end
    # If this position on the map is impassable
    unless $game_map.passable?(@x, @y, 0)
      # Starting determinant is face
      return false
    end
    # Starting determinant is same position
    return true
  end
  #--------------------------------------------------------------------------
  # * Start Event
  #--------------------------------------------------------------------------
  def start
    # If list of event commands is not empty
    if @list.size > 1
      @starting = true
    end
  end
  #--------------------------------------------------------------------------
  # * Temporarily Erase
  #--------------------------------------------------------------------------
  def erase
    @erased = true
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    new_page = @erased ? nil : find_proper_page
    setup_page(new_page) if !new_page || new_page != @page
  end
  #--------------------------------------------------------------------------
  # * Find Event Page Meeting Conditions
  #--------------------------------------------------------------------------
  def find_proper_page
    @event.pages.reverse.find {|page| conditions_met?(page) }
  end
  #--------------------------------------------------------------------------
  # * Determine if Event Page Conditions Are Met
  #--------------------------------------------------------------------------
  def conditions_met?(page)
    c = page.condition
    if c.switch1_valid
      return false unless $game_switches[c.switch1_id]
    end
    if c.switch2_valid
      return false unless $game_switches[c.switch2_id]
    end
    if c.variable_valid
      return false if $game_variables[c.variable_id] < c.variable_value
    end
    if c.self_switch_valid
      key = [@map_id, @event.id, c.self_switch_ch]
      return false if $game_self_switches[key] != true
    end
    return true
  end
  #--------------------------------------------------------------------------
  # * Event Page Setup
  #--------------------------------------------------------------------------
  def setup_page(new_page)
    @page = new_page
    if @page
      setup_page_settings
    else
      clear_page_settings
    end
    clear_starting
    check_event_trigger_auto
  end
  #--------------------------------------------------------------------------
  # * Clear Event Page Settings
  #--------------------------------------------------------------------------
  def clear_page_settings
    @tile_id = 0
    @character_name = ""
    @character_hue = 0
    @move_type = 0
    @through = true
    @trigger = nil
    @list = nil
    @interpreter = nil
  end
  #--------------------------------------------------------------------------
  # * Set Up Event Page Settings
  #--------------------------------------------------------------------------
  def setup_page_settings
    @tile_id        = @page.graphic.tile_id
    @character_name = @page.graphic.character_name
    @character_hue  = @page.graphic.character_hue
    if @original_direction != @page.graphic.direction
      @direction          = @page.graphic.direction
      @original_direction = @direction
      @prelock_direction  = 0
    end
    if @original_pattern != @page.graphic.pattern
      @pattern            = @page.graphic.pattern
      @original_pattern   = @pattern
    end
    @opacity = @page.graphic.opacity
    @blend_type         = @page.graphic.blend_type
    @move_type          = @page.move_type
    @move_speed         = @page.move_speed
    @move_frequency     = @page.move_frequency
    @move_route         = @page.move_route
    @move_route_index   = 0
    @move_route_forcing = false
    @walk_anime         = @page.walk_anime
    @step_anime         = @page.step_anime
    @direction_fix      = @page.direction_fix
    @through            = @page.through
    @always_on_top      = @page.always_on_top
    @trigger            = @page.trigger
    @list               = @page.list
    @interpreter = @trigger == 4 ? Interpreter.new : nil
  end
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    # If event is running
    return if $game_system.map_interpreter.running?
    # If trigger is [touch from event] and consistent with player coordinates
    if @trigger == 2 && x == $game_player.x && y == $game_player.y
      # If starting determinant other than jumping is front event
      start if !jumping? && !over_trigger?
    end
  end
  #--------------------------------------------------------------------------
  # * Automatic Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_auto
    # If trigger is [touch from event] and consistent with player coordinates
    if @trigger == 2 && @x == $game_player.x && @y == $game_player.y
      # If starting determinant other than jumping is same position event
      start if !jumping? && over_trigger?
    end
    # If trigger is [auto run]
    start if @trigger == 3
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    check_event_trigger_auto
    if @interpreter != nil
      @interpreter.setup(@list, @event.id) unless @interpreter.running?
      @interpreter.update
    end
  end
end
So, I managed to solve this problem 😅 Here's what I did (in case someone need it)
Ruby:
# Sprite_Offset Script (1 Sep 2022)

class Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :off_x, :off_y
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias sprite_offset_initialize initialize
  def initialize
    sprite_offset_initialize
    @off_x = 0
    @off_y = 0
  end
  #--------------------------------------------------------------------------
  # * Get Screen X-Coordinates
  #--------------------------------------------------------------------------
  def screen_x
    # Get screen coordinates from real coordinates and map display position
    @off_x + (@real_x - $game_map.display_x + 3) / 4 + 16
  end
  #--------------------------------------------------------------------------
  # * Get Screen Y-Coordinates
  #--------------------------------------------------------------------------
  def screen_y
    # Get screen coordinates from real coordinates and map display position
    y = (@real_y - $game_map.display_y + 3) / 4 + 32
    return y + @off_y if !jumping?
    # Make y-coordinate smaller via jump count
    if @jump_count >= @jump_peak
      n = @jump_count - @jump_peak
    else
      n = @jump_peak - @jump_count
    end
    return y - (@jump_peak * @jump_peak - n * n) / 2
  end
end

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Event Page Setup
  #--------------------------------------------------------------------------
  def setup_page(new_page)
    @page = new_page
    if @page
      setup_page_settings
      check_comment_config
    else
      clear_page_settings
    end
    clear_starting
    check_event_trigger_auto
  end
  #--------------------------------------------------------------------------
  # * Comment Data
  #--------------------------------------------------------------------------
  def check_comment_config
    comment_config = []

    @list.each{ |line|
      next if line.code != 108
      if line.parameters[0].include?('\\')
        comment_config.push(line.parameters[0].split(" "))
      end
    }
   
    comment_config.each{ |data|
      case data[0]
        when '\\ox'
          @off_x = data[1].to_i
        when '\\oy'
          @off_y = data[1].to_i
      end
    }
  end
end
Any suggestion to improve this is welcome. (Because I'm not good at programming at all 😅)
Btw, it won't work without some edit to the Game_Event. I did break it into smaller blocks of code as in VXA.
Spoiler: Game_Event (Edited)
Ruby:
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
#  This class deals with events. It handles functions including event page
#  switching via condition determinants, and running parallel process events.
#  It's used within the Game_Map class.
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :trigger                  # trigger
  attr_reader   :list                     # list of event commands
  attr_reader   :starting                 # starting flag
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     map_id : map ID
  #     event  : event (RPG::Event)
  #--------------------------------------------------------------------------
  def initialize(map_id, event)
    super()
    @map_id = map_id
    @event = event
    @id = @event.id
    @erased = false
    @starting = false
    @through = true
    # Move to starting position
    moveto(@event.x, @event.y)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Clear Starting Flag
  #--------------------------------------------------------------------------
  def clear_starting
    @starting = false
  end
  #--------------------------------------------------------------------------
  # * Determine if Over Trigger
  #    (whether or not same position is starting condition)
  #--------------------------------------------------------------------------
  def over_trigger?
    # If not through situation with character as graphic
    if @character_name != "" && !@through
      # Starting determinant is face
      return false
    end
    # If this position on the map is impassable
    unless $game_map.passable?(@x, @y, 0)
      # Starting determinant is face
      return false
    end
    # Starting determinant is same position
    return true
  end
  #--------------------------------------------------------------------------
  # * Start Event
  #--------------------------------------------------------------------------
  def start
    # If list of event commands is not empty
    if @list.size > 1
      @starting = true
    end
  end
  #--------------------------------------------------------------------------
  # * Temporarily Erase
  #--------------------------------------------------------------------------
  def erase
    @erased = true
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    new_page = @erased ? nil : find_proper_page
    setup_page(new_page) if !new_page || new_page != @page
  end
  #--------------------------------------------------------------------------
  # * Find Event Page Meeting Conditions
  #--------------------------------------------------------------------------
  def find_proper_page
    @event.pages.reverse.find {|page| conditions_met?(page) }
  end
  #--------------------------------------------------------------------------
  # * Determine if Event Page Conditions Are Met
  #--------------------------------------------------------------------------
  def conditions_met?(page)
    c = page.condition
    if c.switch1_valid
      return false unless $game_switches[c.switch1_id]
    end
    if c.switch2_valid
      return false unless $game_switches[c.switch2_id]
    end
    if c.variable_valid
      return false if $game_variables[c.variable_id] < c.variable_value
    end
    if c.self_switch_valid
      key = [@map_id, @event.id, c.self_switch_ch]
      return false if $game_self_switches[key] != true
    end
    return true
  end
  #--------------------------------------------------------------------------
  # * Event Page Setup
  #--------------------------------------------------------------------------
  def setup_page(new_page)
    @page = new_page
    if @page
      setup_page_settings
    else
      clear_page_settings
    end
    clear_starting
    check_event_trigger_auto
  end
  #--------------------------------------------------------------------------
  # * Clear Event Page Settings
  #--------------------------------------------------------------------------
  def clear_page_settings
    @tile_id = 0
    @character_name = ""
    @character_hue = 0
    @move_type = 0
    @through = true
    @trigger = nil
    @list = nil
    @interpreter = nil
  end
  #--------------------------------------------------------------------------
  # * Set Up Event Page Settings
  #--------------------------------------------------------------------------
  def setup_page_settings
    @tile_id        = @page.graphic.tile_id
    @character_name = @page.graphic.character_name
    @character_hue  = @page.graphic.character_hue
    if @original_direction != @page.graphic.direction
      @direction          = @page.graphic.direction
      @original_direction = @direction
      @prelock_direction  = 0
    end
    if @original_pattern != @page.graphic.pattern
      @pattern            = @page.graphic.pattern
      @original_pattern   = @pattern
    end
    @opacity = @page.graphic.opacity
    @blend_type         = @page.graphic.blend_type
    @move_type          = @page.move_type
    @move_speed         = @page.move_speed
    @move_frequency     = @page.move_frequency
    @move_route         = @page.move_route
    @move_route_index   = 0
    @move_route_forcing = false
    @walk_anime         = @page.walk_anime
    @step_anime         = @page.step_anime
    @direction_fix      = @page.direction_fix
    @through            = @page.through
    @always_on_top      = @page.always_on_top
    @trigger            = @page.trigger
    @list               = @page.list
    @interpreter = @trigger == 4 ? Interpreter.new : nil
  end
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    # If event is running
    return if $game_system.map_interpreter.running?
    # If trigger is [touch from event] and consistent with player coordinates
    if @trigger == 2 && x == $game_player.x && y == $game_player.y
      # If starting determinant other than jumping is front event
      start if !jumping? && !over_trigger?
    end
  end
  #--------------------------------------------------------------------------
  # * Automatic Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_auto
    # If trigger is [touch from event] and consistent with player coordinates
    if @trigger == 2 && @x == $game_player.x && @y == $game_player.y
      # If starting determinant other than jumping is same position event
      start if !jumping? && over_trigger?
    end
    # If trigger is [auto run]
    start if @trigger == 3
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    check_event_trigger_auto
    if @interpreter != nil
      @interpreter.setup(@list, @event.id) unless @interpreter.running?
      @interpreter.update
    end
  end
end
If it isnt too much of a bother, would you mind explaining how to set this up? i have the script loaded into the game, how do i make it so an event on screen is offset by + 16 pixels?
If it isnt too much of a bother, would you mind explaining how to set this up? i have the script loaded into the game, how do i make it so an event on screen is offset by + 16 pixels?
Oh, I forgot that. It is set by putting a \comment value Comment on the event page.
Code:
- \ox value : offset right
- \ox -value: offset left
- \oy value : offset down
- \oy -value: offset up
Example:
Code:
\ox 16
\oy -16

I hope this explanation is clear enough 😅

Original thread: https://forums.rpgmakerweb.com/threads/xp-sprite-offset-script.150971/