SkkillUses XP

kyonides

Veteran
Veteran
Joined
Nov 17, 2019
Messages
131
Reaction score
28
First Language
English
Primarily Uses
RMXP
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!
:grin:


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.
:XD:


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.
:XP:

You must include my nickname in your game credits!
Include the URL of the website where you found my script!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Yaaay! My second public script is out and approved! A VX Ace Final Fantasy IX styled Throw Script!

I look forward to all the constructive feedback I get but most importantly I hope everyone who ends up using it enjoys!

Yaaaay! Making scripts is fun lol. :D
When you're lost out therrrrre and you're alllll alone, ahwahwah waitin, to carry you hooooommmme, uhhheverywhere you look! (someone hit me with those backing vocals)
X.X cant focus... too many thing want do... help!
Day 2 of teaching MV, student can move cat across the map.
Got inspired and started writing a simple tower defence battle system last night :o

Forum statistics

Threads
100,525
Messages
976,803
Members
132,080
Latest member
nwr
Top