Change Tileset With Blizz-Abs Bug

Started by MEANDONLYME, April 06, 2017, 07:51:01 pm

Previous topic - Next topic

MEANDONLYME

April 06, 2017, 07:51:01 pm Last Edit: April 06, 2017, 07:52:49 pm by MEANDONLYME
So I was trying to make a swimming system by changing the tileset, and I found those two scripts:
Change Map Tileset by Ryethe
Tileset Swap by Ccoa
(The scripts are posted on different forums, so i'm not sure if i can link them. Just google them)
Now I also have Blizz-Abs on my project, and when I choose one of those scripts (In this example, Ccoa's script) and post it in my project, it makes an error message pop regarding the Blizz scripts:


First I thought this was something to do with the Intelligent Passability system on Blizz, but when I disable it I still get the same result.
The only way to fix this bug is to post the script above blizz, but when I change the tileset everything from bush-tag to terrain-tag changes, but the passability stays the same.
Anyone in a mood to help?
You can download Ccoa's script (demo) here:
https://app.box.com/s/yve9u15paysh788b8xk4

KK20

TIL RMXP only goes up to 8192 before wrapping back around to 0

You can't put the script below BABS because it doesn't alias Game_Map#setup. BABS calls this method too to initialize a passability variable--@virtual_passability (it also cleans up some things like refreshing map battlers and clearing a cache). Because you're not initializing @virtual_passability, you crash as soon as something tries to move as BABS relies on this for movement due to its built-in pixel-based movement.

Since this variable is also what is handling all the map collisions, you need to reinitialize it whenever you update the tileset graphic. Putting these two lines at the end of Game_Map#change_tileset should resolve the issue.

@map.tileset_id = tileset_id
@virtual_passability = $BlizzABS.util.setup_passability(@map)

Do note that you can't enable INTELLIGENT_PASSABILITY. Since this caches map passability to external files for faster loading times, it defeats the purpose if you're going to be dynamically changing the map passability in-game.

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!

MEANDONLYME

April 06, 2017, 10:51:26 pm #2 Last Edit: April 06, 2017, 10:58:10 pm by MEANDONLYME
Quote from: KK20 on April 06, 2017, 08:50:25 pm
TIL RMXP only goes up to 8192 before wrapping back around to 0

You can't put the script below BABS because it doesn't alias Game_Map#setup. BABS calls this method too to initialize a passability variable--@virtual_passability (it also cleans up some things like refreshing map battlers and clearing a cache). Because you're not initializing @virtual_passability, you crash as soon as something tries to move as BABS relies on this for movement due to its built-in pixel-based movement.

Since this variable is also what is handling all the map collisions, you need to reinitialize it whenever you update the tileset graphic. Putting these two lines at the end of Game_Map#change_tileset should resolve the issue.

@map.tileset_id = tileset_id
@virtual_passability = $BlizzABS.util.setup_passability(@map)

Do note that you can't enable INTELLIGENT_PASSABILITY. Since this caches map passability to external files for faster loading times, it defeats the purpose if you're going to be dynamically changing the map passability in-game.

Thanks for the fast response. It works. :naughty:
For anyone interested, the modified code solved the passability issue after I put the script above Blizz-Abs.
btw, do you have any idea why this swimming script also isn't compatible with Blizz?
I changed the Game_Player inheritance from Game_Character to Map_Actor (you can see in the script), but it still gives me an error.

KK20

April 07, 2017, 02:52:00 am #3 Last Edit: April 07, 2017, 03:59:45 am by KK20
Ugh, this was one of his really early scripts. I see he posted what looks to be a more advanced version in the database
http://forum.chaos-project.com/index.php/topic,12111.0.html

But even that has issues with BABS too, so still need to look into it. Again, it probably has to do with the custom passability BABS incorporates.

EDIT:
Yeah, that was it. Since the advanced one has sprite graphic changes, it caused some issues with BABS (since it can do that too). Placing this script under BABS and running it in the demo looks like it worked.
Spoiler: ShowHide

#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
#
#                     B E G I N  C O N F I G U R A T I O N
#
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
module Swim_Config
=begin
  #-=-=-=-=-=-=-=-=-=-=-#
  # * script calls      #
  #-=-=-=-=-=-=-=-=-=-=-#
  #changes the value of oxegen pictures if PICTURE_MODE is true
  $game_system.oxegen_pictures = VALUE
 
  #changes the max oxegen when bar mode is active
  $game_system.oxegen_max = VALUE
  #-=-=-=-=-=-=-=-=-=-=-#
  # * end script calls  #
  #-=-=-=-=-=-=-=-=-=-=-#
=end
  #Extension of the filename to change the swimming graphic
  SWIM_EXTENSION = '_swim'
  #Terrain tag of water to swim on
  WATER_TERRAIN = 2
  #oxegen timer when in water (true/false)
  OXEGEN_TIMER = false
  #picture mode if true, bar mode if false
  PICTURE_MODE = false
  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  # * if oxegen timer is true                                               #
  #-------------------------------------------------------------------------#
  # * if the picture mode is true                                           #
  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  #Picture name of the oxegen picture to show
  PICTURE_NAME = 'bubble'
  #initial amount of oxegen pictures
  PICTURES = 5
  #how many frames does it take for 1 oxegen picture to disapear?
  PICTURE_FRAMES = 100
  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  # * if the picture mode is not true (bar mode)                            #
  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  #how many initial oxegen blocks(pixles) are there?
  OXEGEN = 100
  #the frame rate each oxegen block(pixle) decreases
  OXEGEN_COUNT = 10
end
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
#
#                     E N D   C O N F I G U R A T I O N
#
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# * class Game_System                                                     
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_System
  attr_accessor :oxegen_picture_count
  attr_accessor :oxegen_pictures
  attr_accessor :oxegen_max
  attr_accessor :oxegen
  attr_accessor :oxegen_count
  alias init_swim initialize
  def initialize
    init_swim
    @oxegen_picture_count = 0
    @oxegen_pictures = Swim_Config::PICTURES
    @oxegen_max = Swim_Config::OXEGEN
    @oxegen = @oxegen_max
    @oxegen_count = Swim_Config::OXEGEN_COUNT
  end
end
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# * class Game_Map                                                 
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_Map
    attr_accessor :passages, :map, :virtual_passability
end
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# * class Game_Character                                                   
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_Character
  attr_reader :swimming
end
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# * class Window_Oxegen                                                   
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Window_Oxegen < Window_Base
  def initialize
    if Swim_Config::PICTURE_MODE == true
      @image = RPG::Cache.picture(Swim_Config::PICTURE_NAME)
      @oxegen_picture_amount = $game_system.oxegen_pictures
      super(0, 0, ((@image.width + 5) * $game_system.oxegen_pictures) + 32, @image.height + 32)
    else
      super(0, 0, $game_system.oxegen_max + 34, 7 + 32)
    end
    self.contents = Bitmap.new(width - 32, height - 32)
    self.active = false
    self.opacity = 0
    self.visible = true
    refresh
  end
  def refresh
    self.contents.clear
    if Swim_Config::PICTURE_MODE == true
      if $game_player.swimming == true
        if @oxegen_picture_amount > -1
          if $game_system.oxegen_picture_count > 0
            $game_system.oxegen_picture_count -= 1
          else
            $game_system.oxegen_picture_count = Swim_Config::PICTURE_FRAMES
            @oxegen_picture_amount -= 1
          end
          for i in 0 ... @oxegen_picture_amount
            rect = Rect.new(0, 0, @image.width, @image.height)
            self.contents.blt(0 + (@image.width + 5) * i, 0, @image, rect, 255)
          end
        else
          $game_temp.gameover = true
        end
      else
        @oxegen_picture_amount = $game_system.oxegen_pictures
      end
    else
      if $game_player.swimming == true
        rect = Rect.new(0, 0, $game_system.oxegen_max + 2, 7)
        bitmap = Bitmap.new(rect.width, rect.height)
        bitmap.fill_rect(rect.x, rect.y, rect.width, rect.height, Color.new(0, 0, 0, 255))
        self.contents.blt(0, 0, bitmap, rect)
        if $game_system.oxegen_count > 0 && $game_system.oxegen > 0
          $game_system.oxegen_count -= 1
        else
          $game_system.oxegen_count = Swim_Config::OXEGEN_COUNT
          $game_system.oxegen -= 1
        end
        if $game_system.oxegen > 0
          rect = Rect.new(0, 0, $game_system.oxegen, 5)
          bitmap = Bitmap.new(rect.width, rect.height)
          bitmap.fill_rect(rect.x, rect.y, rect.width, rect.height, Color.new(0, 0, 255, 255))
          self.contents.blt(1, 1, bitmap, rect)
        else
          $game_temp.gameover = true
        end   
      end
    end
  end
end
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# * class Scene_Map                                                 
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Scene_Map
  alias main_swim main
  def main
    @oxegen_window = Window_Oxegen.new if Swim_Config::OXEGEN_TIMER == true
    main_swim
    @oxegen_window.dispose if Swim_Config::OXEGEN_TIMER == true
  end
  alias update_swim update
  def update
    if Swim_Config::OXEGEN_TIMER == true
      @oxegen_window.refresh
      if $game_player.swimming == true
        @oxegen_window.visible = true
      else
        @oxegen_window.visible = false
      end
    end
    update_swim
  end
end
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
# * class Game_Player                                                   
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
class Game_Player < Map_Actor
  attr_accessor :character_name
 
  EXTENSION = "_swim"
  TERRAIN = 2
 
  def change_water_passable(passage=0)
    @water = []
    (0...$game_map.width).each {|x|
      (0...$game_map.height).each {|y|
        [2, 1, 0].each {|i|
           id = $game_map.data[x, y, i]
           @water << id if $game_map.terrain_tags[id] == Swim_Config::WATER_TERRAIN
    }}}
    # This code will get all the possible tile id with
    # water terrain tags
    @water.each {|i|  $game_map.passages[i] = passage  }
    $game_map.virtual_passability = $BlizzABS.util.setup_passability($game_map.map)
    # then this code will change all the water passages
  end
 
  alias update_swim update
  def update
    if $game_map.terrain_tag(@x, @y) != Swim_Config::WATER_TERRAIN
      player = $game_party.actors[0]
      if @swimming == true
        $game_system.oxegen = $game_system.oxegen_max if
          Swim_Config::OXEGEN_TIMER == true && Swim_Config::PICTURE_MODE == false
        change_water_passable(15)
        orig_name = player.character_name.split(Swim_Config::SWIM_EXTENSION)[0]
        @character_name = @character_name_org = orig_name
        player.set_graphic(orig_name, player.character_hue, player.battler_name, player.battler_hue)
        @step_anime = false
        @swimming = false
      end
      if Input.trigger?(Input::C)
        case @direction
        when 2
          if $game_map.terrain_tag(@x, @y + 1) == Swim_Config::WATER_TERRAIN
            start_swimming(player)
            move_down
          end
        when 4
          if $game_map.terrain_tag(@x - 1, @y) == Swim_Config::WATER_TERRAIN
            start_swimming(player)
            move_left
          end
        when 6
          if $game_map.terrain_tag(@x + 1, @y) == Swim_Config::WATER_TERRAIN
            start_swimming(player)
            move_right
          end
        when 8
          if $game_map.terrain_tag(@x, @y - 1) == Swim_Config::WATER_TERRAIN
            start_swimming(player)
            move_up
          end
        end
      end
    end
    update_swim
  end
 
  def start_swimming(player)
    $game_system.oxegen_picture_count = Swim_Config::PICTURE_FRAMES
    change_water_passable(0)
    swim_graphic = player.character_name + Swim_Config::SWIM_EXTENSION
    @character_name = @character_name_org = swim_graphic
    player.set_graphic(swim_graphic, player.character_hue, player.battler_name, player.battler_hue)
    @step_anime = true
    @swimming = true
  end
 
end

That code was a bit of a nightmare to read through. It was one of his earlier scripts back in the days--can't discredit the guy for actually learning RGSS.

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!

MEANDONLYME

Yeah, it looked kind of messy to me, and I don't even know that much about scripting.
Thanks for helping, it works just fine.