Advertisement
TheSixth

Add/Remove State Battle Log Addon for the Damage Formula Box

Apr 15th, 2016
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.17 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] Add/Remove State Battle Log Addon for the Damage Formula Box
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.0
  6. # * Updated: 16/04/2016
  7. # * Requires: ----------
  8. #-------------------------------------------------------------------------------
  9. # * < Change Log >
  10. #-------------------------------------------------------------------------------
  11. # * Version 1.0 (16/04/2016)
  12. #   - Initial release.
  13. #-------------------------------------------------------------------------------
  14. # * < Description >
  15. #-------------------------------------------------------------------------------
  16. # * By default, when you enter "a.add_state(ID)" or "b.remove_state(ID)" in the
  17. #   damage formula, the log window in battle will not display the state changes
  18. #   done by these. This script adds 2 new script calls usable in the damage
  19. #   formula box for adding/removing states with the addition of showing the
  20. #   relevant battle logs for them whenever you want to show them.
  21. #-------------------------------------------------------------------------------
  22. # * < Script Calls >
  23. #-------------------------------------------------------------------------------
  24. # * You can use the following script calls in the damage formula:
  25. #
  26. #     target.add_state_with_log(state_id,chance) # For adding states
  27. #     target.rem_state_with_log(state_id,chance) # For removing state
  28. #
  29. #   The 'target' can be either 'a' (for the attacker) or 'b' (for the target).
  30. #  
  31. #   The state_id is the ID of the state you want to add/remove.
  32. #
  33. #   The chance is the chance of success for the operation in percentages.
  34. #   1 means 1%, 20 means 20%, 100 means 100%, and so on.
  35. #   This argument is optional. If you omit it, 100 will be used by default,
  36. #   which means that it will be executed always (100%).
  37. #
  38. #   Examples:
  39. #
  40. #     b.add_state_with_log(2,25)
  41. #   This adds state 2 (Poison by default) on the target with a 25% success
  42. #   chance. Depending on the result of this action (state is inflicted or not),
  43. #   a different battle log can be shown (if you set up different texts for
  44. #   the different outcomes, at least).
  45. #   If the state is inflicted, it will use the default state messages from the
  46. #   database, which means that the target's name will be displayed along with
  47. #   the 1st (if the target was an actor) or 2nd (if the target was an enemy)
  48. #   state message from the database.
  49. #   If the state did not get applied, it will use the texts set up in this
  50. #   script. If a state do not has a text set up in this script for failure,
  51. #   nothing will show up in the battle log.
  52. #   When I say target, I don't mean the target of the skill itself, but the
  53. #   target of this script call! Remember, the target of this script call is
  54. #   controlled by the target options available in the damage formula box!
  55. #
  56. #     a.remove_state_with_log(3,50)
  57. #   This will remove state 3 (Blind by default) from the target with a 50%
  58. #   success chance.
  59. #   Other than removing a state instead of adding it, it acts the same way like
  60. #   the other script call for adding a state. It shows a different battle log
  61. #   message depending on the outcome of the script call.
  62. #-------------------------------------------------------------------------------
  63. # * < Installation >
  64. #-------------------------------------------------------------------------------
  65. # * Place this script between Materials and Main!
  66. #-------------------------------------------------------------------------------
  67. # * < Compatibility Info >
  68. #-------------------------------------------------------------------------------
  69. # * No known compatibility issues.
  70. #-------------------------------------------------------------------------------
  71. # * < Known Issues >
  72. #-------------------------------------------------------------------------------
  73. # * No known issues so far.
  74. #-------------------------------------------------------------------------------
  75. # * < Terms of Use >
  76. #-------------------------------------------------------------------------------
  77. # * Free to use for whatever purposes you want.
  78. # * Credit me (Sixth) in your game, pretty please! :P
  79. # * Posting modified versions of this script is allowed as long as you notice me
  80. #   about it with a link to it!
  81. #===============================================================================
  82. $imported = {} if $imported.nil?
  83. $imported["SixthLogWinAddonStates"] = true
  84. #===============================================================================
  85. # Settings:
  86. #===============================================================================
  87. module CustomBattleLogs
  88.   #-----------------------------------------------------------------------------
  89.   # State Change Fail Battle Log Settings:
  90.   #-----------------------------------------------------------------------------
  91.   # When a state infliction/removal fails because of a success chance check
  92.   # failure, you can show up a custom text for each states if you set up some
  93.   # texts for them here.
  94.   #
  95.   # All of these settings are optional!
  96.   # If you don't want any battle log showing up for a failed state change
  97.   # attempt, you simply don't need to add any settings for them here.
  98.   # If you only want to show a text when the target was an actor/enemy, you
  99.   # just add a setting for actor/enemy and can omit the other.
  100.   # If you only want a text when the user failed to inflict a state on the
  101.   # target but not when the state failed to cure the target from the state,
  102.   # you just add a setting for state addition and omit the removal text setting.
  103.   # So, everything is optional!
  104.   #
  105.   # Format:
  106.   #
  107.   #   state_id => {
  108.   #     :actor => { # Texts showing when the target is an actor
  109.   #       :add => "state infliction failure text",
  110.   #       :rem => "state removal failure text",
  111.   #     },
  112.   #     :enemy => { # Texts showing when the target is an enemy
  113.   #       :add => "state infliction failure text",
  114.   #       :rem => "state removal failure text",
  115.   #     },
  116.   #   },
  117.   #
  118.   # The format above kinda tells what these do, but if you are not sure, check
  119.   # the sample settings.
  120.   #
  121.   # If you don't want to use these battle logs at all, feel free to remove the
  122.   # sample settings, but do NOT delete the hash itself!
  123.   # So, leave it like this:
  124.   #   FailLogs = {}
  125.   # That must be here!
  126.   #-----------------------------------------------------------------------------
  127.   FailLogs = {
  128.     2 => { # Poison
  129.       :actor => { # Texts showing when the target is an actor
  130.         :add => " resisted the poison!",
  131.         :rem => " could not be cured from poison!",
  132.       },
  133.       :enemy => { # Texts showing when the target is an enemy
  134.         :add => " resisted the poison!",
  135.         :rem => " could not be cured from poison!",
  136.       },
  137.     },
  138.     3 => { # Blind
  139.       :actor => { # Texts showing when the target is an actor
  140.         :add => " did not became blind!",
  141.       },
  142.       :enemy => { # Texts showing when the target is an enemy
  143.         :rem => " still can't see anything!",
  144.       },
  145.     },
  146.     # Add more settings here if needed!
  147.   }
  148.  
  149. end
  150. #===============================================================================
  151. # End of Settings! Editing anything below may lead to... You know what, right?
  152. #===============================================================================
  153.  
  154. class Scene_Battle < Scene_Base
  155.  
  156.   attr_accessor :log_window
  157.  
  158. end
  159.  
  160. class Game_Battler < Game_BattlerBase
  161.  
  162.   def add_state_with_log(state_id,chance=100)
  163.     success = rand(100)
  164.     skip_txt = true if state?(state_id)
  165.     if success < chance
  166.       add_state(state_id)
  167.       txt = get_added_state_txt(state_id,true)
  168.     else
  169.       txt = get_added_state_txt(state_id,false)
  170.     end
  171.     return if skip_txt
  172.     if SceneManager.scene_is?(Scene_Battle) && txt[1] && !txt[1].empty?
  173.       SceneManager.scene.log_window.add_text(txt[0] + txt[1])
  174.       SceneManager.scene.log_window.wait
  175.       SceneManager.scene.log_window.wait_for_effect
  176.     end
  177.   end
  178.  
  179.   def rem_state_with_log(state_id,chance=100)
  180.     return if !state?(state_id)
  181.     success = rand(100)
  182.     if success < chance
  183.       remove_state(state_id)
  184.       txt = get_removed_state_txt(state_id,true)
  185.     else
  186.       txt = get_removed_state_txt(state_id,false)
  187.     end
  188.     if SceneManager.scene_is?(Scene_Battle) && txt[1] && !txt[1].empty?
  189.       SceneManager.scene.log_window.add_text(txt[0] + txt[1])
  190.       SceneManager.scene.log_window.wait
  191.       SceneManager.scene.log_window.wait_for_effect
  192.     end
  193.   end
  194.  
  195.   def get_added_state_txt(state_id,success=true)
  196.     if success
  197.       if self.is_a?(Game_Actor)
  198.         txt = [actor.name,$data_states[state_id].message1]
  199.       else
  200.         txt = [enemy.name,$data_states[state_id].message2]
  201.       end
  202.     else
  203.       return ["",""] unless CustomBattleLogs::FailLogs[state_id]
  204.       if self.is_a?(Game_Actor)
  205.         return ["",""] unless CustomBattleLogs::FailLogs[state_id][:actor]
  206.         txt = [actor.name,CustomBattleLogs::FailLogs[state_id][:actor][:add]]
  207.       else
  208.         return ["",""] unless CustomBattleLogs::FailLogs[state_id][:enemy]
  209.         txt = [enemy.name,CustomBattleLogs::FailLogs[state_id][:enemy][:add]]
  210.       end
  211.     end
  212.   end
  213.  
  214.   def get_removed_state_txt(state_id,success=true)
  215.     if success
  216.       if self.is_a?(Game_Actor)
  217.         txt = [actor.name,$data_states[state_id].message4]
  218.       else
  219.         txt = [enemy.name,$data_states[state_id].message4]
  220.       end
  221.     else
  222.       return ["",""] unless CustomBattleLogs::FailLogs[state_id]
  223.       if self.is_a?(Game_Actor)
  224.         return ["",""] unless CustomBattleLogs::FailLogs[state_id][:actor]
  225.         txt = [actor.name,CustomBattleLogs::FailLogs[state_id][:actor][:rem]]
  226.       else
  227.         return ["",""] unless CustomBattleLogs::FailLogs[state_id][:enemy]
  228.         txt = [enemy.name,CustomBattleLogs::FailLogs[state_id][:enemy][:rem]]
  229.       end
  230.     end
  231.   end
  232.  
  233. end
  234. #==============================================================================
  235. # !!END OF SCRIPT - OHH, NOES!!
  236. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement