[RESOLVED] [XP] Need help refreshing and old Mini Map script

Started by SolarisSpell, March 05, 2021, 03:24:56 am

Previous topic - Next topic

SolarisSpell

March 05, 2021, 03:24:56 am Last Edit: March 11, 2021, 05:49:52 am by SolarisSpell
Hi

I'm using an old script made by Selwyn back in 2006 called "Passability Minimap"
Can I ask for help regarding a script already created a long time ago?

The scripts shows a minimap and some dots (pictures) to represent enemies, npc, etc...
My problem is that if I have an event that changes with a self switch (and changes from npc to enemy), the minimap doesn't reflect that change. If I open and close the menu it shows the enemy dot, in I leave the map and reenter it also shows the enemy dot.
It seems that when the whole scene is created, it works, but if I want to change from npc to enemy, I don't know how to 'refresh' the minimap.

Being from a creator that is no longer here I don't know if I can ask for help.

Should I post the script?

Thanks

KK20

March 05, 2021, 04:29:58 am #1 Last Edit: March 10, 2021, 10:26:15 pm by KK20
I was able to locate the script.

In the script, replace the entire Map_Event class with this:
#==============================================================================
# ? Map_Event
#------------------------------------------------------------------------------
# ?draw the events and hero position
#==============================================================================

class Map_Event < Map_Passability
  #--------------------------------------------------------------------------
  # ? initialize
  #--------------------------------------------------------------------------
  def initialize(corner = 4)
    super(corner)
    @dots = []
    @player = Sprite.new(self.viewport)
    @player.bitmap = RPG::Cache.picture("mm cursors")
    @player.src_rect = Rect.new(0, 0, 15, 15)
    @player.z = self.z + 3
    @events = {}
 
    for key in $game_map.events.keys
      event = $game_map.events[key]
      next if event.list == nil
      set_event_bitmap(event, key)
    end
  end
  #--------------------------------------------------------------------------
  # ? set_event_bitmap
  #--------------------------------------------------------------------------
  def set_event_bitmap(event, key = event.id)
    return if event.list.nil?
   
    for i in 0...event.list.size
      next if event.list[i].code != 108
     
      @events[key] ||= Sprite.new(self.viewport)
      @events[key].z = self.z + 2
   
      if    event.list[i].parameters[0].include?("event")
        @events[key].bitmap = RPG::Cache.picture("event")
      elsif event.list[i].parameters[0].include?("enemy")
        @events[key].bitmap = RPG::Cache.picture("enemy")
      elsif event.list[i].parameters[0].include?("teleport")
        @events[key].bitmap = RPG::Cache.picture("teleport")
      elsif event.list[i].parameters[0].include?("chest")
        @events[key].bitmap = RPG::Cache.picture("chest")
      elsif event.list[i].parameters[0].include?("npc")
        @events[key].bitmap = RPG::Cache.picture("npc")
      elsif event.list[i].parameters[0].include?("savepoint")
        @events[key].bitmap = RPG::Cache.picture("savepoint")
      end
     
      break
    end
  end
 
  #--------------------------------------------------------------------------
  # ? dispose
  #--------------------------------------------------------------------------
  def dispose
    @player.dispose
    for event in @events.values
      event.dispose
    end
    super
  end
  #--------------------------------------------------------------------------
  # ? update
  #--------------------------------------------------------------------------
  def update
    super
    @player.x = $game_player.real_x * 3 / 64 - 5
    @player.y = $game_player.real_y * 3 / 64 - 4
    @player.src_rect.x = ($game_player.direction / 2 - 1) * 15
    for key in @events.keys
      event = @events[key]
      mapevent = $game_map.events[key]
      event.x = mapevent.real_x * 3 / 64
      event.y = mapevent.real_y * 3 / 64
      if mapevent.needs_minimap_update
        set_event_bitmap(mapevent)
        mapevent.needs_minimap_update = false
      end
    end
  end
end

class Game_Event < Game_Character
  attr_accessor :needs_minimap_update
  alias update_minimap_after_refresh refresh
  def refresh
    update_minimap_after_refresh
    @needs_minimap_update = true
  end
end
I didn't test it, but I think the logic is correct. Basically just looks for when an event is refreshed, it turns on a flag to indicate that it might need its minimap graphic updated.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

SolarisSpell

Thank you for your answer

Sadly, it didn't work. It crashes (not that it doesn't respond).
The error says:
"undefined method 'needs_minimap_update' for #<Sprite:0x4110070>"

Thanks

SolarisSpell

Well, somehow I've made an hybrid thing and now it works.

When coding I feel like that meme of the "i have no idea what im doing dog"

I've taken your 'set_event_bitmap' method, added it like an additional thing, removed the 'return if event.list.nil?' because I don't know, and added that 'set_event_bitmap' in the update method. Now it works. It's magic


This is my Map_Event_Class
#==============================================================================
# ■ Map_Event
#------------------------------------------------------------------------------
#  draw the events and hero position
#==============================================================================

class Map_Event < Map_Passability
  #--------------------------------------------------------------------------
  # ● initialize
  #--------------------------------------------------------------------------
  def initialize(corner = 4)
    super(corner)
    @dots = []
    @player = Sprite.new(self.viewport)
    @player.bitmap = RPG::Cache.picture("mm cursors")
    @player.src_rect = Rect.new(0, 0, 15, 15)
    @player.z = self.z + 3
    @events = {}
   
    for key in $game_map.events.keys
      event = $game_map.events[key]
      next if event.list == nil
      for i in 0...event.list.size
        next if event.list[i].code != 108
        @events[key] = Sprite.new(self.viewport)
        @events[key].z = self.z + 2
        if    event.list[i].parameters[0].include?("event")
        @events[key].bitmap = RPG::Cache.picture("event")
      elsif event.list[i].parameters[0].include?("enemy")
        @events[key].bitmap = RPG::Cache.picture("enemy")
      elsif event.list[i].parameters[0].include?("teleport")
        @events[key].bitmap = RPG::Cache.picture("teleport")
      elsif event.list[i].parameters[0].include?("chest")
        @events[key].bitmap = RPG::Cache.picture("chest")
      elsif event.list[i].parameters[0].include?("npc")
        @events[key].bitmap = RPG::Cache.picture("npc")
      elsif event.list[i].parameters[0].include?("savepoint")
        @events[key].bitmap = RPG::Cache.picture("savepoint")
      end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● dispose
  #--------------------------------------------------------------------------
  def dispose
    @player.dispose
    for event in @events.values
      event.dispose
    end
    super
  end
  #--------------------------------------------------------------------------
  # ● update
  #--------------------------------------------------------------------------
  def update
    super
    @player.x = $game_player.real_x * 3 / 64 - 5
    @player.y = $game_player.real_y * 3 / 64 - 4
    @player.src_rect.x = ($game_player.direction / 2 - 1) * 15
    for key in @events.keys
      event = @events[key]
      mapevent = $game_map.events[key]
      event.x = mapevent.real_x * 3 / 64
      event.y = mapevent.real_y * 3 / 64
    end
    set_event_bitmap(event)
  end
 
  #--------------------------------------------------------------------------
  # ? set_event_bitmap
  #--------------------------------------------------------------------------
  def set_event_bitmap(event, key = event.id)
    #return if event.list.nil?
   
    for key in $game_map.events.keys
      event = $game_map.events[key]
      next if event.list == nil   
   
    for i in 0...event.list.size
      next if event.list[i].code != 108
     
      @events[key] ||= Sprite.new(self.viewport)
      @events[key].z = self.z + 2
   
if    event.list[i].parameters[0].include?("event")
        @events[key].bitmap = RPG::Cache.picture("event")
      elsif event.list[i].parameters[0].include?("enemy")
        @events[key].bitmap = RPG::Cache.picture("enemy")
      elsif event.list[i].parameters[0].include?("teleport")
        @events[key].bitmap = RPG::Cache.picture("teleport")
      elsif event.list[i].parameters[0].include?("chest")
        @events[key].bitmap = RPG::Cache.picture("chest")
      elsif event.list[i].parameters[0].include?("npc")
        @events[key].bitmap = RPG::Cache.picture("npc")
      elsif event.list[i].parameters[0].include?("savepoint")
        @events[key].bitmap = RPG::Cache.picture("savepoint")
      end
     
      break
    end
    end
  end
 
end

So thank you very much.
I've managed to make it respond thanks to your help.

KK20

I'm not convinced what you put truly works. It's also extremely inefficient as it loops twice per update. The reason I didn't test the script is because I don't know what the graphic specifications are. If you're willing to provide me yours then I can look into it more.

Alternatively, I read some things about how this script is poorly optimized on larger maps and is not dynamic (which is the reason why you made this topic). Blizzard's Minimap script found in Tons of Add-ons supposedly does a better job with that.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

SolarisSpell

Thanks

Yeah, it's not a surprise that my custom thing is not efficient.
The problem is that I have absolutely no knowledge of coding, so I just franken-code. I take things of something and paste it together with other things to see what happen, and step by step I arrive to some code that somewhat works in a way similar to what I was trying to get.

(The only thing I created as a whole, was also using other existing things and it lags a lot. Some day I will have to try and find a way to make it not laggy. Probably should find a way to not be updating everytime or something like that)

I don't know what you mean by 'graphic specifications'. I'd have no problem providing them to you, is just that I don't know what I have to give you.
I'll look the Blizzard's Minimap script you mentioned. I was using Selwyn's one just because it shows little dots for npc, enemies and the like and I liked it.

KK20

The script requires a number of graphic files to work, like an autotile, background, and all the event types to be displayed. The websites I found the script at had broken images and no demo, so I don't know what these things are supposed to look like. Which is why I'm asking for the graphics you use.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

SolarisSpell

March 09, 2021, 06:06:38 am #7 Last Edit: March 10, 2021, 06:39:54 am by SolarisSpell
I have created a demo, so it has both the script and the images needed

Selwyn's Passability Minimap - Demo

Edit: This is the original script, not the butchered thing I'm using right now

KK20

Hmmm tinyupload is not accessible for me, and IsItDown confirms it's not just me. Can you use something else?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

SolarisSpell

OK, I have added to file to Google Drive, so I think it won't be giving any problems

Selwyn's Passability Minimap

Thanks


KK20

Thanks, that worked fine.

I updated my earlier post containing the fix. I guess I typed too quick since I was using the wrong variable. It was supposed to be this:
      if mapevent.needs_minimap_update
        set_event_bitmap(mapevent)
        mapevent.needs_minimap_update = false
      end

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

SolarisSpell

Amazing! It works perfectly, thanks


I know is not my script, so maybe it's not my place to do so, but would be ok to post the script in the database subforum? Maybe someone appreciates it (but I don't know how much people still uses RMXP or are looking to add new scripts)

KK20

Yeah, we can allow other users to share scripts they didn't make as long as the original author condones it. Some people like to keep their scripts available only on one site, but not sure for what reasons.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!