neutale

Item Script Call

Oct 19th, 2019
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.38 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Item Script Call
  3. #  ItemCallScript.rb
  4. #------------------------------------------------------------------------------
  5. #  
  6. # Create an item or skill that will run any script when used.
  7. # When used on the menu screen, can be done without returning to the map screen.
  8. # Knowledge of RGSS is required for use.
  9. #
  10. # ●How to use
  11. # 1. Specify the following in the item or skill note box.
  12. # <=(Script you want to run)=>
  13. #
  14. # Example(If used, value [100] will be set to variable [1])
  15. # <=
  16. # $game_variables[1] = 100
  17. # =>
  18. #
  19. # If the effect range is set for all allies and all enemies,
  20. # the script will be executed for all targets.
  21. #
  22. # The following variables and functions can be used in the script.
  23. # user     : Item user
  24. # target   : Item target
  25. #
  26. # ●Terms of use
  27. #  It's possible to modify and redistribute without permission from the author.
  28. #-----------------------------------------------------------------------------
  29. # (C)2018 Triacontane
  30. # This software is released under the MIT License.
  31. # http://opensource.org/licenses/mit-license.php
  32. #-----------------------------------------------------------------------------
  33. # Version
  34. # 1.0.0 2018/09/20 Inital release
  35. # ----------------------------------------------------------------------------
  36. # [Blog]   : https://triacontane.blogspot.jp/
  37. # [Twitter]: https://twitter.com/triacontane/
  38. # [GitHub] : https://github.com/triacontane/
  39. #=============================================================================
  40.  
  41. class Game_Battler < Game_BattlerBase
  42.   #--------------------------------------------------------------------------
  43.   # ● Use skills / items
  44.   #    Called to apply effects or target.
  45.   #--------------------------------------------------------------------------
  46.   alias ics_use_item use_item
  47.   def use_item(item)
  48.     ics_use_item(item)
  49.     if !item.for_opponent? and !item.for_friend?
  50.       apply_script_if_exist(self, item)
  51.     end
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # ● Skill / item application test
  55.   #    Determine whether recovery is prohibited when the target is used.
  56.   #--------------------------------------------------------------------------
  57.   alias ics_item_test item_test
  58.   def item_test(user, item)
  59.     return true if ics_item_test(user, item)
  60.     get_item_script(item) != nil
  61.   end
  62.   #--------------------------------------------------------------------------
  63.   # ● Skill / item effects on users
  64.   #--------------------------------------------------------------------------
  65.   alias ics_item_user_effect item_user_effect
  66.   def item_user_effect(user, item)
  67.     ics_item_user_effect(user, item)
  68.     apply_script_if_exist(user, item)
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # ● Get script
  72.   #--------------------------------------------------------------------------
  73.   def get_item_script(item)
  74.     item.note.match(/<=(.*?)=>/m) {$1}
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # ● If script is specified, it is used.
  78.   #--------------------------------------------------------------------------
  79.   def apply_script_if_exist(user, item)
  80.     script = get_item_script(item)
  81.     if script != nil
  82.       target = self
  83.       eval(get_item_script(item))
  84.     end
  85.   end
  86. end
Add Comment
Please, Sign In to add comment