Advertisement
FlipelyFlip

Flips Actor Equip Restriction v1.0

Jun 24th, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.38 KB | None | 0 0
  1. =begin
  2.                             Flips Actor Equip Restrictions
  3.                                        v1.0
  4.  
  5. Hey guys and girls ;D
  6.  
  7. this is one of my first usefull (I hope so) scripts on VX-Ace.
  8. This script helps you to restrict certain armors and weapons for actors.
  9. I know it could be done over the Equip Types but why to set up for a
  10. single Axe a new Equiptype because only 1 actor is using it?
  11. Not needed anymore with this script!
  12.  
  13. Set a notetag in the equipment which should be restricted for certain actors
  14. and it will work (:
  15.  
  16. How to use it?
  17. Write in the notetag of a weapon or armor:
  18.  
  19. <restrict_actor: x>
  20.  
  21. or
  22.  
  23. <restrict_actor: x,x>
  24.  
  25. As an example:
  26.  
  27. if you want that the weapon with the ID 1 won't be available for the actor with
  28. the ID 5 then do this: <restrict_actor: 5>
  29. if actor 5, 7, 10 and 12 shouldn't be able to use the weapon then set it up like
  30. this: <restrict_actor: 5,7,10,12>
  31.  
  32. I hope you understand what I mean (:
  33.  
  34. Credits goes to:
  35.  
  36. FlipelyFlip for creating the Equip Restrictions
  37. MephistoX for the NoteTag Reading Scriptpart I used
  38.  
  39. =end
  40.  
  41. #=============================================================================
  42. # ONLY EDIT IF YOU KNOW WHAT YOU DO!!
  43. #=============================================================================
  44. module RPG
  45.   class Weapon
  46.     def actor_restrict
  47.       NoteReader.get_data(note, 'restrict_actor')
  48.     end
  49.   end
  50.   class Armor
  51.     def actor_restrict
  52.       NoteReader.get_data(note, 'restrict_actor')
  53.     end
  54.   end
  55. end
  56.  
  57. class Game_BattlerBase
  58.   #--------------------------------------------------------------------------
  59.   # ● 装備可能判定
  60.   #--------------------------------------------------------------------------
  61.   def equippable?(item)
  62.     return false unless item.is_a?(RPG::EquipItem)
  63.     return false if equip_type_sealed?(item.etype_id)
  64.     return false if item.is_a?(RPG::Weapon) and w_act_check(item.id).include?(actor.id)
  65.     return false if item.is_a?(RPG::Armor) and a_act_check(item.id).include?(actor.id)
  66.     return equip_wtype_ok?(item.wtype_id) if item.is_a?(RPG::Weapon)
  67.     return equip_atype_ok?(item.atype_id) if item.is_a?(RPG::Armor)
  68.     return false
  69.   end
  70.  
  71.   #--------------------------------------------------------------------------
  72.   # ● checks if actor can equip the weapon
  73.   #--------------------------------------------------------------------------
  74.   def w_act_check(item)
  75.     a = 0
  76.     acties = []
  77.     for weaponry in $data_weapons[item].actor_restrict
  78.       a += 1
  79.       acties[a] = weaponry
  80.     end
  81.   end
  82.   #--------------------------------------------------------------------------
  83.   # ● checks if actor can equip the armor
  84.   #--------------------------------------------------------------------------
  85.   def a_act_check(item)
  86.     a = 0
  87.     acties = []
  88.     for armory in $data_armors[item].actor_restrict
  89.       a += 1
  90.       acties[a] = armory
  91.     end
  92.   end
  93. end
  94.  
  95. #==============================================================================
  96. # ■ Module NoteReader                                                                      # Author: MephistoX
  97. #------------------------------------------------------------------------------
  98. # Description:
  99. # ------------
  100. # Read and Retrieve Information from notes based on a identifier
  101. # It will return 'string' type data, but also incldues some defined returners
  102. # to return data in type like symbols, strings, arrays, etc to make easy to
  103. # read the data after.
  104. #==============================================================================
  105.  
  106. module NoteReader
  107.   #-------------------------------------------------------------------------
  108.   #   Name        : Get Parameter
  109.   #   Info        : Returns a String with a parameter
  110.   #   Author    : MephistoX
  111.   #   Call Info : note to read, parameter
  112.   #-------------------------------------------------------------------------
  113.   def self.get_parameter(note, parameter)
  114.         # Get data to process
  115.         dc_data = note.downcase.split("\r\n")
  116.         data    = note.split("\r\n")
  117.         # Set Result
  118.         result = nil
  119.         # Pass Through each data line
  120.         # If Line Text include parameter
  121.         dc_data.each_index do |i|
  122.           next if dc_data[i].start_with?('#')
  123.           # If Line Text include parameter
  124.           if dc_data[i].include?(parameter.downcase)
  125.                 # Set Result as second element of line separated by ':'
  126.                 result = data[i].split(':')[1]
  127.                 # Break Loop
  128.                 break
  129.           end
  130.         end
  131.         # Return Result to Sym if Transform
  132.         return result
  133.   end
  134.   #-------------------------------------------------------------------------
  135.   #   Name        : Get Data
  136.   #   Info        : Get Checked and Proccessed data
  137.   #   Author    : MephistoX
  138.   #   Call Info : text, parameter to search and type
  139.   #-------------------------------------------------------------------------
  140.   def self.get_data(text, parameter)
  141.         # Set String
  142.         string = get_parameter(text, parameter)
  143.         # Set Result and Proccess it
  144.         result = process_result(string)
  145.         # Return Result
  146.         result
  147.   end
  148.   #-------------------------------------------------------------------------
  149.   #   Name        : Proccess Result
  150.   #   Info        : Proccess the result string and transform into the data
  151.   #   Author    : MephistoX
  152.   #   Call Info : string & type
  153.   #-------------------------------------------------------------------------
  154.   def self.process_result(string)
  155.         # Return nil if no string
  156.         return nil if string.nil?
  157.         # Delete string whitespaces
  158.         r_string = string.strip
  159.         # Return Array of Symbols if type is sarray
  160.         return to_array(r_string)
  161.   end
  162.   #-------------------------------------------------------------------------
  163.   #   Name        : To Array
  164.   #   Info        : Transform string into an array with symbols
  165.   #   Author    : MephistoX
  166.   #   Call Info : String, transform type (:sym or :int)
  167.   #-------------------------------------------------------------------------
  168.   def self.to_array(string)
  169.         # Set Empty Array
  170.         array = []
  171.         # Get Items
  172.         sitems = string.strip.split(',')
  173.         # Pass Through each item
  174.         sitems.each do |item|
  175.           # Push String into integer if transform type is to integer
  176.           array << item.to_i
  177.         end
  178.         # Return Array
  179.         array
  180.   end
  181. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement