Jump to content

Recommended Posts

Magic Units

Author: Tsukihime

 

iYSum.jpg

 

Overview

 

This script converts skill types to "units". In the default engine, skill use consumes MP or TP. A "unit of magic" is treated like an item; in order to use the magic, you must have one, and each time you use it, you consume as many units as required.

 

Features

  • Specify skill types that should be treated as units
  • Consume units of skill rather than MP or TP
  • Gain or lose units through script calls
  • Anyone can use the skill as long as they have units

Usage

You can determine how many units of each skill you can have using

 

<max-units: n>

 

For some integer n

 

You can also determine which skill types should be treated as

units by specifying it in the configuration.

 

You can add/remove magic units by using script calls

 

add_units(skill_id, amount, scope_id, scope)
lose_units(skill_id, amount, scope_id, scope)

 

scope is either "actor" or "party".

 

If the scope is "party", then the scope_id is the number representing

the position of an actor in your party. 1 will be the first person,

2 will be the second person, etc

 

If the scope is actor, then the scope_id is the actor_id.

By default, the scope is "party"

 

Download

 

Script: http://db.tt/47ySZhca

Demo: http://db.tt/5UCTLMZH (copy rgss30x.dll to the System folder to run it)

Edited by Tsukihime

Share this post


Link to post
Share on other sites

I've added a demo. Copy rgss30x.dll to the system folder since I didn't include it to make it small (most people should have it)

 

I didn't touch the database.

In the script, I specified skill type 2 (magic) to be treated as units.

 

There are 4 NPC's. Two on the left demonstrate adding/removing units. The one on the top adds magic to a specific actor in the game. The slime is just for using magic in battle.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

Nice script, Tsuki! I'm currently using it now.

 

Is there a way to do the following:

 

1) Have an Actor or Class increase the maximum number of units for their alloted skills as they level up?

2) Have the Skill display "0" uses left when they run out (instead of the Skill disappearing from the menu altogether)?

3) Restore units by resting at an inn?

Share this post


Link to post
Share on other sites

ok well ive got it so that once drawn the skill remains even when at 0 (shows 0) but i cant get it to show when the actor levels up and is supposed to learn the skill

is there a way to add this whit a pre determined amount (wouldnt say full since by default thats 99 which is a bit unfair to start with)

 

EDIT

 

ok so now ive got it so that when you level up you'll learn the skill and gain 10 units of that skill also when reduced to 0 the skill remains however the skills can still be drawn by actors who do not learn the skill so kindda makes it pointless except for the free skill points

Edited by Tammsyn

Share this post


Link to post
Share on other sites

ok sorry for the double post but can we store the amount of units a specific skill has as a variable so that we can can do a sort of exchange system like what you can do in final fantasy 8

Edited by Tammsyn

Share this post


Link to post
Share on other sites

Maybe, but I can't come up with any reasonable way to do it.

You can in theory have arbitrary units of magic on your character so how would you manage that...?

 

I mean, you can always do this:

 

$game_variables[20] = $game_actors[1].get_units(30)

 

Which stores the number of units of magic 30 that your actor has in variable 20.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

What?  I thought I stalked you good enough to know most of your scripts, but this one has escaped my attention for 2 years.  This sounds exactly like something I am doing now using common event checks on every cast of a spell, so using a script to make it more tidy seems like a great idea.

 

I'm going to try this out on my current project and see what happens.

Share this post


Link to post
Share on other sites
Spoiler

=begin
#==============================================================================
 ** Magic Units
 Author: Hime
 Date: May 28, 2012
------------------------------------------------------------------------------
 ** Change log
 May 28
   - initial release
------------------------------------------------------------------------------   
 This script converts skill types to "units".
 In the default engine, skill use consumes MP or TP.
 A "unit of magic" is treated like an item; in order to use
 the magic, you must have one, and each time you use it,
 you consume as many units as required.
 
 You can determine how many units of each skill you can have using
    <max-units: n>
    
 For some integer n
 
 You can also determine which skill types should be treated as 
 units by specifying it in the configuration.
 
 You can add/remove magic units by using script calls
 
    add_units(skill_id, amount, scope_id, scope)
    lose_units(skill_id, amount, scope_id, scope)
    
 scope is either "actor" or "party".
 
 If the scope is "party", then the scope_id is the number representing
 the position of an actor in your party. 1 will be the first person,
 2 will be the second person, etc
 
 If the scope is actor, then the scope_id is the actor_id.
 By default, the scope is "party"
 
#==============================================================================
=end
$imported = {} if $imported.nil?
$imported["Tsuki_MagicUnits"] = true
#==============================================================================
# ** Configuration
#==============================================================================
module Tsuki
  module Magic_Units
    
    # skill types that this script applies to
    Applied_Types = [2]
    
    # default maximum number of units you can have for a skill
    Max_Units = 99
    
    #
    Default_Scope = "party"
#==============================================================================
# ** Rest of the script
#==============================================================================
    # regex
    Max_Unit_Regex = /<max-units:?\s*(\d+)\s*>/i
  end
end

module RPG
  class Skill < UsableItem
    def max_units
      return @max_units unless @max_units.nil?
      return @max_units = load_notetag_max_units
    end
    
    def load_notetag_max_units
      matches = Tsuki::Magic_Units::Max_Unit_Regex.match(self.note)
      return matches ? matches[1].to_i : Tsuki::Magic_Units::Max_Units
    end
  end
end

# stores a battler's skill units
class Game_MagicStore
  
  def initialize
    @units = {}
  end
  
  def all_magic
    @units.keys.collect {|id| $data_skills[id]}
  end
  
  def skill(skill_id)
    $data_skills[skill_id]
  end
    
  def add_unit(skill_id, amount)
    @units[skill_id] = 0 if @units[skill_id].nil?
    @units[skill_id] = [@units[skill_id] + amount, skill(skill_id).max_units].min
  end
  
  def remove_unit(skill_id, amount)
    return if @units[skill_id].nil?
    @units[skill_id] -= amount
    @units.delete(skill_id) if @units[skill_id] <= 0
  end
  
  def get_units(skill_id)
    @units[skill_id] || 0
  end
end

class Game_BattlerBase
  
  alias :th_magic_units_init_bbase :initialize
  def initialize
    th_magic_units_init_bbase
    clear_magic_store
  end
  
  def clear_magic_store
    @magic_store = Game_MagicStore.new
  end
    
  alias :th_magic_units_pay_cost :pay_skill_cost
  def pay_skill_cost(skill)
    magic_unit_type?(skill.id) ? pay_unit_cost(skill) : th_magic_units_pay_cost(skill)
  end
  
  alias :th_magic_units_skill_payable? :skill_cost_payable?
  def skill_cost_payable?(skill)
    magic_unit_type?(skill.id) ? has_magic_units?(skill.id) : th_magic_units_skill_payable?(skill)
  end
  
  # ignore added skills if they're unit types
  alias :th_magic_units_added_skills :added_skills
  def added_skills
    th_magic_units_added_skills.select {|id| !magic_unit_type?(id)}
  end
  
  def pay_unit_cost(skill)
    lose_magic_units(skill.id, magic_unit_cost(skill))
  end
    
  def magic_unit_cost(skill)
    1
  end
  
  def magic_unit_type?(skill_id)
    Tsuki::Magic_Units::Applied_Types.include?($data_skills[skill_id].stype_id)
  end
  
  def has_magic_units?(skill_id)
    @magic_store.get_units(skill_id) > 0
  end
  
  def add_magic_units(skill_id, units)
    @magic_store.add_unit(skill_id, units) if magic_unit_type?(skill_id)
  end 
  
  def lose_magic_units(skill_id, units)
    @magic_store.remove_unit(skill_id, units) if magic_unit_type?(skill_id)
  end
  
  def get_magic_units(skill_id)
    @magic_store.get_units(skill_id) if magic_unit_type?(skill_id)
  end
  
  def get_all_magic
    @magic_store.all_magic
  end
end

class Game_Actor < Game_Battler
  
  alias :th_magic_units_learn_skill :learn_skill
  def learn_skill(skill_id)
    return if magic_unit_type?(skill_id)
    th_magic_units_learn_skill(skill_id)
  end
  
  alias :th_magic_units_skills :skills
  def skills
    th_magic_units_skills.concat(get_all_magic)
  end
end

class Game_Interpreter
  
  def get_actor(scope, scope_id)
    scope == "party" ? $game_party.all_members[scope_id-1] : $game_actors[scope_id]
  end
  
  def add_units(id, amount, scope_id=1, scope=Tsuki::Magic_Units::Default_Scope)
    actor = get_actor(scope.downcase, scope_id)
    return unless actor
    actor.add_magic_units(id, amount)
  end
  
  def lose_units(id, amount, scope_id=1, scope=Tsuki::Magic_Units::Default_Scope)
    actor = get_actor(scope.downcase, scope_id)
    return unless actor
    actor.lose_magic_units(id, amount)
  end
end

#==============================================================================
# ** update skill list window to display units of magic
#==============================================================================
class Window_SkillList < Window_Selectable
  
  def draw_item(index)
    skill = @data[index]
    if skill
      rect = item_rect(index)
      rect.width -= 4
      draw_item_name(skill, rect.x, rect.y, enable?(skill))
      if Tsuki::Magic_Units::Applied_Types.include?(skill.stype_id)
        draw_total_units(rect, skill)
      else
        draw_skill_cost(rect, skill)
      end
    end
  end
  
  def draw_total_units(rect, skill)
    draw_text(rect, @actor.get_magic_units(skill.id), 2)
  end
end

 

 

Edited by roninator2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×