Help - Search - Members - Calendar
Full Version: DSC - Skill Cooldown
RPG RPG Revolution Forums > Scripting > Script Submissions > RGSS2-Submissions
DrDhoom
I made this script for learning RGSS2. Sorry if there already another one. And, sorry for my bad English

Introduction
This script add cooldown to specific skill, so player can't use it for some turn.

Script
CODE
#==========================================================================
=====
#--------------------------=�€� Skill Cooldown �€�=---------------------------------
#---------------------------=�€� by: DrDhoom �€�=-----------------------------------
# Version: 1.1
# Date Published: 05 - 04 - 2011
# Battle Addon
# RPGMakerID Community
#-------------------------------------------------------------------------------
# Introduction:
# This script make a skill have cooldown.
#-------------------------------------------------------------------------------
# Compatibility:
# - Tankentai Sideview Battle System
# - Wij's Battle Macros
# Note: not tested in other battle system
#-------------------------------------------------------------------------------
# How to use:
#  - Insert this script above Main
#  - Insert under all Battle System Core Script
#===============================================================================

module Dhoom
  module SkillCooldown
  
    SHOW_COOLDOWN_NUMBER = true #true = cooldown number of skill show
                                #      at the end of skill name  
  
    #RGB Color
    COOLDOWN_COLOR = Color.new(255,0,0,128)  
  
    SKILL_CD = []        #<----Don't delete this line
  
    #SKILL_CD[skill id] = number of cooldown (1 is minimum number)
    SKILL_CD[1] = 1
    SKILL_CD[2] = 9
  end
end

#===============================================================================
# Start
#===============================================================================

#-------------------------------------------------------------------------------
# Window Base
#-------------------------------------------------------------------------------

class Window_Base

  def draw_skill_cooldown_name(item, x, y, enabled = true)
    if item != nil
      if @actor.skill_cooldown(item.id) != nil
        if @actor.skill_cooldown(item.id)!= 0
          cd_color = Dhoom::SkillCooldown::COOLDOWN_COLOR
          draw_icon(item.icon_index, x, y, enabled)
          self.contents.font.color = cd_color
          if Dhoom::SkillCooldown::SHOW_COOLDOWN_NUMBER
            self.contents.draw_text(x + 24, y, 172, WLH, item.name + '(' +@actor.skill_cooldown(item.id).to_s + ')')
          else
            self.contents.draw_text(x + 24, y, 172, WLH, item.name)
          end
        else
          draw_icon(item.icon_index, x, y, enabled)
          self.contents.font.color = normal_color
          self.contents.font.color.alpha = enabled ? 255 : 128
          self.contents.draw_text(x + 24, y, 172, WLH, item.name)
        end
      else
        draw_icon(item.icon_index, x, y, enabled)
        self.contents.font.color = normal_color
        self.contents.font.color.alpha = enabled ? 255 : 128
        self.contents.draw_text(x + 24, y, 172, WLH, item.name)
      end
    end
  end
end

#-------------------------------------------------------------------------------
# Window Skill
#-------------------------------------------------------------------------------

class Window_Skill < Window_Selectable

  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    skill = @data[index]
    if skill != nil
      rect.width -= 4
      enabled = @actor.skill_can_use?(skill)
      draw_skill_cooldown_name(skill, rect.x, rect.y, enabled)
      self.contents.draw_text(rect, @actor.calc_mp_cost(skill), 2)
    end
  end
end

#-------------------------------------------------------------------------------
# Game Actor
#-------------------------------------------------------------------------------

class Game_Actor

  alias dsc_actor_setup setup
  alias dsc_skill_can_use? skill_can_use?

  def setup(actor_id)
    dsc_actor_setup(actor_id)
    @skill_cooldown = []
  end

  def make_cooldown_value(id)
    @skill_cooldown[id] = Dhoom::SkillCooldown::SKILL_CD[id]
    if $imported == nil
      @skill_cooldown[id] += 1
    elsif $imported["TankentaiATB"]
      @skill_cooldown[id] -= 0
    elsif $imported["TankentaiSideview"]
      @skill_cooldown[id] += 1
    else
      @skill_cooldown[id] += 1
    end
  end

  def skill_cooldown(id)
    return @skill_cooldown[id]
  end

  def decrease_cooldown(id)
    @skill_cooldown[id] -= 1
  end
  
  def reset_cooldown(id)
    @skill_cooldown[id] = 0
  end

  def skill_can_use?(skill)
    if skill_cooldown(skill.id) != nil
      return false if skill_cooldown(skill.id) != 0
    end
    dsc_skill_can_use?(skill)
  end
end

#-------------------------------------------------------------------------------
# Scene Battle
#-------------------------------------------------------------------------------

class Scene_Battle < Scene_Base
  
  alias dsc_battle_end battle_end
  alias dsc_execute_action_skill execute_action_skill
  alias dsc_start_actor_command_selection start_actor_command_selection
  
  def battle_end(result)
    for actor in $game_party.members
      for skill in actor.skills
        actor.reset_cooldown(skill.id)
      end
    end
    dsc_battle_end(result)
  end

  def execute_action_skill
    dsc_execute_action_skill
    skill = @active_battler.action.skill
    if Dhoom::SkillCooldown::SKILL_CD[skill.id] != nil
      @active_battler.make_cooldown_value(skill.id)
    end
  end

  def start_actor_command_selection
    dsc_start_actor_command_selection
    if @active_battler != nil and @active_battler.actor?    
      for skill in @active_battler.skills
        if @active_battler.skill_cooldown(skill.id) != nil
          if @active_battler.skill_cooldown(skill.id) != 0
            @active_battler.decrease_cooldown(skill.id)
          end
        end
      end
    elsif @commander !=nil
      for skill in @commander.skills
        if @commander.skill_cooldown(skill.id) != nil
          if @commander.skill_cooldown(skill.id) != 0
            @commander.decrease_cooldown(skill.id)
          end
        end
      end
    end
  end
end

#===============================================================================
# End
#===============================================================================


Instruction
Place above main and under all core battle script.
hainkiwanki
Cool script ^^
TTrain427
how do we use it on only one or two specific skills?
DrDhoom
QUOTE (TTrain427 @ May 23 2011, 10:16 AM) *
how do we use it on only one or two specific skills?


see the module...
then, just add SKILL_CD[Skill id] = number of cooldown you want...

example:
SKILL_CD[1] = 1 # 1 cooldown for skill 1
SKILL_CD[2] = 9 # 9 cooldown for skill 2
Night5h4d3
This is a good looking script, but I have a few suggestions I'd like to venture.
You can put the cooldown color constant as a color type (this saves lines and an array)
CODE
COOLDOWN_COLOR = Color.new(255,0,0,128)

And people already know that a color format is in RGBA.

Secondly, instead of initializing the array, then setting the skills to cooldown, have the skills specified during initialization
CODE
SKILL_CD = [1, 9]

This way people don't need a new line for every skill, and they don't have to increment the SKILL_CD index for each new skill
(If you decide to keep your method on both of these, that's fine, but arrays start at the index 0, so you'll want to change that)
InfinateX
this is a neat script! Fortunatley I'm using tankentia so it will definatley work. BTW I didn't know WIJ made a battle script!
DrDhoom
@Night5h4d3: thanks for your suggestions... but i'm only change the color XD
@RPGMakerVX52: thanks biggrin.gif
Twin Matrix
So what exactly happens visually when a skill is on a cool down? How do you see when it's available again? :3
DrDhoom
QUOTE (Twin Matrix @ Jun 1 2011, 03:16 AM) *
So what exactly happens visually when a skill is on a cool down? How do you see when it's available again? :3


if show_cooldown_number is true, there will be a cooldown number at the end of skill's name. if avaible the cooldown number is gone biggrin.gif
InfinateX
I can't believe I didn't download this in May when I first found it! This is an awesome script!
Desa
Using takentai, and it has problem with line 124, could you check it?
Thanks!

Desa
InfinateX
QUOTE (Desa @ Jul 7 2011, 03:39 AM) *
Using takentai, and it has problem with line 124, could you check it?
Thanks!

Desa


If it was tested to work it could be an incompatable script fighting due to lack of aliases since the scripts were not ment to work together.

In order from top to bottom what are your script?
clout1
When in battle, guarding doesnt decrease the cooldown timer, can anyone help me with this?
DrDhoom
ukh sorry for leaving this thread for a long time... and this version have a bug... and unfortunely, i'm forget to bring the fixed version =_="
i'll update it soon tomorrow...
DrDhoom
@clout1: the cooldown still decrease while guarding. did you using tankentai or default battle system?

and i'm just updatet the first post... added reset cooldown when battle ended... and let me know if you have problem with this...

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.