Save-Point
KChangeSkill XP - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+--- Thread: KChangeSkill XP (/thread-7414.html)



KChangeSkill XP - kyonides - 01-26-2019

KChangeSkill XP

by Kyonides-Arkanthes


Introduction

Did you ever want to add weird states to force any hero waste his SP? Did you try to force him cast a spell or perform a physical technique whenever there was no need for it or his foe was immune to that specific move? Now you are able to make the hero's life miserable for sure! Laughing

Side Notes

You still need to create the states listed in this script in your game's states tab.

Script


Code:
# * KChangeSkill XP
#   Scripter : Kyonides-Arkanthes
#   2019-01-26

#   This script will let you automatically change the skill the player chooses
#   whenever the current hero has not gotten rid of an unusual status.

#   Available Options  #

#   Weak or Strong or Random or Weak Healing Skill

#   Warning!  #
#   Two of Scene_Battle original methods have been overwritten, namely
#   update_phase3_skill_select and update_phase3_item_select.

module KChangeSkill
  EFFECTIVENESS = 75
  STATE_IDS = { 17 => :weak, 18 => :strong, 19 => :random, 20 => :healing }
end

class Scene_Battle
  def update_phase3_skill_select
    @skill_window.visible = true
    @skill_window.update
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      end_skill_select
      return
    elsif Input.trigger?(Input::C)
      @skill = @skill_window.skill
      unless @skill and @active_battler.skill_can_use?(@skill.id)
        return $game_system.se_play($data_system.buzzer_se)
      end
      $game_system.se_play($data_system.decision_se)
      effective = KChangeSkill::EFFECTIVENESS > rand(100)
      sid = effective ? get_skill_id(true) : @skill.id
      @active_battler.current_action.skill_id = sid
      @state_kind = @pos = nil
      @skill_window.visible = false
      check_skill_scope
    end
  end

  def check_skill_scope
    if @skill.scope == 1
      start_enemy_select
    elsif @skill.scope == 3 or @skill.scope == 5
      start_actor_select
    else
      end_skill_select
      phase3_next_actor
    end
  end

  def update_phase3_item_select
    @item_window.visible = true
    @item_window.update
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      end_item_select
      return
    elsif Input.trigger?(Input::C)
      @item = @item_window.item
      unless $game_party.item_can_use?(@item.id)
        return $game_system.se_play($data_system.buzzer_se)
      end
      $game_system.se_play($data_system.decision_se)
      sid = 0
      if KChangeSkill::EFFECTIVENESS > rand(100)
        sid = get_skill_id
        @active_battler.current_action.skill_id = sid
      end
      @item_window.visible = false
      if sid == 0
        @active_battler.current_action.item_id = @item.id
        check_item_scope
      else
        @skill = $data_skills[sid]
        check_skill_scope
        @state_kind = nil
        @skill = nil
        @pos = nil
      end
    end
  end

  def check_item_scope
    if @item.scope == 1
      start_enemy_select
    elsif @item.scope == 3 or @item.scope == 5
      start_actor_select
    else
      end_item_select
      phase3_next_actor
    end
  end

  def get_skill_id(found_id=nil)
    sid = found_id ? @skill.id : 0
    @active_battler.states.each do |state_id|
      next unless (@state_kind = KChangeSkill::STATE_IDS[state_id])
      @pos = case @state_kind
      when :weak, :heal then 0
      when :strong then -1
      when :random then rand(@active_battler.skills.size)
      end
      break
    end
    return sid unless @state_kind
    skills = @active_battler.skills.map {|skid| SkillPower.new(skid) }
    skills = skills.sort_by{|sd| sd.power }
    if @state_kind == :heal
      heal_skills = skills.select{|s| s.can_heal }
      return heal_skills[0].id unless heal_skills.empty?
    end
    return skills[@pos].id
  end
end

class SkillPower
  def initialize(new_id)
    @id = new_id
    pow = $data_skills[@id].power
    @power = pow.abs
    @can_heal = pow < 0
  end
  attr_reader :id, :power, :can_heal
end


Terms and Conditions

You may use it in any kind of game. If you go commercial, I will ask you to make a small payment for using in your game project. Do never forget to include me in your game credits.