Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 KBattleLog XP
#1
KBattleLog XP

by Kyonides Arkanthes


Introduction

This script simply keeps a record of your performance in battle by adding basic information to a log.
It stores its contents in the BattleLog.txt fileĀ once the battle is over.

Code:
# * KBattleLog XP * #
#   Scripter : Kyonides Arkanthes
#   v0.3.0 - 2023-02-06

module KBattleLog
  BEGINS = "The battle begins!"
  TROOP_NAME = "The troop calls itself %s"
  TROOP_MEMBERS = "The troop consists of "
  PARTY_MEMBERS = "You heroes are "
  ESCAPE_FAILED = "Your party failed to escape!"
  GOLD_SYM_MODE = :first # Options - :first or :last
  GAIN_EXP = "Each hero gained %s EXP!"
  GAIN_GOLD = "Your party earned %s%s"
  CONGRATULATIONS = "Congratulations for defeating those bastards!"
  VICTORY = "Your party is victorious!"
  ESCAPE = "Your party escaped from the battlefield!"
  DEFEAT = "Your party has been defeated!"
  LEVEL_UP = "%s has leveled up!"
  HEROES_STATS = "Your Heroes' Stats:"
  HERO_STATS = "%s: HP %s/%s - SP %s/%s"
  extend self
  @lines = []
  attr_reader :message
  def <<(text)
    @lines << text
  end

  def start
    @lines << BEGINS
    @lines << sprintf(TROOP_NAME, $game_troop.name)
    @lines << TROOP_MEMBERS + $game_troop.names.join(", ") + "."
    @lines << PARTY_MEMBERS + $game_party.names.join(", ") + "."
  end

  def old_levels
    @levels = $game_party.levels
  end

  def check_levels
    names = $game_party.names
    levels = $game_party.levels
    @levels.size.times do |n|
      next if levels[n] == @levels[n]
      @lines << sprintf(LEVEL_UP, names[n])
    end
    @lines << HEROES_STATS
    $game_party.actors.each do |a|
      @lines << sprintf(HERO_STATS, a.name, a.hp, a.maxhp, a.sp, a.maxsp)
    end
  end

  def win(exp, gold, treasures)
    @lines << VICTORY
    @lines << sprintf(GAIN_EXP, exp)
    if GOLD_SYM_MODE == :first
      sub1, sub2 = $data_system.words.gold, gold
    else
      sub1, sub2 = gold, $data_system.words.gold
    end
    @lines << sprintf(GAIN_GOLD, sub1, sub2)
    return if treasures.empty?
    @lines << treasures.map{|t| t.name }.join(", ")
  end

  def finish(result)
    texts = [CONGRATULATIONS, ESCAPE, DEFEAT]
    @lines << texts[result]
    save_file
  end

  def save_file
    troop = $game_troop.name.sub("*", "x")
    filename = "Logs/BattleLogVs#{troop}.txt"
    File.open(filename, "w"){|f| f.puts @lines }
  end

  def make_dir
    Dir.mkdir("Logs") unless Dir.exist?("Logs")
  end
  make_dir
end

class Game_Battler
  alias :kyon_battlelog_gm_btlr_attack_fx :attack_effect
  alias :kyon_battlelog_gm_btlr_skill_fx :skill_effect
  alias :kyon_battlelog_gm_btlr_item_fx :item_effect
  def attack_effect(attacker)
    result = kyon_battlelog_gm_btlr_attack_fx(attacker)
    if @critical
      KBattleLog << "#{attacker} hits #{self.name} with a critical blow!"
    elsif @damage == "Miss"
      KBattleLog << "#{attacker} fails to hit #{self.name}!"
    else
      KBattleLog << "#{attacker} attacks #{self.name}!"
    end
    result
  end

  def skill_effect(user, skill)
    result = kyon_battlelog_gm_btlr_skill_fx(user, skill)
    sn = skill.name
    nm = self.name
    if @critical
      KBattleLog << "#{user} casts a powerful #{sn} spell on #{nm}!"
    elsif @damage == "Miss"
      KBattleLog << "#{user} fails to cast #{sn} on #{nm}!"
    else
      KBattleLog << "#{user} casts #{sn} on #{nm}!"
    end
    result
  end

  def item_effect(item)
    result = kyon_battlelog_gm_btlr_item_fx(item)
    return result unless $game_temp.in_battle
    on = item.name
    if @damage == "Miss"
      KBattleLog << "#{self.name} fails to consume the #{on}!"
    else
      KBattleLog << "#{self.name} consumes the #{on}!"
    end
    result
  end
end
  
class Game_Party
  def names
    @actors.map{|a| a.name }
  end

  def levels
    @actors.map{|a| a.level }
  end
end

class Game_Troop
  alias :kyon_battlelog_gm_troop_setup :setup
  def setup(troop_id)
    kyon_battlelog_gm_troop_setup(troop_id)
    @troop_id = troop_id
  end

  def name
    $data_troops[@troop_id].name
  end

  def names
    @enemies.map{|e| e.name }
  end
end

class Window_BattleResult
  alias :kyon_battlelog_win_blt_result_init :initialize
  def initialize(exp, gold, treasures)
    kyon_battlelog_win_blt_result_init(exp, gold, treasures)
    KBattleLog.win(exp, gold, treasures)
  end
end

class Scene_Battle
  alias :kyon_battlelog_scn_btl_start_ph1 :start_phase1
  alias :kyon_battlelog_scn_btl_start_ph5 :start_phase5
  alias :kyon_battlelog_scn_btl_btl_end :battle_end
  def start_phase1
    KBattleLog.start
    kyon_battlelog_scn_btl_start_ph1
  end

  def update_phase2_escape
    enemies_agi = 0
    enemies_number = 0
    for enemy in $game_troop.enemies
      if enemy.exist?
        enemies_agi += enemy.agi
        enemies_number += 1
      end
    end
    if enemies_number > 0
      enemies_agi /= enemies_number
    end
    actors_agi = 0
    actors_number = 0
    for actor in $game_party.actors
      if actor.exist?
        actors_agi += actor.agi
        actors_number += 1
      end
    end
    if actors_number > 0
      actors_agi /= actors_number
    end
    success = rand(100) < 50 * actors_agi / enemies_agi
    if success
      $game_system.se_play($data_system.escape_se)
      $game_system.bgm_play($game_temp.map_bgm)
      battle_end(1)
    else
      KBattleLog << KBattleLog::ESCAPE_FAILED
      $game_party.clear_actions
      start_phase4
    end
  end

  def start_phase5
    KBattleLog.old_levels
    kyon_battlelog_scn_btl_start_ph5
    KBattleLog.check_levels
  end

  def battle_end(result)
    kyon_battlelog_scn_btl_btl_end(result)
    KBattleLog.finish(result)
  end
end


Default Output

Code:
The battle begins!
The troop calls itself Ghost*2
The troop consists of Ghost, Ghost
You are counting on Aluxes, Basil, Gloria, Hilda
Your party is victorious!
Each hero gained 4 EXP!
Your party earned G32
Your Heroes' Stats:
Aluxes: HP 741/741 - SP 434/534
Basil: HP 695/695 - SP 491/591
Gloria: HP 486/486 - SP 661/661
Hilda: HP 422/422 - SP 606/606
Congratulations for defeating those bastards!

Terms & Conditions

Free as in Beer beer.
Do not repost it!
"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: