Save-Point
KSetTilesets XP - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+--- Thread: KSetTilesets XP (/thread-8723.html)



KSetTilesets XP - kyonides - 04-29-2023

KSetTilesets XP
Version 1.0.0

by Kyonides Arkanthes

Introduction

This scriptlet should let you set a new tileset as the default one for any given map via script call.

The main idea behind it is to replace the default tileset with another one with some tiles changed for any specific reason, like different house facades or withered trees or an open well or all of them at the same time.

It is pretty much like a method to stop making dozens of events to cover those areas. This might be especially useful if the changes are supposed to last for a long period of time or even for the rest of your game.

It DOES refresh the current map and its spriteset!

It also works for other maps, obviously.

Warning

If you have implemented other scripts that have changed how the Game_Map class works, make sure you place this script above all of them.


The Script

Code:
# * KSetTilesets XP * #
#   Scripter : Kyonides Arkanthes
#   v1.0.0 - 2024-05-02

# * Warning! * #
# If you have implemented other scripts that have changed how the Game_Map
# class works, make sure you place this script above all of them.

# It should let you completely replace your current map's tileset with another
# one that shares similar passability and other settings, while retaining all
# of the changes you have made to its actual tiles.

# * Script Calls * #
#  Both script calls will refresh the target map's Tileset Data
#  IF the new MapID matches with the current MapID.

# - Set a new Tileset for MapID n
#   $game_map.change_tileset(map_id, tileset_id)
# - Remove any new Tileset for MapID n
#   $game_map.default_tileset(map_id)

class Game_Map
  alias :kyon_tileset_sw_gm_map_init :initialize
  def initialize
    kyon_tileset_sw_gm_map_init
    @tilesets = {}
  end

  def setup(map_id)
    @map_id = map_id
    @map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
    setup_tileset
    setup_events
    setup_fog
    setup_scroll
  end

  def find_current_tileset
    @tilesets[@map_id] || @map.tileset_id
  end

  def setup_tileset
    tileset_id = find_current_tileset
    tileset = $data_tilesets[tileset_id]
    @tileset_name = tileset.tileset_name
    @autotile_names = tileset.autotile_names
    @panorama_name = tileset.panorama_name
    @panorama_hue = tileset.panorama_hue
    @fog_name = tileset.fog_name
    @fog_hue = tileset.fog_hue
    @fog_opacity = tileset.fog_opacity
    @fog_blend_type = tileset.fog_blend_type
    @fog_zoom = tileset.fog_zoom
    @fog_sx = tileset.fog_sx
    @fog_sy = tileset.fog_sy
    @battleback_name = tileset.battleback_name
    @passages = tileset.passages
    @priorities = tileset.priorities
    @terrain_tags = tileset.terrain_tags
  end

  def setup_events
    @need_refresh = false
    @events = {}
    for i in @map.events.keys
      @events[i] = Game_Event.new(@map_id, @map.events[i])
    end
    @common_events = {}
    for i in 1...$data_common_events.size
      @common_events[i] = Game_CommonEvent.new(i)
    end
  end

  def setup_fog
    @fog_ox = 0
    @fog_oy = 0
    @fog_tone = Tone.new(0, 0, 0, 0)
    @fog_tone_target = Tone.new(0, 0, 0, 0)
    @fog_tone_duration = 0
    @fog_opacity_duration = 0
    @fog_opacity_target = 0
  end

  def setup_scroll
    @display_x = 0
    @display_y = 0
    @scroll_direction = 2
    @scroll_rest = 0
    @scroll_speed = 4
  end

  def change_tileset(map_id, tileset_id)
    return if tileset_id == 0 or @tilesets[map_id] == tileset_id
    @tilesets[map_id] = tileset_id
    setup_tileset if @map_id == map_id
  end

  def default_tileset(map_id)
    return unless @tilesets[map_id]
    @tilesets[map_id] = nil
    setup_tileset if @map_id == map_id
  end
  attr_reader :tilesets
end


Terms & Conditions

Free for use in your game projects.
Include my nickname in your game credits.
You could include an URL to the website where you found this scriptlet.


RE: KSetTilesets XP - kyonides - 05-03-2023

Script Improved!

Since some people complained about my script not being able to reload the current map in real time, I just let it do that by telling it to retrieve the new tileset data at once. Happy with a sweat Well, it can also revert to the original tileset if needed.

Happy Tile Switching! Tongue sticking out