Advertisement
roninator2

NASTY Extra Stats mod

Dec 5th, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.82 KB | None | 0 0
  1. #===============================================================================
  2. #   N.A.S.T.Y. Extra Stats
  3. #   Nelderson's Awesome Scripts To You
  4. # By: Nelderson
  5. # Made On: 12/19/2011
  6. # Last Updated : 3/27/2012
  7. #===============================================================================
  8. # Update History:
  9. # - Version 1.1 - Cleaned up some sheep, and added enemies xstats for Enemies!
  10. # - Version 1.0 - Initial release, made for the sheep of it  :p
  11. #===============================================================================
  12. # *Notes:
  13. # - This script can be used to make all sorts of stats that can derive from
  14. # an actor's level, and base stats.
  15. #
  16. # - This thing can be a pain to set up, but once it's done, it can be a very
  17. # powerful way to include new stats into your game!
  18. #
  19. # - Made a quick edit to the status screen to show up to 6 stats!
  20. #
  21. # *Usage
  22. #
  23. # -First is the STATS section. This is an array that holds all the new
  24. # stats that everything else gets info from.
  25. #
  26. # - Next fill out the Default Level formula(Use Example Below as a guide)
  27. # *ANYTHING that an actor has, you can base it off of (Except other XSTATS!)
  28. #   (level, hp, mp, atk, spi, agi, maxhp, etc.)
  29. #
  30. # -You can use the ACTOR and ENEMY NOTETAGS to customize
  31. # the formulas for each actor.
  32. #
  33. # Examples:
  34. # Place the following in an actor's notebox(You must make one for each stat):
  35. #   <xstat>
  36. #   :str => '(level/3.5) + 16',
  37. #   :con => '(level/5.6) + 12',
  38. #   :dex => '(level/5.25) + 15 + agi',
  39. #   :int => '(level/10.5) + 10',
  40. #   :wis => '(level/10.5) + 10',
  41. #   :cha => '(level/10.5) + 10',
  42. #   <xstat_end>
  43. #
  44. # Or you can place this in an actor's/enemy's notebox
  45. #   <xstat>
  46. #   :str => 15,
  47. #   :con => 14,
  48. #   :dex => 13,
  49. #   :int => 12,
  50. #   :wis => 11,
  51. #   :cha => 0,
  52. #   <xstat_end>
  53. #
  54. # - This script also uses notetags for weapons and armors to increase xstats
  55. # if you want. Just place in a notebox:
  56. #
  57. #   <weapon_xstat: STAT x> , where STAT is th name of the new stat
  58. #
  59. #   Ex. <weapon_xstat: str 5> , would raise the actor's str +5
  60. #
  61. # *For Scripters
  62. #
  63. # -If you want to access the stats, just use:
  64. #   actor.xstat.STAT - Where STAT is the name of the new stat
  65. #  
  66. #   Ex. $game_actors[1].xstat.str , will return actor 1's str
  67. #
  68. #===============================================================================
  69. # Credits:
  70. # -Nelderson and Zetu
  71. # Original Script was made by Zetu, and I spiced the sheep out of it!
  72. #
  73. # Multiple rows addon by Roninator2 with guidance from Night_Runner
  74. #
  75. # Added increasing stats
  76. # Script Calls:
  77. # change_xstat(actor_id, stat, value) # Alter the specified stat by the specifed
  78. # value. Can be either positive or negative.
  79. #   e.g. change_xstat(1, :str, 10)
  80. #===============================================================================
  81.  
  82. module Z26
  83.  
  84.   STATS = [:str,:con,:dex,:int,:wis,:cha,:spd,:div,:hth]
  85.  
  86.   #Default xstat formulas for ACTORS
  87.   DEFAULT_LEVEL_FORMULA =
  88.   {
  89.   :str => '(level/3.5) + 16 + atk',
  90.   :con => '(level/5.6) + 12',
  91.   :dex => '(level/5.25) + 15 + agi',
  92.   :int => '(level/10.5) + 10',
  93.   :wis => '(level/10.5) + 10',
  94.   :cha => '(level/10.5) + 10',
  95.   :spd => '(level/10.5) + 10',
  96.   :div => '(level/10.5) + 10',
  97.   :hth => '(level/10.5) + 10',
  98.   }
  99.  
  100.   #Default xstat formulas for ENEMIES  
  101.   DEFAULT_FOR_ENEMIES =
  102.   {
  103.   :str => 0,
  104.   :con => 0,
  105.   :dex => 0,
  106.   :int => 0,
  107.   :wis => 0,
  108.   :cha => 0,
  109.   }
  110.  
  111.   def self.actor_level_formulas(actor_id)
  112.     jhh = ""
  113.     strin = $data_actors[actor_id].get_start_end_cache
  114.     strin.each do |i|
  115.     jhh += i
  116.     end
  117.     return DEFAULT_LEVEL_FORMULA if strin == "" or strin == []
  118.     return eval("{#{jhh}}")
  119.   end
  120.  
  121.   def self.enemy_stats(enemy_id)
  122.     jhh = ""
  123.     strin = $data_enemies[enemy_id].get_start_end_cache
  124.     strin.each do |i|
  125.     jhh += i
  126.     end
  127.     return DEFAULT_FOR_ENEMIES if strin == "" or strin == []
  128.     return eval("{#{jhh}}")
  129.   end
  130.  
  131. #=============================================================================
  132.   SYMBOLS = []
  133.   for stat in STATS
  134.     SYMBOLS.push(stat)
  135.   end
  136.   Xstats = Struct.new(*SYMBOLS)
  137. end
  138.  
  139. ##############################################################
  140.  
  141. class Game_Enemy < Game_Battler
  142.   attr_accessor :xstat
  143.  
  144.   alias z26_enemy_set initialize unless $@
  145.   def initialize(*args)
  146.     z26_enemy_set(*args)
  147.     @xstat = Z26::Xstats.new(*([0]*Z26::STATS.size))
  148.     for stat in Z26::STATS
  149.     z26variate_stats(stat)
  150.     end
  151.   end
  152.  
  153.   def z26variate_stats(stat)
  154.     return if Z26.enemy_stats(@enemy_id)[stat].nil?
  155.     if Z26.enemy_stats(@enemy_id)[stat].is_a?(String)
  156.       set_in = eval(Z26.enemy_stats(@enemy_id)[stat]).to_i
  157.       eval("@xstat.#{stat} += #{set_in}")
  158.     else
  159.       set_in = Z26.enemy_stats(@enemy_id)[stat]
  160.       @xstat[stat] += set_in
  161.     end
  162.     end
  163.   end
  164.  
  165. ##############################################################
  166.  
  167. class Game_Actor < Game_Battler
  168.   attr_accessor :xstat
  169.  
  170.   alias z26_s setup unless $@
  171.   def setup(actor_id)
  172.     z26_s(actor_id)
  173.     @xstat = Z26::Xstats.new(*([0]*Z26::STATS.size))
  174.     for item in equips.compact
  175.       z26variate_equip(item)
  176.     end
  177.     for stat in Z26::STATS
  178.       z26variate_stats(stat, @level)
  179.     end
  180.   end
  181.  
  182.   alias z26_change_equip change_equip
  183.   def change_equip(equip_type, item, test = false)
  184.     last_item = equips[equip_type]
  185.     z26_change_equip(equip_type, item)
  186.     z26variate_equip(item)
  187.     z26variate_equip(last_item, false)
  188.   end
  189.  
  190. #=====================#
  191. ##EDITED BY NELDERSON##
  192. #=====================#
  193.   def z26variate_equip(item, adding = true)
  194.     return if item.nil?
  195.     for line in item.note.split(/[\r\n]+/).each{ |a|
  196.     case a
  197.     when /<weapon_xstat:[ ](.*)[ ](\d+)>/i
  198.     if Z26::STATS.include?(eval(":" + $1))
  199.       if adding
  200.         eval("@xstat.#{$1} += #{$2}")
  201.       else
  202.         eval("@xstat.#{$1} -= #{$2}")
  203.       end
  204.     end
  205.     end
  206.     }
  207.     end
  208.   end
  209.  
  210.   def z26variate_stats(stat, level, adding = true)
  211.     return if Z26.actor_level_formulas(@actor_id)[stat].nil?
  212.     if Z26.actor_level_formulas(@actor_id)[stat].is_a?(String)
  213.       amount = eval(Z26.actor_level_formulas(@actor_id)[stat]).to_i
  214.     else
  215.       amount = Z26.actor_level_formulas(@actor_id)[stat]
  216.     end
  217.     if adding
  218.       eval("@xstat.#{stat} += #{amount}")
  219.     else
  220.       eval("@xstat.#{stat} -= #{amount}")
  221.     end
  222.   end
  223.  
  224.   alias z26level_up level_up unless $@
  225.   def level_up
  226.     for stat in Z26::STATS
  227.       z26variate_stats(stat, @level, false)
  228.     end
  229.     z26level_up
  230.     for stat in Z26::STATS
  231.       z26variate_stats(stat, @level)
  232.     end
  233.   end
  234. end
  235.  
  236. ##############################################################
  237.  
  238. class Game_Interpreter
  239.   #--------------------------------------------------------------------------
  240.   # * Modify an Extra Stat
  241.   #--------------------------------------------------------------------------
  242.   def change_xstat(id, stat, value)
  243.     $game_actors[id].xstat[stat] += value
  244.   end
  245. end
  246.  
  247. ##############################################################
  248.  
  249. class Window_Status < Window_Selectable
  250.  
  251.   def draw_block3(y)
  252.     draw_parameters(0, y)
  253.     draw_equipments(self.contents.width-172, y)
  254.     draw_xstat_parameters(stat_widths / 0.9, y)
  255.   end
  256.  
  257.   def draw_xstat_parameters(x, y)
  258.     dy = 0
  259.     @actor.xstat.size.times {|i|
  260.     draw_actor_xstat_param(@actor, x, y + line_height * i, i) #}
  261.     dy += line_height
  262.     if  dy > 120
  263.        dy = 0
  264.        y -= line_height * (i + 1)
  265.       x += stat_widths / 0.9
  266.     end
  267.     }
  268.   end
  269.   #--------------------------------------------------------------------------
  270.   # * Draw Parameters
  271.   #--------------------------------------------------------------------------
  272.   def draw_actor_param(actor, x, y, param_id)
  273.     change_color(system_color)
  274.     draw_text(x, y, stat_widths, line_height, Vocab::param(param_id))
  275.     change_color(normal_color)
  276.     draw_text(x + stat_widths-36, y, 36, line_height, actor.param(param_id), 2)
  277.   end
  278.  
  279. end
  280.  
  281. ##############################################################
  282.  
  283. class Window_Base < Window
  284.  
  285.   def draw_actor_xstat_param(actor, x, y, param_id)
  286.     id = Z26::STATS[param_id]
  287.     change_color(system_color)
  288.     draw_text(x, y, 120, line_height, id.capitalize)
  289.     change_color(normal_color)
  290.     draw_text(x + stat_widths-36, y, 36, line_height, eval("actor.xstat.#{id}"), 2)  
  291.   end
  292.  
  293.   def stat_widths
  294.     wind_wid = self.contents.width
  295.     xstat_cols = (Z26::STATS.length + 5) / 6
  296.     return (((wind_wid - 172) / (xstat_cols + 1))*0.9).to_i
  297.   end
  298.  
  299. end
  300.  
  301. ##############################################################
  302.  
  303. class RPG::BaseItem
  304.   def get_start_end_cache
  305.     record = false
  306.     temp = []
  307.     self.note.split(/[\r\n]+/).each do |line|
  308.     if line =~ /<xstat>/i
  309.       record = true
  310.     elsif line =~ /<xstat_end>/i
  311.       record = false
  312.     end
  313.     if record
  314.       temp << line
  315.     end
  316.     end
  317.     return nil if temp == ""
  318.     temp.delete_at(0)
  319.     temp
  320.   end
  321. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement