Advertisement
TheSixth

Equipment Parameter Description

Sep 17th, 2016
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.90 KB | None | 0 0
  1. =begin
  2. -----------
  3. - Equipment Parameter Description v1.1
  4. - Made by: Sixth
  5. - Requires: Sixth's Negative Bonus Fix for Vlue's W/A Randomizer
  6. -----------
  7. - Description:
  8. Just a small script to show the basic parameters of the equipment in their
  9. description text. Can be good for lazy people who don't want to type all that
  10. into their description box, or if a custom script can generate random parameters
  11. for your equipment.
  12. The parameters will be displayed next to each other, and they will be separated
  13. and formatted automatically based on your settings in this script.
  14. Parameters with 0 value will be skipped from the display!
  15. -----------
  16. - Message Codes:
  17. To show up the equipment's parameters in their description:
  18.  
  19.   <params>
  20.  
  21. That's it. Just enter this message code, and the magic happens. :D
  22. -----------
  23. To show only the equipment's base parameters without any bonuses from Vlue's
  24. script in their description, use this:
  25.  
  26.   <bparams>
  27.  
  28. This requires Vlue's script!
  29. -----------
  30. To show only the bonus gotten from the randomized parameters, use this:
  31.  
  32.   <bonuses>
  33.  
  34. This requires Vlue's Weapon/Armor Randomization script!
  35. If that script is not installed, this message code will be removed
  36. automatically from your description text!
  37. -----------
  38. - Installation:
  39. Place this script between Materials and Main.
  40. Don't forget to install the required script or you will get display errors!
  41. -----------
  42. - Terms of Usage:
  43. Credit me (Sixth) in your game, pretty please! :P
  44. -----------
  45. =end
  46.  
  47. $imported = {} if $imported.nil?
  48. $imported["SixthStatDescription"] = true
  49.  
  50. module StatDisplay
  51.   #-----------------------------------------------------------------------------
  52.   # Settings:
  53.   #-----------------------------------------------------------------------------
  54.   # Here are what each of these options do:
  55.   #
  56.   # :pos = The format used for displaying positive parameter values.
  57.   #        Expects one %s in the text, and that will be the actual value of
  58.   #        the parameter!
  59.   # :neg = The format used for displaying negative parameter values.
  60.   #        Expects one %s in the text, and that will be the actual value of
  61.   #        the parameter!
  62.   # :params = The format of the displayed parameter text.
  63.   #           Use <value> to display the parameter's value.
  64.   #           Use <name> to display the parameter's name.
  65.   #           You can also add any other text here.
  66.   # :bparams = Same as :params, but this format is for the base parameter
  67.   #            display which requires Vlue's script.
  68.   # :bonus = Same as :params, but this format is for the bonus parameter
  69.   #          display which requires Vlue's script.
  70.   # :ptxt = A static text which will appear before the listed parameter data.
  71.   # :bptxt = A static text which will appear before the listed base parameters.
  72.   # :btxt = A static text which will appear before the listed bonus parameter
  73.   #         data.
  74.   # :separator = The text used to separate the parameters from each other.
  75.   # :end = The text which appears after the final parameter text.
  76.   # :nparam = If you add something here, this text will be displayed in place of
  77.   #           the parameter values if there are no displayable parameter texts
  78.   #           (so, all of the parameter values are 0).
  79.   #           This one will be displayed for the total parameter display.
  80.   #           Set it to "" (so an empty string) and nothing will be shown in the
  81.   #           description if all parameter values are 0 for the equipment!
  82.   # :nbparam = Same as above but this one is for the item's base parameter
  83.   #            display. Requires Vlue's script!
  84.   # :nbonus = Same as above but this one is for the random bonus display from
  85.   #           Vlue's script!
  86.   #
  87.   # Note that in all of these text settings, you can use any message codes
  88.   # you want! You can see I used some color codes in them as well.
  89.   #-----------------------------------------------------------------------------
  90.   Format = {
  91.     :pos => "\ec[3]+%s\ec[0]",
  92.     :neg => "\ec[2]%s\ec[0]",
  93.     :params => "<value> <name>",
  94.     :bparams => "<value> <name>",
  95.     :bonus => "<value> <name>",
  96.     :ptxt => "\ec[17]Stats\ec[0]: ",
  97.     :bptxt => "\ec[18]Base Stats\ec[0]: ",
  98.     :btxt => "\ec[1]Bonuses\ec[0]: ",
  99.     :separator => ", ",
  100.     :end => ".",
  101.     :nparam => "----",
  102.     :nbparam => "----",
  103.     :nbonus => "----",
  104.   }
  105.  
  106.   #-----------------------------------------------------------------------------
  107.   # No more settings, shoo-shoo! :P
  108.   #-----------------------------------------------------------------------------
  109.  
  110.   def self.bonus(item,total,pid)
  111.     case item
  112.     when RPG::Weapon; ori = $data_weapons[item.original_id]
  113.     when RPG::Armor;  ori = $data_armors[item.original_id]
  114.     when RPG::Item;   ori = $data_items[item.original_id]
  115.     end
  116.     diff = total - ori.params[pid]
  117.     return diff
  118.   end
  119.  
  120.   def self.get_params_txt(item)
  121.     return "" if !item.respond_to?("params")
  122.     txt = ""
  123.     item.params.each_with_index do |val,pid|
  124.       next if val == 0
  125.       vtxt = sprintf(StatDisplay::Format[val > 0 ? :pos : :neg],val.to_s)
  126.       dtxt = StatDisplay::Format[:params].clone
  127.       dtxt.gsub!(/<value>/) { vtxt }
  128.       dtxt.gsub!(/<name>/) { Vocab.param(pid) }
  129.       txt += txt.empty? ? dtxt : (StatDisplay::Format[:separator] + dtxt)
  130.     end
  131.     if txt.empty?
  132.       if !StatDisplay::Format[:nparam].empty?
  133.         txt = StatDisplay::Format[:ptxt] + StatDisplay::Format[:nparam]
  134.       end
  135.     else
  136.       txt += StatDisplay::Format[:end]
  137.       txt = StatDisplay::Format[:ptxt] + txt
  138.     end
  139.     return txt
  140.   end
  141.  
  142.   def self.get_bparams_txt(it)
  143.     return "" if !it.respond_to?("params") || !$imported[:Vlue_WARandom]
  144.     case it
  145.     when RPG::Weapon; item = $data_weapons[it.original_id]
  146.     when RPG::Armor;  item = $data_armors[it.original_id]
  147.     when RPG::Item;   item = $data_items[it.original_id]
  148.     end
  149.     txt = ""
  150.     item.params.each_with_index do |val,pid|
  151.       next if val == 0
  152.       vtxt = sprintf(StatDisplay::Format[val > 0 ? :pos : :neg],val.to_s)
  153.       dtxt = StatDisplay::Format[:bparams].clone
  154.       dtxt.gsub!(/<value>/) { vtxt }
  155.       dtxt.gsub!(/<name>/) { Vocab.param(pid) }
  156.       txt += txt.empty? ? dtxt : (StatDisplay::Format[:separator] + dtxt)
  157.     end
  158.     if txt.empty?
  159.       if !StatDisplay::Format[:nbparam].empty?
  160.         txt = StatDisplay::Format[:bptxt] + StatDisplay::Format[:nbparam]
  161.       end
  162.     else
  163.       txt += StatDisplay::Format[:end]
  164.       txt = StatDisplay::Format[:bptxt] + txt
  165.     end
  166.     return txt
  167.   end
  168.  
  169.   def self.get_bonuses_txt(item)
  170.     return "" if !item.respond_to?("params") || !$imported[:Vlue_WARandom]
  171.     txt = ""
  172.     bonuses = {}
  173.     item.params.each_with_index do |val,pid|
  174.       bonuses[pid] = self.bonus(item,val,pid)
  175.     end
  176.     bonuses.each do |pid,val|
  177.       next if val == 0
  178.       vtxt = sprintf(StatDisplay::Format[val > 0 ? :pos : :neg],val.to_s)
  179.       dtxt = StatDisplay::Format[:bonus].clone
  180.       dtxt.gsub!(/<value>/) { vtxt }
  181.       dtxt.gsub!(/<name>/) { Vocab.param(pid) }
  182.       txt += txt.empty? ? dtxt : (StatDisplay::Format[:separator] + dtxt)
  183.     end
  184.     if txt.empty?
  185.       if !StatDisplay::Format[:nbonus].empty?
  186.         txt = StatDisplay::Format[:btxt] + StatDisplay::Format[:nbonus]
  187.       end
  188.     else
  189.       txt += StatDisplay::Format[:end]
  190.       txt = StatDisplay::Format[:btxt] + txt
  191.     end
  192.     return txt
  193.   end
  194.  
  195. end
  196.  
  197. class RPG::BaseItem
  198.    
  199.   def description
  200.     desc = @description.clone
  201.     desc.gsub!(/<bonuses>/i) { StatDisplay.get_bonuses_txt(self) }
  202.     desc.gsub!(/<bparams>/i) { StatDisplay.get_bparams_txt(self) }
  203.     desc.gsub!(/<params>/i) { StatDisplay.get_params_txt(self) }
  204.     return desc
  205.   end
  206.  
  207.   def description=(txt)
  208.     @description = txt
  209.   end
  210.  
  211. end
  212. #==============================================================================
  213. # !!END OF SCRIPT!!
  214. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement