Code:
# * KBuild XP * #
# Scripter : Kyonides
# 2026-07-11
# This scriptlet allows you to copy and paste tiles on the fly on maps that
# use the same tileset. It totally depends on script calls to work.
# * Script Calls - 2 Stages * #
# * Development Stage Only * #
# - Copy a custom Area with Tiles on the current map for future calls.
# KBuild.set_build_area(AreaID, X, Y, Width, Height)
# - Save all custom Areas with Tiles for future calls.
# KBuild.save_buildings
# * For Both Development Stage and Normal Gameplay * #
# - Paste a custom Area with Tiles on the current map.
# It will fail if both maps don't share the same tileset!
# KBuild.build_area(BaseMapID, ThisMapID, AreaID, X, Y, Width, Height)
module KBuild
BUILDING_AREAS_FN = "Data/KBuildingAreas.rxdata"
BUILD_SE = "129-Earth01"
@build_se = RPG::AudioFile.new(BUILD_SE, 50)
extend self
attr_accessor :building_areas
def set_build_area(key, *area)
map_id = $game_map.map_id
table = $game_map.area_tiles(key, area)
@building_areas[map_id][key] = table
end
def build_area(base_map_id, map_id, key, *area)
map = $game_system.map_data[base_map_id]
return if map and $game_map.map.tileset_id != map.tileset_id
areas = $game_system.built_areas[map_id]
return if areas.include?(key)
$game_system.se_play(@build_se)
$game_system.dup_map(map_id)
areas << key
map_data = $game_system.map_data[map_id]
map_table = map_data.data
table = @building_areas[base_map_id][key]
min_x = area.shift
min_y = area.shift
width = area.shift
height = area.shift
for i in 0..2
width.times do |mx|
height.times do |my|
map_table[min_x + mx, min_y + my, i] = table[mx, my, i]
end
end
end
$game_map.replace_data
end
def save_buildings
save_data(@building_areas, BUILDING_AREAS_FN)
end
def load_maps
if FileInt.exist?(BUILDING_AREAS_FN)
@building_areas = load_data(BUILDING_AREAS_FN)
else
@building_areas = {}
@building_areas.default = {}
end
end
load_maps
end
class Game_System
alias :kyon_tiles_gm_sys_init :initialize
def initialize
kyon_tiles_gm_sys_init
@map_data = {}
@built_areas = {}
@built_areas.default = []
end
def dup_map(map_id)
@map_data[map_id] ||= $game_map.map
end
attr_accessor :map_data, :built_areas
end
class Game_Map
alias :kyon_tiles_gm_map_stp :setup
def setup(map_id)
kyon_tiles_gm_map_stp(map_id)
replace_data
end
def replace_data
map_data = $game_system.map_data
return unless map_data.has_key?(@map_id)
@map = map_data[@map_id]
@need_refresh = true
end
def area_tiles(key, area)
min_x = area.shift
min_y = area.shift
width = area.shift
height = area.shift
table = Table.new(width, height, 3)
map_table = @map.data
for i in 0..2
width.times do |mx|
height.times do |my|
table[mx, my, i] = map_table[min_x + mx, min_y + my, i]
end
end
end
table
end
def tileset_id
@map.tileset_id
end
attr_reader :map
end