Advertisement
mjshi

Conditional Branch+

Mar 31st, 2016
1,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.43 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Conditional Branch+ v1.01
  3. #-- Extends the functionality of what a conditional branch can check.
  4. #-- By mjshi
  5. #-------------------------------------------------------------------------------
  6. # Installation: Put above Main, otherwise, location doesn't matter
  7. #-------------------------------------------------------------------------------
  8. # How to use:
  9. # On a conditional branch, go to the fourth tab and select the "Script" option.
  10. # Type in desired thing to check. See below...
  11. #===============================================================================
  12. #               Asterisk (*) means multiple inputs are accepted.
  13. #===============================================================================
  14. # Combining Checks
  15. # Use "&&", "||", and "()" to combine several checks in a conditional branch.
  16. # && = this AND that are true
  17. # || = this OR that are true
  18. # () = order of operations, check innermost parentheses first
  19. # !  = translates to NOT. EX. !Check.has(1) checks if player DOESN'T have it.
  20. #
  21. #-- EX: (Check.has(1) && Check.greater(1 , 0)) || Check.has(2)
  22. #-- Checks if player has item 1 and variable 1 > 0, or player has item 2.
  23. #===============================================================================
  24. # Possible Checks
  25. #-------------------------------------------------------------------------------
  26. # Items
  27. #-------------------------------------------------------------------------------
  28. # Check.has(*items)
  29. #-- EX: Check.has(1, 3, 4)
  30. #-- checks if player has items 1, 3, and 4 in inventory.
  31. #
  32. # Check.has_more(*items, number)
  33. #-- EX: Check.has_more(1, 2, 3, 4, 5)
  34. #-- checks if player has at least five (includes 5) of items 1, 2, 3, 4.
  35. #
  36. # Check.has_less(*items, number)
  37. #-- EX: Check.has_less(1, 2, 3, 4, 5)
  38. #-- checks if player has at most five (includes 5) of items 1, 2, 3, 4.
  39. #
  40. # Check.has_any(*items)
  41. #-- EX: Check.has_any(1, 3, 4)
  42. #-- checks if player has either item 1, 3, or 4 in inventory.
  43. #
  44. # Check.each_more(*[item, number])
  45. #-- EX: Check.each_more([1, 2], [2, 4])
  46. #-- checks if there are at least 2 of item 1 and at least 4 of item 2.
  47. #
  48. # Check.each_less(*[item, number])
  49. #-- EX: Check.each_less([1, 2], [2, 4])
  50. #-- checks if there are at most 2 of item 1 and at most 4 of item 2.
  51. #-------------------------------------------------------------------------------
  52. # Variables
  53. #-------------------------------------------------------------------------------
  54. # Check.is_any(variable, *values)
  55. #-- EX: Check.is_any(1, 3, 4, 5)
  56. #-- checks if variable 1 is either 3, 4, or 5
  57. #
  58. # Check.greater(*variables, value)
  59. #-- EX: Check.greater(1, 2, 3, 5)
  60. #-- checks if variables 1, 2, and 3 are at least 5.
  61. #
  62. # Check.lesser(*variables, value)
  63. #-- EX: Check.lesser(1, 2, 3, 5)
  64. #-- checks if variables 1, 2, and 3 are at most 5.
  65. #
  66. # Check.in_range(*variables, start, stop)
  67. #-- EX: Check.in_range(1, 3, 4, 5)
  68. #-- checks if variable 1 AND 3 are between 4 and 5, including 4 and 5.
  69. #
  70. # Check.any_inrange(*variables, start, stop)
  71. #-- EX: Check.any_inrange(1, 3, 4, 5)
  72. #-- checks if variable 1 OR 3 are between 4 and 5, including 4 and 5.
  73. #
  74. # Check.each_is(*[variable, value])
  75. #-- EX: Check.each_is([1, 3], [4, 5])
  76. #-- checks if variable 1 is 3, and variable 4 is 5.
  77. #
  78. # Check.each_greater(*[variable, value])
  79. #-- EX: Check.each_greater([1, 3], [4, 5])
  80. #-- checks if variable 1 is at least 3 and variable 4 is at least 5.
  81. #
  82. # Check.each_lesser(*[variable, value])
  83. #-- EX: Check.each_lesser([1, 3], [4, 5])
  84. #-- checks if variable 1 is at most 3 and variable 4 is at most 5.
  85. #
  86. # Check.each_inrange(*[variable, start, stop])
  87. #-- EX: Check.in_range([1, 3, 5], [3, 1, 4])
  88. #-- checks if variable 1 is between 3 and 5, and variable 3 is between 1 and 4.
  89. #-------------------------------------------------------------------------------
  90. # Switches
  91. #-------------------------------------------------------------------------------
  92. # Check.all_true(*switches)
  93. #-- EX: Check.all_true(1, 2, 3)
  94. #-- checks if switches 1, 2, 3 are true
  95. #
  96. # Check.any_true(*switches)
  97. #-- EX: Check.any_true(1, 2, 3)
  98. #-- checks if either of switches 1, 2, 3 are true
  99. #
  100. # Check.all_false(*switches)
  101. #-- EX: Check.all_false(1, 2, 3)
  102. #-- checks if switches 1, 2, 3 are false
  103. #
  104. # Check.any_false(*switches)
  105. #-- EX: Check.any_false(1, 2, 3)
  106. #-- checks if either of switches 1, 2, 3 are false
  107. #
  108. # Check.each_switch(*[switch, on/off])
  109. # If on, put 1. If off, put 0.
  110. #===============================================================================
  111.  
  112. module Check
  113.  
  114.   #-----------------------------------------------------------------------------
  115.   # Items
  116.   #-----------------------------------------------------------------------------
  117.   def self.has(*items)
  118.     items.each do |item|
  119.       return false if !$game_party.has_item?($data_items[item])
  120.     end
  121.     return true
  122.   end
  123.  
  124.   def self.has_more(*items, number)
  125.     items.each do |item|
  126.       return false if $game_party.item_number($data_items[item]) < number
  127.     end
  128.     return true
  129.   end
  130.  
  131.   def self.has_less(*items, number)
  132.     items.each do |item|
  133.       return false if $game_party.item_number($data_items[item]) > number
  134.     end
  135.     return true
  136.   end
  137.  
  138.   def self.has_any(*items)
  139.     items.each do |item|
  140.       return true if $game_party.has_item?($data_items[item])
  141.     end
  142.     return false
  143.   end
  144.  
  145.   def self.each_more(*item_number_array)
  146.     item_number_array.each do |array|
  147.       return false if $game_party.item_number($data_items[array[0]]) < array[1]
  148.     end
  149.     return true
  150.   end
  151.  
  152.   def self.each_less(*item_number_array)
  153.     item_number_array.each do |array|
  154.       return false if $game_party.item_number($data_items[array[0]]) > array[1]
  155.     end
  156.     return true
  157.   end
  158.  
  159.   #-----------------------------------------------------------------------------
  160.   # Variables
  161.   #-----------------------------------------------------------------------------
  162.  
  163.   def self.is_not(id, *values)
  164.     values.each do |value|
  165.       return false if $game_variables[id] == value
  166.     end
  167.     return true
  168.   end
  169.  
  170.   def self.is_any(id, *values)
  171.     values.each do |value|
  172.       return true if $game_variables[id] == value
  173.     end
  174.     return false
  175.   end
  176.  
  177.   def self.greater(*ids, value)
  178.     ids.each do |id|
  179.       return false if $game_variables[id] < value
  180.     end
  181.     return true
  182.   end
  183.  
  184.   def self.lesser(*ids, value)
  185.     ids.each do |id|
  186.       return false if $game_variables[id] > value
  187.     end
  188.     return true
  189.   end
  190.  
  191.   def self.in_range(*ids, start, stop)
  192.     ids.each do |id|
  193.       return false if ($game_variables[id] < start) || ($game_variables[id] > stop)
  194.     end
  195.     return true
  196.   end
  197.  
  198.   def self.any_inrange(*ids, start, stop)
  199.     ids.each do |id|
  200.       return true if ($game_variables[id] >= start) && ($game_variables[id] <= stop)
  201.     end
  202.     return false
  203.   end
  204.  
  205.   def self.each_is(*variable_array)
  206.     variable_array.each do |array|
  207.       return false if $game_variables[array[0]] != array[1]
  208.     end
  209.     return true
  210.   end
  211.  
  212.   def self.each_greater(*variable_array)
  213.     variable_array.each do |array|
  214.       return false if $game_variables[array[0]] < array[1]
  215.     end
  216.     return true
  217.   end
  218.  
  219.   def self.each_lesser(*variable_array)
  220.     variable_array.each do |array|
  221.       return false if $game_variables[array[0]] > array[1]
  222.     end
  223.     return true
  224.   end
  225.  
  226.   def self.each_inrange(*variable_array)
  227.     variable_array.each do |array|
  228.       return false if ($game_variables[array[0]] < array[1]) || ($game_variables[array[0]] > array[2])
  229.     end
  230.     return true
  231.   end
  232.  
  233.   #-----------------------------------------------------------------------------
  234.   # Switches
  235.   #-----------------------------------------------------------------------------
  236.  
  237.   def self.all_true(*switches)
  238.     switches.each do |switch|
  239.       return false if !$game_switches[switch]
  240.     end
  241.     return true
  242.   end
  243.  
  244.   def self.any_true(*switches)
  245.     switches.each do |switch|
  246.       return true if $game_switches[switch]
  247.     end
  248.     return false
  249.   end
  250.  
  251.   def self.all_false(*switches)
  252.     switches.each do |switch|
  253.       return false if $game_switches[switch]
  254.     end
  255.     return true
  256.   end
  257.  
  258.   def self.any_false(*switches)
  259.     switches.each do |switch|
  260.       return true if !$game_switches[switch]
  261.     end
  262.     return false
  263.   end
  264.  
  265.   def self.each_switch(*switches_array)
  266.     switches_array.each do |array|
  267.       return false if $game_switches[array[0]] != array[1]
  268.     end
  269.     return true
  270.   end
  271. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement