Advertisement
neonblack

Equip Check Snippet

Apr 5th, 2012
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.46 KB | None | 0 0
  1. ###--------------------------------------------------------------------------###
  2. #  Equipment and Skill Check Scriptlet                                         #
  3. #  Version 1.0                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Request by: EvilEagles                                                      #
  7. #  Original code by: NeonBlack                                                 #
  8. #  Modified by:                                                                #
  9. #                                                                              #
  10. #  This work is licensed under the Creative Commons Attribution 3.0 Unported   #
  11. #  License. To view a copy of this license, visit                              #
  12. #  http://creativecommons.org/licenses/by/3.0/.                                #
  13. ###--------------------------------------------------------------------------###
  14.  
  15. ###--------------------------------------------------------------------------###
  16. #      Revision information:                                                   #
  17. #  V1.0 - 4.5.2012 ~ 4.15.2012                                                 #
  18. #   Wrote and debugged main script                                             #
  19. ###--------------------------------------------------------------------------###
  20.  
  21. ###--------------------------------------------------------------------------###
  22. #      Instructions:                                                           #
  23. #  This snippet adds the simple function to evaluate certain properties        #
  24. #  related to the party that were not previously available.  These include     #
  25. #  such things as checking if the party has particular items or weapons or     #
  26. #  checking certain stats.  This can be used with script calls, in actual      #
  27. #  scripts, or with the conditional branch script option.  This is meant to    #
  28. #  be a scripters resource.                                                    #
  29. ###-----                                                                -----###
  30. #      Usage:                                                                  #
  31. #                                                                              #
  32. #   Check.armour(x[, y]) -or- Check.armor(x[, y])                              #
  33. #     - Used to check if the party has a particular piece of armour equipped   #
  34. #       or not.  Use "x" to define the ID of the armour to check for.  "y" is  #
  35. #       an optional value and does not need to be defined.  If "y" is "true"   #
  36. #       then the ENTIRE party must be wearing the armour.  By default it is    #
  37. #       false.                                                                 #
  38. #                                                                              #
  39. #   Check.weapon(x[, y])                                                       #
  40. #     - Used to check if the party has a particular weapon equipped or not.    #
  41. #       Use "x" to define the ID of the weapon to check for.  "y" is an        #
  42. #       optional value and does not need to be defined.  If "y" is "true"      #
  43. #       then the ENTIRE party must be wearing the weapon.  By default it is    #
  44. #       false.                                                                 #
  45. #                                                                              #
  46. #   Check.skill(x[, y])                                                        #
  47. #     - Used to check if the party has a particular skill learned or not.      #
  48. #       Use "x" to define the ID of the skill to check for.  "y" is an         #
  49. #       optional value and does not need to be defined.  If "y" is "true"      #
  50. #       then the ENTIRE party must have learned the skill.  By default it is   #
  51. #       false.                                                                 #
  52. #                                                                              #
  53. #   Check.state(x[, y])                                                        #
  54. #     - Used to check if the party has a particular state afflicted or not.    #
  55. #       Use "x" to define the ID of the state to check for.  "y" is an         #
  56. #       optional value and does not need to be defined.  If "y" is "true"      #
  57. #       then the ENTIRE party must be afflicted with the state.  By default    #
  58. #       it is false.                                                           #
  59. #                                                                              #
  60. #   Check.stat[(x, y)]                                                         #
  61. #     - Used to check the value of a certain stat.  Replace "stat" with one    #
  62. #       of the following:                                                      #
  63. #         atk, def, spi, agi, maxhp, maxmp, hit, eva, cri, level,              #
  64. #         hp, mp, perhp, permp                                                 #
  65. #       "perhp" and "permp" are percentage checks that return a percent.       #
  66. #       This method returns an integer rather than true or false.  There are   #
  67. #       two arguments that can be used.  "x" defines the range of the value    #
  68. #       to return where -1 = return lowest, 0 = return average, and            #
  69. #       1 = return highest.  Be default, the highest value is returned.        #
  70. #       "y" defines the variable to return the value to.  This can be useful   #
  71. #       if you want to tell the player one of these values.                    #
  72. #                                                                              #
  73. #   Check.song(x) -requires Neonblack's Ocarina script v2.0 or higher-         #
  74. #     - Used to check if the player has learned a certain song.  Remember      #
  75. #       that this script uses 1 as the lowest number song rather than 0.       #
  76. #       Returns either true or false.                                          #
  77. #                                                                              #
  78. #   Check.lockpicks -requires Neonblack's Lockpick script v1.2 or higher-      #
  79. #     - Used to check if the party has any lockpicks.  Does not check for the  #
  80. #       gold lockpick.  Returns the number of lockpicks as an integer.         #
  81. #                                                                              #
  82. #   Check.goldpick -requires Neonblack's Lockpick script v1.2 or higher-       #
  83. #     - Used to check if the party has the gold lockpick.  If the creator has  #
  84. #       opted not to use the gold lockpick, a value of "false" is returned.    #
  85. ###--------------------------------------------------------------------------###
  86.  
  87.  
  88. ###--------------------------------------------------------------------------###
  89. #  The following lines are the actual core code of the script.  While you are  #
  90. #  certainly invited to look, modifying it may result in undesirable results.  #
  91. #  Modify at your own risk!                                                    #
  92. ###--------------------------------------------------------------------------###
  93.  
  94.  
  95.  
  96. module Check
  97.   def self.armor(check_arm, all = false)
  98.     return armour(check_arm, all)
  99.   end
  100.  
  101.   def self.armour(check_arm, all = false)
  102.     for i in 0...$game_party.members.size
  103.       chars = $game_party.members[i]
  104.       result = (chars.armors.include?($data_armors[check_arm]))
  105.       break if result == true unless all
  106.       break if result == false if all
  107.     end
  108.     return result
  109.   end
  110.  
  111.   def self.weapon(check_wep, all = false)
  112.     for i in 0...$game_party.members.size
  113.       chars = $game_party.members[i]
  114.       result = (chars.weapons.include?($data_weapons[check_wep]))
  115.       break if result == true unless all
  116.       break if result == false if all
  117.     end
  118.     return result
  119.   end
  120.  
  121.   def self.skill(check_ski, all = false)
  122.     for i in 0...$game_party.members.size
  123.       chars = $game_party.members[i]
  124.       result = (chars.skill_learn?($data_skills[check_ski]))
  125.       break if result == true unless all
  126.       break if result == false if all
  127.     end
  128.     return result
  129.   end
  130.  
  131.   def self.state(check_sta, all = false)
  132.     for i in 0...$game_party.members.size
  133.       chars = $game_party.members[i]
  134.       result = (chars.state?(check_sta))
  135.       break if result == true unless all
  136.       break if result == false if all
  137.     end
  138.     return result
  139.   end
  140.  
  141.   def self.atk(lah = 1, var = nil)
  142.     return cstat(1, lah, var)
  143.   end
  144.  
  145.   def self.def(lah = 1, var = nil)
  146.     return cstat(2, lah, var)
  147.   end
  148.  
  149.   def self.spi(lah = 1, var = nil)
  150.     return cstat(3, lah, var)
  151.   end
  152.  
  153.   def self.agi(lah = 1, var = nil)
  154.     return cstat(4, lah, var)
  155.   end
  156.  
  157.   def self.maxhp(lah = 1, var = nil)
  158.     return cstat(5, lah, var)
  159.   end
  160.  
  161.   def self.maxmp(lah = 1, var = nil)
  162.     return cstat(6, lah, var)
  163.   end
  164.  
  165.   def self.hit(lah = 1, var = nil)
  166.     return cstat(7, lah, var)
  167.   end
  168.  
  169.   def self.eva(lah = 1, var = nil)
  170.     return cstat(8, lah, var)
  171.   end
  172.  
  173.   def self.cri(lah = 1, var = nil)
  174.     return cstat(9, lah, var)
  175.   end
  176.  
  177.   def self.hp(lah = 1, var = nil)
  178.     return cstat(10, lah, var)
  179.   end
  180.  
  181.   def self.mp(lah = 1, var = nil)
  182.     return cstat(11, lah, var)
  183.   end
  184.  
  185.   def self.level(lah = 1, var = nil)
  186.     return cstat(100, lah, var)
  187.   end
  188.  
  189.   def self.perhp(lah = 1, var = nil)
  190.     return cstat(101, lah, var)
  191.   end
  192.  
  193.   def self.permp(lah = 1, var = nil)
  194.     return cstat(102, lah, var)
  195.   end
  196.  
  197.   def self.cstat(stat, lah, var)
  198.     var = nil if var < 1
  199.     vi = 0
  200.     si = $game_party.members.size
  201.     for i in 0...$game_party.members.size
  202.       chars = $game_party.members[i]
  203.       vn = rstat(stat, chars)
  204.       case lah
  205.       when 0
  206.         vi = vn if vn < vi or vi == 0
  207.       when 1
  208.         vi += vn
  209.       when 2
  210.         vi = vn if vi < vn
  211.       end
  212.     end
  213.     vi /= si if lah == 1
  214.     $game_variables[var] = Integer(vi) if var != nil
  215.     return Integer(vi)
  216.   end
  217.  
  218.   def self.rstat(stat, chars)
  219.     case stat
  220.     when 1
  221.       return chars.atk
  222.     when 2
  223.       return chars.def
  224.     when 3
  225.       return chars.spi
  226.     when 4
  227.       return chars.agi
  228.     when 5
  229.       return chars.maxhp
  230.     when 6
  231.       return chars.maxmp
  232.     when 7
  233.       return chars.hit
  234.     when 8
  235.       return chars.eva
  236.     when 9
  237.       return chars.cri
  238.     when 10
  239.       return chars.hp
  240.     when 11
  241.       return chars.mp
  242.     when 100
  243.       return chars.level
  244.     when 101
  245.       cs = chars.hp
  246.       ms = chars.maxhp
  247.       rs = cs * 100 / ms
  248.       return rs
  249.     when 102
  250.       cs = chars.mp
  251.       ms = chars.maxmp
  252.       rs = cs * 100 / ms
  253.       return rs
  254.     end
  255.   end
  256.  
  257.   if $imported["CP_OCARINA"]
  258.     def self.song(num)
  259.       result = $data_songs[num - 1][2]
  260.       return result
  261.     end
  262.   end
  263.  
  264.   if $imported["CP_LOCKPICK"]
  265.     def self.lockpicks
  266.       itemnum = CP::LOCKPICK::SETTINGS::PICK_ITEM
  267.       result = $game_party.item_number($data_items[itemnum])
  268.       return result
  269.     end
  270.    
  271.     def self.goldpick
  272.       itemnum = CP::LOCKPICK::SETTINGS::PICK_ITEM
  273.       usegp = CP::LOCKPICK::SETTINGS::USE_G_PICK
  274.       result = false
  275.       result = $game_party.has_item?($data_items[itemnum]) if usegp
  276.       return result
  277.     end
  278.   end
  279. end
  280.  
  281.        # I overcomplicate things, no?
  282. ###--------------------------------------------------------------------------###
  283. #  End of script.                                                              #
  284. ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement