Save-Point
Skill Cooldown script - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: Skill Cooldown script (/thread-7600.html)

Pages: 1 2


Skill Cooldown script - Fenriswolf - 12-06-2019

Hello,

After balancing the stats and working out the skills and talents for my rmxp game during the past couple of days, I am running into a bump.
For many of the skills my actors use, I want to have a cooldown function. Meaning they cannot use specific skills for X number of turns (I use the default battle system).

Example:
Skill 1 has no cooldown
Skill 2 has a cooldown of 3 turns
Skill 3 has a cooldown of 10 turns

Ideally these skills will be greyed-out when on cooldown.

I suppose this can be done with eventing, but I think it would be far more efficient with a script.
When I looked for one, I could not find anything for rmxp.

I am hoping someone can refer me to a working script or help me tweaking one to make it work in the way I'm looking for.

As mentioned, I do not use a custom battle system, but I do use some scripts that influence battle/skills which I'll post just in case:
Threat system by Fantasist, reflection by Blizzard, hots dots by Shdwlink1993.


RE: Skill Cooldown script - Mel - 12-06-2019

You could try this script.
Sadly I don't know who made this anymore

Code:
   #==============================================================================
   #
   #------------------------------------------------------------------------------
   #
   #==============================================================================
   module Config
     Cooldown = {} # Do not touch
     Cooldown[1] = 10 # Skill with ID 1 has a cooldown of 10 turns.
   
   end
   
   #==============================================================================
   #
   #------------------------------------------------------------------------------
   #
   #==============================================================================
   class RPG::Skill
     #--------------------------------------------------------------------------
     #
     #--------------------------------------------------------------------------
     def cooldown
       return (Config::Cooldown[@id] != nil ? Config::Cooldown[@id] : 0)
     end
   end
   
   #==============================================================================
   #
   #------------------------------------------------------------------------------
   #
   #==============================================================================
   class Game_Battler
     #--------------------------------------------------------------------------
     #
     #--------------------------------------------------------------------------
     attr_accessor :cooldown
     #--------------------------------------------------------------------------
     #
     #--------------------------------------------------------------------------
     alias cooldown_initialize initialize
     def initialize
       cooldown_initialize
       @cooldown = {}
     end
     #--------------------------------------------------------------------------
     #
     #--------------------------------------------------------------------------
     alias cooldown_skill_can_use skill_can_use?
     def skill_can_use?(skill_id)
       return false if @cooldown[skill_id] != nil and @cooldown[skill_id] > 0
       return cooldown_skill_can_use(skill_id)
     end
     #--------------------------------------------------------------------------
     #
     #--------------------------------------------------------------------------
     def update_cooldowns
       @cooldown.keys.each {|id|
         @cooldown[id] = [@cooldown[id] - 1, 0].max if @cooldown[id] != nil
       }
     end
     #--------------------------------------------------------------------------
     #
     #--------------------------------------------------------------------------
     def cooldown_clear
       @cooldown.keys.each {|id| @cooldown[id] = 0}
     end
     #--------------------------------------------------------------------------
     #
     #--------------------------------------------------------------------------
     alias cooldown_skill_effect skill_effect
     def skill_effect(user, skill)
       effective = cooldown_skill_effect(user, skill)
       user.cooldown[skill.id] = skill.cooldown if effective
       return effective
     end
   end
   
   #==============================================================================
   #
   #------------------------------------------------------------------------------
   #
   #==============================================================================
   class Scene_Battle
     #--------------------------------------------------------------------------
     #
     #--------------------------------------------------------------------------
     alias cooldown_update_phase4_step2 update_phase4_step2
     def update_phase4_step2
       @active_battler.update_cooldowns
       cooldown_update_phase4_step2
     end
     #--------------------------------------------------------------------------
     #
     #--------------------------------------------------------------------------
     alias cooldown_battle_end battle_end
     def battle_end(result)
       for actor in $game_party.actors
         actor.cooldown_clear
       end
       cooldown_battle_end(result)
     end
   end



RE: Skill Cooldown script - Fenriswolf - 12-06-2019

(12-06-2019, 06:07 PM)Melana Wrote: You could try this script.
Sadly I don't know who made this anymore

Thanks for the script!

But, when I tested, the skill was still available after the first turn.
When I used it again in turn 2, it became grey in turn 3 though.

Any idea why?

EDIT: it doesn't seem to be working at all now. I'm using a fresh project without scripts to test.


RE: Skill Cooldown script - Mel - 12-07-2019

Hmm it works for me.
If I start a fresh project and give Aluxes' Cross Cut Skill a cooldown of 3 turns, it greys out once he uses the skill.


RE: Skill Cooldown script - Fenriswolf - 12-07-2019

(12-07-2019, 12:40 AM)Melana Wrote: Hmm it works for me.
If I start a fresh project and give Aluxes' Cross Cut Skill a cooldown of 3 turns, it greys out once he uses the skill.

It might have been because I used a healing skill, I will try again tomorrow morning.


RE: Skill Cooldown script - DerVVulfman - 12-07-2019

Hey, guys. That script is by Victor Sant. He wrote that back in 2011 when he was still known as Atoa.


RE: Skill Cooldown script - Fenriswolf - 12-07-2019

(12-07-2019, 04:53 AM)DerVVulfman Wrote: Hey, guys.   That script is by Victor Sant.   He wrote that back in 2011 when he was still known as Atoa.

Alright, I'll put his name in the script so I won't forget to credit him if I ever share it.

Also, it seems to be pretty glitchy with healing spells (I need to use a spell twice in a row to trigger the cooldown and it will be one turn less than supposed to).
Could it be that the script will have trouble with such skills because of their scope or occasion?


RE: Skill Cooldown script - Fenriswolf - 12-08-2019

(12-07-2019, 12:24 PM)Fenriswolf Wrote:
(12-07-2019, 04:53 AM)DerVVulfman Wrote: Hey, guys.   That script is by Victor Sant.   He wrote that back in 2011 when he was still known as Atoa.

Alright, I'll put his name in the script so I won't forget to credit him if I ever share it.

Also, it seems to be pretty glitchy with healing spells (I need to use a spell twice in a row to trigger the cooldown and it will be one turn less than supposed to).
Could it be that the script will have trouble with such skills because of their scope or occasion?

I figured out what the problem is.
Whenever a skill has a negative number or 0 as power value, the script won't work as intended.

Problem is, I mostly want to use cooldowns for utility skills (buffs, disabling abilities, etc.).
Meaning I can not use the script this way.

Anybody willing to help me fix this?


RE: Skill Cooldown script - kyonides - 12-09-2019

There's a part of the script that says "if effective"... Why don't you comment it out? That means placing a # pound symbol right in front of it... Check out if it now works as expected.


RE: Skill Cooldown script - Fenriswolf - 12-09-2019

(12-09-2019, 12:28 AM)kyonides Wrote: There's a part of the script that says "if effective"... Why don't you comment it out? That means placing a # pound symbol right in front of it... Check out if it now works as expected.

Thanks, that did the trick!
It works now, so long as a skill doesn't have scope "none", which is fine.

This should make the combat much more interesting, by having to use rotations and timing your "once in a battle" skills.