adiktuzmiko

Skill PP Cost v1.01

Jan 1st, 2014
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.40 KB | None | 0 0
  1. =begin
  2.  ==============================================================================
  3.  
  4.  Skill PP Cost v1.01
  5.  by AdiktuzMiko
  6.  --- Date Created: 01/03/2014
  7.  --- Last Date Updated: 01/03/2014
  8.  --- Level: Easy
  9.  
  10.  ==============================================================================
  11.  Overview
  12.  ==============================================================================
  13.  
  14.  So this script provides to make skills that can only be used a number of times
  15.  until you reset it. You can set each skills "PP" per actor, meaning one actor
  16.  can have a different PP for 1 skill than another actor. The PP can also be
  17.  modified in-game via script calls
  18.  
  19.  Also, it's set-up in a way that you can choose if a skill will have PP or not.
  20.  If PP for a skill is not defined for that actor, it will use the default costs
  21.  instead (MP/TP or probably if you have a custom cost manager, the custom cost)
  22.  So you can do like only a certain actor uses PP while all others uses the normal
  23.  method.
  24.  
  25.  ==============================================================================
  26.  Set-Up
  27.  ==============================================================================
  28.  
  29.  Just put this script into a blank slot above main but below materials and
  30.  go to the module PP_SET_UP below to set up your actors
  31.  
  32.  Note that when you initialize an actor, it will reload the default PP values
  33.  for that actor.
  34.    
  35.  Set the color of normal and critical PP using the module. You can also set
  36.  up the critical rate
  37.  
  38.  ==============================================================================
  39.  Script Calls
  40.  ==============================================================================
  41.  
  42.  Legend:
  43.  
  44.  id => actor id
  45.  skill_id => skill id
  46.  initial => initial/current PP
  47.  max => maximum PP
  48.  value => value to add/multiply
  49.  
  50.  to get the current PP of a skill of an actor:
  51.  
  52.  $game_actors[id].pp(skill_id)
  53.  
  54.  to get the max PP of a skill of an actor:
  55.  
  56.  $game_actors[id].pp_max(skill_id)
  57.  
  58.  go reset PP of a skill on an actor:
  59.  
  60.  $game_actors[id].reset_pp(skill_id)
  61.  
  62.  to reset PP of all skills of an actor:
  63.  
  64.  $game_actors[id].reset_pp_all
  65.  
  66.  to change the PP of the skill of an actor:
  67.  
  68.  $game_actors[id].set_pp(skill_id,initial,max)
  69.  
  70.  to know if a skill has a PP value set-up:
  71.  
  72.  $game_actors[id].has_pp(skill_id)
  73.  
  74.  -Wrapper Functions-
  75.  
  76.  to add to the current PP of a skill of an actor
  77.  
  78.  $game_actors[id].add_current_pp(skill_id,value)
  79.  
  80.  to add value to max PP of a skill of an actor:
  81.  
  82.  $game_actors[id].add_max_pp(skill_id,value)
  83.  
  84.  to multiply the current PP of a skill of an actor:
  85.  
  86.  $game_actors[id].mul_current_pp(skill_id,value)
  87.  
  88.  to multiply the max PP of a skill of an actor:
  89.  
  90.  $game_actors[id].mul_max_pp(skill_id,value)
  91.  
  92.  to add value to current PP for all skills of an actor:
  93.  
  94.  $game_actors[id].add_current_pp_all(value)
  95.  
  96.  to add value to max PP for all skills of an actor:
  97.  
  98.  $game_actors[id].add_max_pp_all(value)
  99.  
  100.  to multiply the current PP for all skills of an actor:
  101.  
  102.  $game_actors[id].mul_current_pp_all(value)
  103.  
  104.  to multiply the max PP for all skills of an actor:
  105.  
  106.  $game_actors[id].mul_max_pp_all(value)
  107.  
  108.  to apply the above eight functions to party:
  109.  
  110.  just remove the $game_actors[id]. part
  111.  
  112.  to reset PP of all party members:
  113.  
  114.  party_reset_pp
  115.  
  116.  ==============================================================================
  117.  Compatibility
  118.  ==============================================================================
  119.  
  120.  This script aliases Game_BattlerBase.usable? method, Game_Actor.use_item
  121.  method and Window_SkillList.draw_skill_cost method
  122.  
  123.  So put it below any script that overwrites those
  124.  
  125.  ==============================================================================
  126.  Terms and Conditions
  127.  ==============================================================================
  128.  
  129.  View it here: http://lescripts.wordpress.com/terms-and-conditions/
  130.  
  131.  ==============================================================================
  132. =end
  133.  
  134. module PP_SET_UP
  135.   PP_DEFAULT = {
  136.    
  137.     #Actor ID
  138.     1 => {
  139.       #Skill ID => [Initial PP, Max PP],
  140.       26 => [1,10],
  141.       2 => [30,30],
  142.       3 => [22,22],
  143.     },
  144.     2 => {
  145.       #Skill ID => [Initial PP, Max PP],
  146.       1 => [5,5],
  147.       2 => [30,30],
  148.       3 => [22,22],
  149.     },
  150.     #And so on
  151.  
  152.   }
  153.   #Show max PP?
  154.   SHOW_MAX = true
  155.   #Color.new(R,G,B)
  156.   #Color of normal PP
  157.   NORMAL_PP = Color.new(0,255,200)
  158.   #Color of critical PP
  159.   CRIT_PP = Color.new(255,255,0)
  160.   #Rate/Percent of PP before it's tagged as critical
  161.   CRIT_RATE = 0.5
  162.  
  163. end
  164.  
  165. #Do not edit below this line
  166.  
  167. class Game_Actor
  168.  
  169.   attr_accessor :skills_pp
  170.  
  171.   alias initialize_skill_pp initialize
  172.   def initialize(actor_id)
  173.     initialize_skill_pp(actor_id)
  174.     @skills_pp = PP_SET_UP::PP_DEFAULT[actor_id].nil? ? {} : PP_SET_UP::PP_DEFAULT[actor_id]
  175.   end
  176.  
  177.   def has_pp(id)
  178.     return false if @skills_pp.keys.empty?
  179.     return @skills_pp.keys.include?(id)
  180.   end
  181.  
  182.   def pp(id)
  183.     return @skills_pp[id][0]
  184.   end
  185.  
  186.   def pp_max(id)
  187.     return @skills_pp[id][1]
  188.   end
  189.  
  190.   def use_pp(id)
  191.     @skills_pp[id][0] -= 1
  192.   end
  193.  
  194.   def reset_pp(id)
  195.     @skills_pp[id][0] = @skills_pp[id][1]
  196.   end
  197.  
  198.   def reset_pp_all
  199.     @skills_pp.each_value  {|skill| skill[0] = skill[1]}
  200.   end
  201.  
  202.   def add_current_pp(id,value)
  203.     @skills_pp[id][0] += value  
  204.   end
  205.  
  206.   def add_max_pp(id,value)
  207.     @skills_pp[id][1] += value    
  208.   end
  209.  
  210.   def mul_current_pp(id,value)
  211.     @skills_pp[id][0] *= value
  212.   end
  213.  
  214.   def mul_max_pp(id,value)
  215.     @skills_pp[id][1] *= value
  216.   end
  217.  
  218.   def add_current_pp_all(value)
  219.     @skills_pp.each_value  {|skill| skill[0] += value}
  220.   end
  221.  
  222.   def add_max_pp_all(value)
  223.     @skills_pp.each_value  {|skill| skill[1] += value}
  224.   end
  225.  
  226.   def mul_current_pp_all(value)
  227.     @skills_pp.each_value  {|skill| skill[0] *= value}
  228.   end
  229.  
  230.   def mul_max_pp_all(value)
  231.     @skills_pp.each_value  {|skill| skill[1] *= value}
  232.   end
  233.  
  234.   def set_pp(id,init,max)
  235.     @skills_pp[id][0] = init
  236.     @skills_pp[id][1] = max
  237.   end
  238.  
  239.   def get_pp_count(id)
  240.     return self.pp(id).to_s if !PP_SET_UP::SHOW_MAX
  241.     return self.pp(id).to_s + " / " + self.pp_max(id).to_s
  242.   end
  243.  
  244.   alias use_item_adik_pp use_item
  245.   def use_item(item)
  246.     if (item.is_a?(RPG::Skill) and self.has_pp(item.id))
  247.       self.use_pp(item.id)
  248.       item.effects.each {|effect| item_global_effect_apply(effect) }
  249.     else
  250.       use_item_adik_pp(item)
  251.     end
  252.   end
  253. end
  254.  
  255. class Game_BattlerBase
  256.   alias adik_pp_usable? usable?
  257.   def usable?(item)
  258.     begin
  259.       ex = (usable_item_conditions_met?(item) &&
  260.       skill_wtype_ok?(item) && !skill_sealed?(item.id) &&
  261.       !skill_type_sealed?(item.stype_id))
  262.       return (self.pp(item.id) > 0 and ex)
  263.     rescue
  264.       return adik_pp_usable?(item)
  265.     end
  266.   end
  267. end
  268.  
  269. class Window_SkillList
  270.  
  271.   def pp_color(cur,max,enabled)
  272.     x = cur.to_f/max
  273.     if x <= PP_SET_UP::CRIT_RATE
  274.       contents.font.color.set(PP_SET_UP::CRIT_PP)
  275.     else
  276.       contents.font.color.set(PP_SET_UP::NORMAL_PP)
  277.     end
  278.     contents.font.color.alpha = translucent_alpha unless enabled
  279.   end
  280.  
  281.   #alias method draw_skill_cost
  282.   alias draw_skill_cost_adik_pp draw_skill_cost
  283.   def draw_skill_cost(rect, skill)
  284.     if @actor.has_pp(skill.id)
  285.       pp_color(@actor.pp(skill.id),@actor.pp_max(skill.id),enable?(skill))
  286.       draw_text(rect, @actor.get_pp_count(skill.id), 2)
  287.     else
  288.       draw_skill_cost_adik_pp(rect, skill)
  289.     end
  290.   end
  291. end
  292.  
  293. class Game_Interpreter
  294.  
  295.   def party_reset_pp
  296.     $game_party.all_members.each { |act| act.reset_pp_all }
  297.   end
  298.  
  299.   def add_current_pp_all(value)
  300.     $game_party.all_members.each { |act| act.add_current_pp_all(value) }
  301.   end
  302.  
  303.   def add_max_pp_all(value)
  304.     $game_party.all_members.each { |act| act.add_max_pp_all(value) }
  305.   end
  306.  
  307.   def mul_current_pp_all(value)
  308.     $game_party.all_members.each { |act| act.mul_current_pp_all(value) }
  309.   end
  310.  
  311.   def mul_max_pp_all(value)
  312.     $game_party.all_members.each { |act| act.mul_max_pp_all(value) }
  313.   end
  314.  
  315.   def add_current_pp(id,value)
  316.     $game_party.all_members.each { |act| act.add_current_pp(id,value) }
  317.   end
  318.  
  319.   def add_max_pp(id,value)
  320.     $game_party.all_members.each { |act| act.add_max_pp(id,value) }
  321.   end
  322.  
  323.   def mul_current_pp(id,value)
  324.     $game_party.all_members.each { |act| act.mul_current_pp(id,value) }
  325.   end
  326.  
  327.   def mul_max_pp(id,value)
  328.     $game_party.all_members.each { |act| act.mul_max_pp(id,value) }
  329.   end
  330. end
Advertisement
Add Comment
Please, Sign In to add comment