Skill "Consumables" Script?

Status
Not open for further replies.

Allusion

♕ The Girl Who Lived (for chocolate) ♛
Veteran
Joined
Aug 21, 2013
Messages
163
Reaction score
169
First Language
English
Primarily Uses
Hello! I was looking for a way to have certain skills treated like consumable items; x number available for use, and when you run out, you can no longer use the skill until it's 'recharged' (or re-collected/bought/etc...) it is forgotten, no longer in the skill menu (rather than just being grayed out.)

For anyone familiar with FF8's magic system, it's exactly like that! (They had to find spells again via draw points, and would collect x amount of a spell to use in battle.)

The amount of spell/skill units the player has left to use would be shown beside the MP/TP cost.

Fomar has something like this already, but unfortunately it seems the system has never been supported, and he didn't explain how to use it. (Such as how to re-fill charges, nor did he update the script to allow for charge caps, etc...) I'll paste it below in case anyone would like to reference it!

Code:
=begin
Skill Charges
by Fomar0153
Version 1.0
----------------------
Notes
----------------------
This script can implement two new features.
The first is skill charges, each time you learn a skill
you gain a charge in it and you're allowed to use that skill
only as many times as you have charges per battle.
The second feature is that each time you learn a skill after
initially learning it the skill gets more powerful.
Using both features together allows for your skills to get
weaker each time you use a charge.
----------------------
Instructions
----------------------
Change the variables in the Fomar module to suit your needs.
----------------------
Known bugs
----------------------
None
=end
module Fomar
 
  # With this set to true you can only use each skill as
  # many times as you have skill charges
  SKILL_CHARGES = true
  # 50% increase in skill power per additional charge
  # set to 0.0 if you don't want this feature
  SKILL_CHARGES_POWER_INC = 0.5
  # Set to true to display a message when you gain a skill charge
  SKILL_CHARGES_MSG = true
  # %s will be replaced with the actor's name and skill's name
  SKILL_CHARGES_VOCAB = "%s gained a skill charge of %s."
 
end

class Game_Actor < Game_Battler
 
  attr_accessor :skill_charges
  attr_accessor :used_skill_charges
 
  alias sc_setup setup
  def setup(actor_id)
    @skill_charges = []
    @used_skill_charges = []
    sc_setup(actor_id)
  end
 
  alias sc_learn_skill learn_skill
  def learn_skill(skill_id)
    if skill_learn?($data_skills[skill_id])
      @skill_charges[skill_id] += 1
      if $game_party.in_battle and Fomar::SKILL_CHARGES_MSG
        $game_message.add(sprintf(Fomar::SKILL_CHARGES_VOCAB, @name, $data_skills[skill_id].name))
      end
    else
      sc_learn_skill(skill_id)
      @skill_charges[skill_id] = 1
    end
  end
 
  def usable?(item)
    return super unless $game_party.in_battle
    return super if item.is_a?(RPG::Skill) && (item.id == attack_skill_id || item.id == guard_skill_id)
    return false if item.is_a?(RPG::Skill) &&
      (@skill_charges[item.id] - @used_skill_charges[item.id] == 0 && Fomar::SKILL_CHARGES)
    return super(item)
  end
 
  def reset_skill_charges
    for skill in @skills + [attack_skill_id,guard_skill_id]
      @used_skill_charges[skill] = 0
    end
  end
 
  alias sc_use_item use_item
  def use_item(item)
    sc_use_item(item)
    return unless $game_party.in_battle
    @used_skill_charges[item.id] += 1 if item.is_a?(RPG::Skill)
  end
 
  def skill_damage_mult(item)
    return 1.0 if item.id == attack_skill_id or item.id == guard_skill_id
    if @used_skill_charges[item.id].nil?
      @used_skill_charges[item.id] = 0
    end
    return 1.0 + (@skill_charges[item.id] - @used_skill_charges[item.id]).to_f * Fomar::SKILL_CHARGES_POWER_INC
  end
 
end

class Game_Battler < Game_BattlerBase
 
  alias sc_item_element_rate item_element_rate
  def item_element_rate(user, item)
    if user.actor? and item.is_a?(RPG::Skill)
      sc_item_element_rate(user, item) * user.skill_damage_mult(item)
    else
      sc_item_element_rate(user, item)
    end
  end
 
end

module BattleManager
 
  class << self
    alias sc_setup setup
  end
 
  def self.setup(troop_id, can_escape = true, can_lose = false)
    sc_setup(troop_id, can_escape, can_lose)
    for actor in $game_party.members
      actor.reset_skill_charges
    end
  end
 
end

class Window_BattleSkill < Window_SkillList
 
  def draw_item_name(item, x, y, enabled = true, width = 172)
    return unless item
    draw_icon(item.icon_index, x, y, enabled)
    change_color(normal_color, enabled)
    draw_text(x + 24, y, width, line_height, item.name + " (" + (@actor.skill_charges[item.id] - @actor.used_skill_charges[item.id]).to_s + ")")
  end
 
end

Compatibility:
For my project, I'm using Yanfly's battle system, as well as Yami's Skill Equip.
 

mathmaster74

just...John
Veteran
Joined
Jun 12, 2016
Messages
285
Reaction score
192
First Language
English
Primarily Uses
RMMV
@Allusion Since you're already using Yanfly's Battle Core, may I suggest Yanfly's Limited Skill Uses plugin? I'm using it extensively in one of my projects and it works great! :hhappy:Best!:smile:

EDIT: Also, if you wish the skill to be totally "consumed", you can make the player "Unlearn" it.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,251
Reaction score
460
First Language
English
Primarily Uses
RMVXA
Yanfly's Limited Skill Uses plugin
Don't think this is for VX Ace?
x number available for use,
There is a script that does this. I'll have to look as I can't remember what it is.
Looks like you already have it. Let's test play and see how it is supposed to work,

EDIT*

Did some quick testing, it looks like the script is designed to give all skills a limited use and only gets reset when entering a new battle.
Unless this script can be modified then this is not the one for you.
On a side note there is a mod to this script which I have that allows you to specify only certain skills to have charges.
Code:
class RPG::Skill
  def charges
    if @charges.nil?
      @charges = @note.include?("<charges>")
    end
    @charges
  end
end
 
Last edited:

Allusion

♕ The Girl Who Lived (for chocolate) ♛
Veteran
Joined
Aug 21, 2013
Messages
163
Reaction score
169
First Language
English
Primarily Uses
@Roninator2 Hi, thank you so much! I agree, Fomar's charge isn't a perfect fit, I mostly added it in case it helped with scripting something like it. (I can fiddle my way around scripts, but I'm not proficient with RGSS3 in the least, so I don't know what does or doesn't help. ^~^; )

It also clashes with my current script-list set-up, and since it's a fairly sensitive list (moving 1 up or down tends to break another <_<; but as I have it, everything works fine.) I didn't want to keep Fomar's. It hasn't been updated since 2012, so it could be too outdated for RM's current version, or it could simply be conflicting with something else.

This idea, (consumable skills) doesn't seem to have been done before, and so I'm sure it would need a new script.

@mathmaster74 I'm using Ace, sadly! QAQ I wish I could use MV, but it lags too much on my laptop. (Mostly in battles or with weather effects) so I'm having to make things with the older generation. Thank you, though!
 

mathmaster74

just...John
Veteran
Joined
Jun 12, 2016
Messages
285
Reaction score
192
First Language
English
Primarily Uses
RMMV
@Allusion You're welcome. Sorry. I started into RPG Maker with MV so I often forget any other versions existed over the 16 or so years prior to it sometimes. :oops: I saw Yanfly and read what you were trying to do and missed the tag and the thread source. I jumped straight in because it popped up in the new thread section and I thought I had a quick answer. :rolleyes: Ah, well...
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
21,867
Reaction score
11,081
First Language
English
Primarily Uses
RMVXA
I've done this using Yanfly's Skill Costs Manager script. There is an option there for custom costs and I used that to limit uses until there is a rest at an inn.
https://yanflychannel.wordpress.com/rmvxa/gameplay-scripts/skill-cost-manager/

EDIT
You might find this thread helpful. It is the one where I discussed how this might be done. You will also see in the opening post reference to another script which might be of use.

EDIT 2
Depending on exactly what you want, you might not even need a script.
Let us suppose that you have a skill which lasts 3 uses and then goes away until you interact with something (local priest, skill fountain, whatever).

At the point that the skill is given to the actor (via Learn Skill command) switch #n is turned ON.
A variable switch #nn is set to Add 3
All the skill that is in the actor's skill list does is call a Common Event.
Common Event
Conditional check: is switch #n ON?
If yes, then follow below. Else: nothing, because the player won't be able to call this CE.
When the switch is ON:-
Conditional check that Variable ##n is greater than 1.
If yes, Force Action of the actual skill and reduce the variable by one.
Else: Force Action, reduce the variable by one, turn Switch #n OFF, Forget skill, tell the player the skill is exhausted.

How you 'top up' the skill again is up to you. Could be another event like the first one, or whatever method you choose.
 
Last edited:

Allusion

♕ The Girl Who Lived (for chocolate) ♛
Veteran
Joined
Aug 21, 2013
Messages
163
Reaction score
169
First Language
English
Primarily Uses
@Kes Hello! Thank you so much for your help! I did some tinkering and discovered a way to event the skills, indeed! My method is similar to yours heheh. I use a variable (say, 'Fire') and add 3 (or any number) to represent 3 uses.

Then, the spell Fire runs a conditional check when cast, subtracting 1 if there are any uses left. When it's at 1 use, it removes the skill and sets the Fire variable to 0. (This lets the spell play out it's given animation/formulas as well, no force action necessary.)

I hadn't thought to utilize switches, though! That saves so much conditional checking to see if Actor X has skill Y; thank you!

The only missing factor is displaying how many uses are left. I've had to put this into the item's description for now using \v[n], rather than having it beside the MP/TP cost. (Hopefully that won't look tacky to people? (//▽//) )

So I think I can safely say this issue is solved! -^^- Thanks again, everyone! I really appreciate it!
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
21,867
Reaction score
11,081
First Language
English
Primarily Uses
RMVXA
I'm glad that has worked out for you.

When your query is fully resolved, please Report your post and ask for the thread to be closed. Mods might not see an individual post, but they will see a Report. As I'm here, though, I'll do this one now.

[closed]IgnoreMe[/closed]
 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

Here it is in all its leggy glory! I apologize in advance.
Suggestion for the name for the new RM, RPG Maker Re-MV (Re-Mastered Version)
A guide on Furry Potatoes.

I apparently need to send photo ID to Blizzard to change my phone number. I don't even need to do this to change my number with my bank or PayPal

Forum statistics

Threads
98,175
Messages
950,076
Members
129,472
Latest member
Strigoi
Top