SkkillUses XP
#1
SkkillUses XP

by Kyonides Arkanthes


Introduction

This scriptlet allows you to set a skill use system instead of consuming mana! Shocked 
It even allows you to set different use maximums for actors and enemies! Grinning

skills.default = Number
It lets you set a default maximum for actors and enemies in that order! Shocked It's mainly because it appears twice in my script. Laughing

Warning!

It overwrites a few default methods and aliases some other methods like initialize.

Script
Code:
# * SkkillUses XP Default Version
#   Scripter : Kyonides Arkanthes
#   v1.0.0 - 2019-12-22

# * Script Calls * #

# Get an Actor
#   battler = $game_party.actors[Index]
# Get an Enemy
#   battler = $game_troop.enemies[Index]
# Change Skill Use Maximum - Checks Max and returns the New Maximum
#   battler.change_skill_use_max(Skill_ID, USES_MAX)
# Replenishes a Skill's Use Max
#   battler.refill_skill_use(Skill_ID, USES)
# Replenishes Skills' Use Max
#   battler.refill_skill_uses

module Skkill
  USES = { :actor => {}, :enemy => {} }
  # Actors' Skill IDs
  skills = USES[:actor]
  skills.default = 3
  skills[1] = 5
  skills[57] = 5
  # Enemies' Skill IDs
  skills = USES[:enemy]
  skills.default = 3
  skills[1] = 5
end

class Game_Battler
  def skill_can_use?(skill_id)
    return false if dead? or self.skill_uses[skill_id] == 0
    return false if $data_skills[skill_id].atk_f == 0 and self.restriction == 1
    occasion = $data_skills[skill_id].occasion
    if $game_temp.in_battle
      return (occasion == 0 or occasion == 1)
    else
      return (occasion == 0 or occasion == 2)
    end
  end

  def change_skill_use_max(sid, new_max)
    temp_max = [@skill_use_max[sid], 0].max
    @skill_use_max[sid] = [new_max, temp_max].min
    skill_use_max(sid)
  end

  def refill_skill_use(sid, uses)
    @skill_uses[sid] = [@skill_uses[sid] + uses, skill_use_max(sid)].min
  end

  def refill_skill_uses
    @skill_uses.keys.each{|sid| @skill_uses[sid] = skill_use_max(sid) }
  end
  def skill_use_max(sid) Skkill::USES[kind][sid] + @skill_use_max[sid] end
  def skill_use(sid) @skill_uses[sid] -= 1 end
  attr_reader :skill_uses
end

class Game_Actor
  alias :kyon_skilluses_gm_actor_init :initialize
  def initialize(actor_id)
    kyon_skilluses_gm_actor_init(actor_id)
    @skill_uses = {}
    @skill_use_max = {}
    @skill_use_max.default = 0
    @skills.each{|sid| @skill_uses[sid] = Skkill::USES[:actor][sid] }
  end

  def kind() :actor end
end

class Game_Enemy
  alias :kyon_skilluses_gm_enemy_init :initialize
  def initialize(troop_id, member_index)
    kyon_skilluses_gm_enemy_init(troop_id, member_index)
    @skill_uses = {}
    @skill_use_max = {}
    @skill_use_max.default = 0
    $data_enemies[@enemy_id].actions.each do |action|
      next if action.kind != 1
      sid = action.skill_id
      @skill_uses[sid] = Skkill::USES[:enemy][sid]
    end
  end
  def kind() :enemy end
end

class Window_Skill
  def draw_item(index)
    skill = @data[index]
    usable = @actor.skill_can_use?(skill.id)
    self.contents.font.color = usable ? normal_color : disabled_color
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(skill.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    uses = @actor.skill_uses[skill.id].to_s
    use_max = @actor.skill_use_max(skill.id).to_s
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 204, 32, skill.name, 0)
    self.contents.draw_text(x + 200, y, 48, 32, uses, 2)
    self.contents.draw_text(x + 248, y, 8, 32, '/')
    self.contents.draw_text(x + 256, y, 48, 32, use_max)
  end
end

class Scene_Skill
  def update_skill
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(1)
      return
    elsif Input.trigger?(Input::C)
      @skill = @skill_window.skill
      unless @skill and @actor.skill_can_use?(@skill.id)
        return $game_system.se_play($data_system.buzzer_se)
      end
      $game_system.se_play($data_system.decision_se)
      if @skill.scope >= 3
        @skill_window.active = false
        @target_window.x = (@skill_window.index + 1) % 2 * 304
        @target_window.visible = true
        @target_window.active = true
        if @skill.scope == 4 || @skill.scope == 6
          @target_window.index = -1
        elsif @skill.scope == 7
          @target_window.index = @actor_index - 10
        else
          @target_window.index = 0
        end
        return
      else
        if @skill.common_event_id > 0
          $game_temp.common_event_id = @skill.common_event_id
          $game_system.se_play(@skill.menu_se)
          @actor.skill_use(@skill.id)
          @status_window.refresh
          @skill_window.refresh
          @target_window.refresh
          return $scene = Scene_Map.new
        end
      end
    elsif Input.trigger?(Input::R)
      $game_system.se_play($data_system.cursor_se)
      @actor_index += 1
      @actor_index %= $game_party.actors.size
      return $scene = Scene_Skill.new(@actor_index)
    elsif Input.trigger?(Input::L)
      $game_system.se_play($data_system.cursor_se)
      @actor_index += $game_party.actors.size - 1
      @actor_index %= $game_party.actors.size
      $scene = Scene_Skill.new(@actor_index)
    end
  end

  def update_target
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @skill_window.active = true
      @target_window.visible = false
      @target_window.active = false
      return
    end
    if Input.trigger?(Input::C)
      unless @actor.skill_can_use?(@skill.id)
        return $game_system.se_play($data_system.buzzer_se)
      end
      if @target_window.index == -1
        used = false
        for i in $game_party.actors
          used |= i.skill_effect(@actor, @skill)
        end
      end
      if @target_window.index <= -2
        target = $game_party.actors[@target_window.index + 10]
        used = target.skill_effect(@actor, @skill)
      end
      if @target_window.index >= 0
        target = $game_party.actors[@target_window.index]
        used = target.skill_effect(@actor, @skill)
      end
      if used
        $game_system.se_play(@skill.menu_se)
        @actor.skill_use(@skill.id)
        @status_window.refresh
        @skill_window.refresh
        @target_window.refresh
        return $scene = Scene_Gameover.new if $game_party.all_dead?
        if @skill.common_event_id > 0
          $game_temp.common_event_id = @skill.common_event_id
          return $scene = Scene_Map.new
        end
      end
      $game_system.se_play($data_system.buzzer_se) unless used
    end
  end
end

class Scene_Battle
  def make_skill_action_result
    @skill = $data_skills[@active_battler.current_action.skill_id]
    unless @active_battler.current_action.forcing
      unless @active_battler.skill_can_use?(@skill.id)
        $game_temp.forcing_battler = nil
        return @phase4_step = 1
      end
    end
    @active_battler.skill_use(@skill.id)
    @status_window.refresh
    @help_window.set_text(@skill.name, 1)
    @animation1_id = @skill.animation1_id
    @animation2_id = @skill.animation2_id
    @common_event_id = @skill.common_event_id
    set_target_battlers(@skill.scope)
    @target_battlers.each{|target| target.skill_effect(@active_battler, @skill)}
  end
end

Terms & Condition
You can freely use it in non commercial games except for anybody that got a nickname, namely Silly. Laughing + Tongue sticking out
You must include my nickname in your game credits!
Include the URL of the website where you found my script!
Give me a free copy of your completed game if you include at least 2 of my scripts! Laughing + 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 }


Messages In This Thread
SkkillUses XP - by kyonides - 12-22-2019, 11:49 PM



Users browsing this thread: 1 Guest(s)