Hello like in topic.
Maybe exist script for shownig pictures under event on the map or someone can help me solve a problem with my?
Problem is simple but i don't know what i do wrong.
Usage:
Add comment to event:
PICTURE.Z 150
EVENT.Z 200
If i add picture to the event and graphic for the event then picture is showing still on the event graphic.
class Game_Event < Game_Character
attr_accessor :picture_z, :event_z
alias original_refresh refresh
def refresh
begin
original_refresh
@picture_z = nil
@event_z = nil
if @list
@list.each do |command|
if command.code == 108 || command.code == 408
if command.parameters[0] =~ /PICTURE\.Z\s+(\d+)/
@picture_z = $1.to_i
elsif command.parameters[0] =~ /EVENT\.Z\s+(\d+)/
@event_z = $1.to_i
end
end
end
end
log_event_debug_info
rescue => e
log_error(e)
end
end
def log_event_debug_info
File.open("event_debug_log.txt", "a") do |file|
file.puts("Event ID: #{@id} - EVENT.Z: #{@event_z}, PICTURE.Z: #{@picture_z}")
end
end
def log_error(exception)
File.open("error_log.txt", "a") do |file|
file.puts("Error in Game_Event: #{exception.message}")
file.puts(exception.backtrace)
end
end
end
class Sprite_Character < RPG::Sprite
alias original_update update
def update
begin
original_update
if @character.is_a?(Game_Event)
self.z = @character.event_z || 100
log_character_debug_info
end
rescue => e
log_error(e)
end
end
def log_character_debug_info
File.open("character_debug_log.txt", "a") do |file|
file.puts("Character ID: #{@character.id} - Z: #{self.z}")
end
end
def log_error(exception)
File.open("error_log.txt", "a") do |file|
file.puts("Error in Sprite_Character: #{exception.message}")
file.puts(exception.backtrace)
end
end
end
class Sprite_Picture < Sprite
alias original_update update
def update
begin
original_update
update_z
log_picture_debug_info
rescue => e
log_error(e)
end
end
def update_z
max_event_z = $game_map.events.values.map { |event| event.event_z || 0 }.max
self.z = (max_event_z || 0) - 1
end
def log_picture_debug_info
File.open("picture_debug_log.txt", "a") do |file|
file.puts("Picture - Z set to: #{self.z}")
end
end
def log_error(exception)
File.open("error_log.txt", "a") do |file|
file.puts("Error in Sprite_Picture: #{exception.message}")
file.puts(exception.backtrace)
end
end
end
class Spriteset_Map
alias original_initialize initialize
def initialize
begin
original_initialize
update_picture_z
rescue => e
log_error(e)
end
end
alias original_update update
def update
begin
original_update
update_picture_z
rescue => e
log_error(e)
end
end
def update_picture_z
begin
max_event_z = $game_map.events.values.map { |event| event.event_z || 0 }.max
@picture_sprites.each do |sprite|
sprite.z = (max_event_z || 0) - 1
end
# Debug
File.open("spriteset_debug_log.txt", "a") do |file|
file.puts("Spriteset update:")
@picture_sprites.each_with_index do |sprite, index|
file.puts("Picture Index: #{index} - Z set to: #{sprite.z}")
end
end
rescue => e
log_error(e)
end
end
def log_error(exception)
File.open("error_log.txt", "a") do |file|
file.puts("Error in Spriteset_Map: #{exception.message}")
file.puts(exception.backtrace)
end
end
end