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

2 calls are used exclusively during the Sculptor development stage, while the remaining one can be used at any time. Grinning

By the way, it can also play a SE and some animation! Two Thumbs Up! Both are optional.

The Script

Code:
# * KBuild XP * #
#   Scripter : Kyonides
#   v0.7.0 - 2026-07-12

# 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"
  # Set the SE name or leave it empty
  BUILD_SE = "129-Earth01"
  # DB Animation ID or 0 for none
  BUILD_ANIME = 17
  @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
    b_area = @building_areas[map_id].areas[key]
    b_area.id = $game_map.map.tileset_id
    b_area.table = $game_map.area_tiles(key, area)
  end

  def build_area(base_map_id, map_id, key, *area)
    b_area = @building_areas[base_map_id].areas[key]
    return if $game_map.map.tileset_id != b_area.id
    areas = $game_system.built_areas[map_id]
    return if areas.include?(key)
    $game_system.se_play(@build_se) unless BUILD_SE.empty?
    map = $game_system.dup_map(map_id)
    if BUILD_ANIME > 0
      interpreter = $game_system.map_interpreter
      event = interpreter.get_character(0)
      event.animation_id = BUILD_ANIME
    end
    areas << key
    map_table = map.data
    table = b_area.table
    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

  class Area
    attr_accessor :table, :id
  end

  class Map
    def initialize
      @areas = {}
      @areas.default = Area.new
    end
    attr_reader :areas
  end

  def save_buildings
    save_data(@building_areas, BUILDING_AREAS_FN)
  end

  def load_maps
    begin
      @building_areas = load_data(BUILDING_AREAS_FN)
    rescue
      @building_areas = {}
      @building_areas.default = Map.new
    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
#2
Script Update

Yeah, I know. Only 1 day has passed and I already came back with an updated release. Happy with a sweat But it's for a good reason!

Recent Changes:
  • Some Dog Wulfo reported a Bug bug involving a HiddenChest-exclusive class called FileInt.
    It has been replaced by a begin rescue block valid for both vanilla RMXP and HiddenChest.
  • Made playing a SE optional. Grinning
  • Implemented playing an animation on the event with the KBuild.build_area script call.
    It's optional as well. Winking
  • Uploaded a new demo to MediaFire.
"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
#3
Script Update

Once again, I come here to announce that a new demo and script are available here! Grinning

What happened is that some Dog Wulfo started finding a weird messed-up tree on the second map if the copy tent had not been placed on the first map. This lead me to delve into the code to find the root cause.

The issue was that the KBuild.build_area script call was not returning a false value on the second map because it was reading the current map's tileset ID twice, even if the code suggested they were different in essence.

To solve this I had to first realized that I did NOT have a need to call the base map's data at all. It would suffice to store the tileset ID in the building areas previously set by the Gamer game developer. And that was it! Winking The infamous Bug bug has been smashed successfully!
"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)