KBuild XP
#1
KBuild XP

by Kyonides

Introduction

Did you ever want to copy and paste tiles on a map?
Did you ever plan to create your very own city builder (on a small scale)?
Or did you ever dream on recreating your favorite Harvest Moon game?

Well, now that might be possible! Grinning
Happy with a sweat On a small scale at least. Laughing

My scriptlet includes 3 useful script calls that might make it happen! Winking

The Script

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



Terms & Conditions

Free as in Beer beer.
Include my nickname in your game credits! Shocked
That's it! 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)