adiktuzmiko

Skill Levels v1.05

Feb 26th, 2014
1,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.25 KB | None | 0 0
  1. =begin
  2. ======================================================
  3.  
  4.   Skill Levels v1.05
  5.   by Adiktuzmiko                  
  6.  
  7.   Date Created: 02/27/2014
  8.   Date Last Updated: 04/12/2014
  9.   Requires: N/A
  10.   Difficulty: Easy
  11.  
  12. ======================================================
  13.  Overview
  14. ======================================================
  15.  
  16.  This script allows you to have skill levels. Initial
  17.  and maximum skill level values can be defined per
  18.  actor. Escape code sequences for
  19.  text boxes that support escape codes are given for
  20.  showing skill level,max and exp.
  21.  
  22.  Do note that this script does not provide a default,
  23.  automatic way to increase exp and/or levels. Those
  24.  will be provided as Add-Ons. Script calls to do those
  25.  are built-in
  26.  
  27.  Also, how levels modify your abilities are up to you.
  28.  For simple things like increased damage, you can use
  29.  the damage formula for that.
  30.  
  31. ======================================================
  32.  Usage
  33. ======================================================
  34.  
  35.  Put this script into your scripts editor, probably
  36.  below any other script that might modify Game_Actor
  37.  and/or Game_Enemy and Game_Battler. Next thing to do
  38.  is to tag your actors.
  39.  
  40.  Remember that these settings are per actor
  41.  
  42.  <SKILL LEVEL: ID,VALUE> = Sets initial level of
  43.  skill denoted by ID to VALUE
  44.  
  45.  <SKILL MAX: ID,VALUE> = Sets the maximum level of
  46.  skill denoted by ID to VALUE
  47.  
  48.  <SKILL EXTENSION: ID>VALUE<END SKILL EXTENSION> = Allows you to run ruby lines
  49.  when the skill denoted by ID levels. VALUE accepts multilines
  50.  
  51.  <SKILL EXTENSION_A>VALUE<END SKILL EXTENSION_A> = Allows you to run ruby lines
  52.  when any skill levels. VALUE accepts multilines
  53.  
  54.  #This is for the skill  
  55.    
  56.  <SKILL PATH>FORMULA<END SKILL PATH> = The formula used to determine
  57.  how much EXP is needed per level. Supports multiple
  58.  lines.  
  59.    
  60.  Script calls:
  61.  
  62.  To modify the skill level for an actor
  63.  $game_actors[id].mod_skill_level(id,type,value)
  64.  
  65.  To modify the skill max level for an actor
  66.  $game_actors[id].mod_skill_max(id,type,value)
  67.  
  68.  To modify the skill exp for an actor
  69.  $game_actors[id].mod_skill_exp(id,type,value)
  70.    
  71.    type => 'add' for adding
  72.            'mul' for multiplying
  73.    value => value to add or multiply
  74.    
  75.  To obtain the skill level,max and exp for an Actor
  76.  
  77.  $game_actors[id].skill_level(skill_id)
  78.  $game_actors[id].skill_max(skill_id)
  79.  $game_actors[id].skill_exp(skill_id)
  80.  
  81.  You can also use those methods on battler objects,
  82.  so like if you want a skill to deal damage depending
  83.  on level, you can do this in the damage formula:
  84.  
  85.  10*a.skill_level(skill_id)
  86.  
  87.  Escape Character Codes:
  88.  
  89.  \SL[actor_id,skill_id] = Shows skill level for that actor
  90.  \SM[actor_id,skill_id] = Shows skill max for that actor
  91.  \SE[actor_id,skill_id] = Shows skill exp for that actor
  92.  
  93. ======================================================
  94.  Compatibility
  95. ======================================================
  96.  
  97.  Aliases Game_Actor/Enemy's initialize, and
  98.  Window Base's convert_escape_characters
  99.  
  100. ======================================================
  101.  Terms and Conditions
  102. ======================================================
  103.  
  104.  View it here: http://lescripts.wordpress.com/terms-and-conditions/
  105.  
  106. ======================================================
  107. =end
  108.  
  109. #======================================================
  110. #  Do not edit below this line
  111. #======================================================
  112.  
  113. module ADIK
  114.   module SKILL_LEVEL
  115.     TAG = /<SKILL LEVEL: (\d+),(\d+)>/i
  116.     TAG_MAX = /<SKILL MAX: (\d+),(\d+)>/i
  117.       EXT = /<SKILL EXTENSION: (\d+)>/i
  118.     EXT_END = /<END SKILL EXTENSION>/i
  119.       EXT_A = /<SKILL EXTENSION_A>(.*)<END SKILL EXTENSION_A>/im
  120.     FORMULA = /<SKILL PATH>(.*)<END SKILL PATH>/im
  121.   end
  122. end
  123.  
  124. class Game_Battler
  125.  
  126.   attr_accessor :skill_levels
  127.   attr_accessor :skill_exps
  128.  
  129.   #alias initialize_skill_levels_adik initialize
  130.   #def initialize
  131.     #initialize_skill_levels_adik
  132.    
  133.   #end
  134.  
  135.   def load_skill_level_notetag
  136.     @skill_levels = [1]*$data_skills.size
  137.     @skill_exps = [0]*$data_skills.size
  138.     @skill_max = [1]*$data_skills.size
  139.       @skill_ext = [""]*$data_skills.size
  140.     extension = false
  141.     id = 0
  142.     x = self.actor? ? self.actor : self.enemy  
  143.     x.note.split(/[\r\n]+/).each { |line|
  144.       case line
  145.       when ADIK::SKILL_LEVEL::TAG
  146.         @skill_levels[$1.to_i] = $2.to_i
  147.       when ADIK::SKILL_LEVEL::TAG_MAX
  148.         @skill_max[$1.to_i] = $2.to_i
  149.       when ADIK::SKILL_LEVEL::EXT
  150.         extension = true
  151.         id = $1.to_i
  152.         next
  153.       when ADIK::SKILL_LEVEL::EXT_END
  154.         extension = false
  155.         id = 0
  156.         next
  157.       end
  158.       if extension
  159.         @skill_ext[id] += line.to_s
  160.       end
  161.     }
  162.   end
  163.  
  164.   def skill_level(id)
  165.     if @skill_levels[id] > @skill_max[id]
  166.       @skill_levels[id] = @skill_max[id]
  167.     end
  168.     return @skill_levels[id]
  169.   end
  170.  
  171.   def skill_max(id)
  172.     return @skill_max[id]
  173.   end
  174.  
  175.   def skill_exp(id)
  176.     return @skill_exps[id]
  177.   end
  178.  
  179.   def mod_skill_level(id,type,value)
  180.     case type
  181.     when 'add'
  182.       @skill_levels[id] += value
  183.     when 'mul'
  184.       @skill_levels[id] *= value
  185.     end
  186.     refresh_skill_adik_level
  187.   end
  188.  
  189.   def mod_skill_max(id,type,value)
  190.     case type
  191.     when 'add'
  192.       @skill_max[id] += value
  193.     when 'mul'
  194.       @skill_max[id] *= value
  195.     end
  196.     refresh_skill_adik_level
  197.   end
  198.  
  199.   def mod_skill_exp(id,type,value)
  200.     case type
  201.     when 'add'
  202.       @skill_exps[id] += value
  203.     when 'mul'
  204.       @skill_exps[id] *= value
  205.     end
  206.     refresh_skill_level(id)
  207.     refresh_skill_adik_level(id)
  208.   end
  209.  
  210.   def refresh_skill_adik_level(id)
  211.     if @skill_levels[id] > @skill_max[id]
  212.       @skill_levels[id] = @skill_max[id]
  213.     end
  214.     skill_level_extension(id)
  215.   end
  216.  
  217.   def skill_level_extension(id)
  218.     eval(@skill_ext[id])
  219.     x = self.actor? ? self.actor : self.enemy
  220.     if x.note =~ ADIK::SKILL_LEVEL::EXT_A
  221.       eval($1.to_s)
  222.     else
  223.       return
  224.     end
  225.   end
  226.  
  227.   def refresh_skill_level(id)
  228.     if $data_skills[id].note =~ ADIK::SKILL_LEVEL::FORMULA
  229.       formula = $1.to_s
  230.     else
  231.       return
  232.     end
  233.     while true
  234.       lvl = @skill_levels[id]
  235.         if lvl >= @skill_max[id]
  236.           break
  237.         end
  238.       req = eval(formula)
  239.       if @skill_exps[id] >= req
  240.         @skill_levels[id] += 1
  241.         @skill_exps[id] -= req
  242.       else
  243.         break
  244.       end
  245.     end
  246.   end
  247.  
  248. end
  249.  
  250. class Game_Actor
  251.   alias initialize_skill_levels_adikx initialize
  252.   def initialize(actor_id)
  253.     initialize_skill_levels_adikx(actor_id)
  254.     load_skill_level_notetag
  255.   end
  256. end
  257.  
  258. class Game_Enemy
  259.   alias initialize_skill_levels_adikx initialize
  260.   def initialize(index,enemy_id)
  261.     initialize_skill_levels_adikx(index,enemy_id)
  262.     load_skill_level_notetag
  263.   end
  264. end
  265.  
  266. class Window_Base
  267.   alias escape_character_skill_levels convert_escape_characters
  268.   def convert_escape_characters(text)
  269.     result = escape_character_skill_levels(text)
  270.     result.gsub!(/\eSL\[(\d+)\,(\d+)\]/i) { $game_actors[$1.to_i].skill_level($2.to_i) }
  271.     result.gsub!(/\eSM\[(\d+)\,(\d+)\]/i) { $game_actors[$1.to_i].skill_max($2.to_i) }
  272.     result.gsub!(/\eSE\[(\d+)\,(\d+)\]/i) { $game_actors[$1.to_i].skill_exp($2.to_i) }
  273.     result
  274.   end
  275. end
Advertisement
Add Comment
Please, Sign In to add comment