KSetTilesets XP
#1
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.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }
#2
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
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }




Users browsing this thread: 1 Guest(s)