SHARE
TWEET

[VXA] TP System Overhaul

AngryPacman Apr 23rd, 2012 1,490 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. #
  3. # TP System Overhaul (1.1)
  4. # 22/6/2014
  5. # By Pacman
  6. # RPG Maker VX Ace comes with a very cool system secondary to MP called TP. All
  7. # actors (and enemies) have TP (whether it is shown or not is up to the user),
  8. # with a maximum of 100. While an interesting idea and useful in a lot of ways,
  9. # the default TP system is not very flexible to the users needs. This script
  10. # sets out to get rid of restrictions placed by the default scripts in relation
  11. # to TP.
  12. #
  13. # This super-sexy script will allow you to:
  14. #   Give actors and enemies different maximum TP values (exceeding the default
  15. #     limit of 100)
  16. #   Give skills a TP cost of over 100
  17. #   Change actor and enemy base TP values at your pleasure
  18. #   Let the TP of an actor be effected by the actor's level
  19. #   Give each actor or enemy a different formula for calculating the initial
  20. #     TP they start every battle with.
  21. #   Set TP altering stats on equips (Armors and Weapons)
  22. #
  23. # Notetags:
  24. #   Put \mtp[x] in the notebox of an enemy or actor to give them the base max
  25. #     TP value x.
  26. #   Put \tp_gain[x] in the notebox of an equip to add x to the TP of an actor
  27. #     who has it equipped.
  28. #   Put \tp_mul[x] in the notebox of an equip to multiply the TP of an actor
  29. #     who has it equipped by x.
  30. #   Put \tp_per[x] in the notebox of an equip to change the TP of an actor who
  31. #     has it equipped to x% of the preexisting value (\tp_per[150] will change,
  32. #     for example, 200 into 300).
  33. #
  34. # Script Calls:
  35. #   change_tp_limit(id, limit[, type])
  36. #     Changes the base max TP of actor or enemy with ID id to limit. id and
  37. #     limit must both be positive numbers. type must be :actor or :a for
  38. #     changing and actor's limit, or :enemy or :e for changing an enemy's limit.
  39. #     If type is ommited, it will default to actor.
  40. #
  41. # Configuration is below. Note that the formulaic options can be extremely
  42. # complicated. They are there for super-duper-crazy-smart people to make their
  43. # games extra-special fun if they want to. By all means, do not feel pressured
  44. # to use these options.
  45. #
  46. #===============================================================================
  47. #
  48. # CONFIGURATION
  49. #
  50. #===============================================================================
  51.  
  52. module PAC
  53.   module TP
  54.     ACTOR_DEFAULT = 100 # Default for actor TP
  55.     ENEMY_DEFAULT = 100 # Default for enemy TP
  56.     LEVEL = false        # Does TP go up with actors' levels?
  57.     LEVEL_GAIN_DEFAULT = "2"  # How much does TP go up in levels by default?
  58.     # This is multiplied by the level of the actor.
  59.     LEVEL_GAIN = []
  60.     # In this array, we can store the formulae for calculating the amount TP
  61.     # is gained specific to each actor. This is multiplied by the level of the
  62.     # actor.
  63.     LEVEL_GAIN[1] = "self.atk / 4"
  64.     ACTOR_INIT_FORMULA = "100"  # Default formula for
  65.     # initializing actors' TP at the start of all battles.
  66.     # You can specify the formula for actors in this array.
  67.     AIF = []
  68.     AIF[2] = "[[(rand * 100) - (rand * 100), 0].max + self.mtp / 100 *
  69.    self.level, self.mtp / (self.level / 25)].min"
  70.     ENEMY_INIT_FORMULA = "rand * 25"  # Default formula for
  71.     # initializing enemies' TP at the start of all battles.
  72.     # You can specify the formula for enemies in this array.
  73.     EIF = []
  74.   end
  75. end
  76.  
  77. #===============================================================================
  78. #
  79. # END CONFIGURATION
  80. #
  81. #===============================================================================
  82.  
  83. ($pac ||= {})[:tp_system] = 1.1
  84.  
  85. #==============================================================================
  86. # ** RPG::Actor and RPG::Enemy
  87. #------------------------------------------------------------------------------
  88. #  Data classes for actors and enemies respectively.
  89. #==============================================================================
  90.  
  91. #--------------------------------------------------------------------------
  92. # Some high-tech shit goin' on up in here
  93. #--------------------------------------------------------------------------
  94. class RPG::Actor < RPG::BaseItem
  95.   def mtp
  96.     return !self.note[/\\mtp\[(\d+)\]/i].nil? ? $1.to_i : nil
  97.   end
  98. end
  99.  
  100. class RPG::Enemy < RPG::BaseItem
  101.   def mtp
  102.     return !self.note[/\\mtp\[(\d+)\]/i].nil? ? $1.to_i : nil
  103.   end
  104. end
  105.  
  106.  
  107. #==============================================================================
  108. # ** RPG::EquipItem
  109. #------------------------------------------------------------------------------
  110. #  A superclass of weapons and armor.
  111. #==============================================================================
  112.  
  113. class RPG::EquipItem < RPG::BaseItem
  114.   #--------------------------------------------------------------------------
  115.   # * Get TP Gain value
  116.   #--------------------------------------------------------------------------
  117.   def tp_gain
  118.     !self.note[/\\tp[_ ]?gain\[(\d+)\]/i].nil? ? $1.to_i : 0
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # * Get TP Multiply value
  122.   #--------------------------------------------------------------------------
  123.   def tp_multiply
  124.     !self.note[/\\tp[_ ]?mul(tiply)?\[(\d+)\]/i].nil? ? $1.to_i : 1
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # * Get TP Percentage value
  128.   #--------------------------------------------------------------------------
  129.   def tp_percent
  130.     !self.note[/\\tp[_ ]?per(cent)?\[(\d+)\]/i].nil? ? $1.to_i : 100
  131.   end
  132. end
  133.  
  134. #==============================================================================
  135. # ** RPG::Skill
  136. #------------------------------------------------------------------------------
  137. #  The data class for skills.
  138. #==============================================================================
  139.  
  140. class RPG::Skill < RPG::UsableItem
  141.   #--------------------------------------------------------------------------
  142.   # Alias listing
  143.   #--------------------------------------------------------------------------
  144.   alias pac_tpsys tp_cost
  145.   #--------------------------------------------------------------------------
  146.   # * Get adjusted TP cost
  147.   #--------------------------------------------------------------------------
  148.   def tp_cost(*args)
  149.     !self.note[/\\tp[_ ]?cost\[(\d+)\]/i].nil? ? $1.to_i : pac_tpsys(*args)
  150.   end
  151. end
  152.  
  153. #==============================================================================
  154. # ** Game_System
  155. #------------------------------------------------------------------------------
  156. #  This class handles system data. It saves the disable state of saving and
  157. # menus. Instances of this class are referenced by $game_system.
  158. #==============================================================================
  159.  
  160. class Game_System
  161.   #--------------------------------------------------------------------------
  162.   # Public Instance Variables
  163.   #--------------------------------------------------------------------------
  164.   attr_accessor :actor_tp
  165.   attr_accessor :enemy_tp
  166.   #--------------------------------------------------------------------------
  167.   # Alias listing
  168.   #--------------------------------------------------------------------------
  169.   alias pac_tpsys_init initialize
  170.   #--------------------------------------------------------------------------
  171.   # * Object Initialization
  172.   #--------------------------------------------------------------------------
  173.   def initialize(*args)
  174.     pac_tpsys_init(*args)
  175.     setup_tp_arrays
  176.   end
  177.   #--------------------------------------------------------------------------
  178.   # * Initialize TP Arrays
  179.   #--------------------------------------------------------------------------
  180.   def setup_tp_arrays
  181.     @actor_tp = []
  182.     for actor in $data_actors
  183.       next if actor.nil?
  184.       @actor_tp[actor.id] = actor.mtp || PAC::TP::ACTOR_DEFAULT
  185.     end
  186.     #----
  187.     @enemy_tp = []
  188.     for enemy in $data_enemies
  189.       next if enemy.nil?
  190.       @enemy_tp[enemy.id] = enemy.mtp || PAC::TP::ENEMY_DEFAULT
  191.     end
  192.   end
  193. end
  194.  
  195. #==============================================================================
  196. # ** Game_BattlerBase
  197. #------------------------------------------------------------------------------
  198. #  This base class handles battlers. It mainly contains methods for calculating
  199. # parameters. It is used as a super class of the Game_Battler class.
  200. #==============================================================================
  201.  
  202. class Game_BattlerBase
  203.   #--------------------------------------------------------------------------
  204.   # * Get Battler ID
  205.   #--------------------------------------------------------------------------
  206.   if !defined?(id); def id
  207.     actor? ? @actor_id : @enemy_id
  208.   end; end
  209.   #--------------------------------------------------------------------------
  210.   # * Get Max TP value
  211.   #--------------------------------------------------------------------------
  212.   def mtp
  213.     b = actor? ? $game_system.actor_tp[self.id] : $game_system.enemy_tp[self.id]
  214.     if actor? && PAC::TP::LEVEL
  215.       e = PAC::TP::LEVEL_GAIN[self.id] || PAC::TP::LEVEL_GAIN_DEFAULT
  216.       a = eval(e) * (self.level - 1) rescue 0
  217.       b += a
  218.       b += weapon_tp
  219.     end
  220.     b
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # * Alias for Max TP value
  224.   #--------------------------------------------------------------------------
  225.   def max_tp
  226.     mtp
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # * Get TP modifiers from equips
  230.   #--------------------------------------------------------------------------
  231.   def weapon_tp
  232.     return 0 if !actor?
  233.     t = 0
  234.     equips.each { |equip|
  235.       next if equip.nil?
  236.       n = 0
  237.       n += equip.tp_gain
  238.       n *= equip.tp_multiply
  239.       n = (n * equip.tp_percent) / 100
  240.       t += n
  241.     }
  242.     return t
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # * Fix TP rate for adjusted Max TP
  246.   #--------------------------------------------------------------------------
  247.   def tp_rate
  248.     @tp.to_f / max_tp
  249.   end
  250. end
  251.  
  252. #==============================================================================
  253. # ** Game_Battler
  254. #------------------------------------------------------------------------------
  255. #  A battler class with methods for sprites and actions added. This class
  256. # is used as a super class of the Game_Actor class and Game_Enemy class.
  257. #==============================================================================
  258.  
  259. class Game_Battler < Game_BattlerBase
  260.   #--------------------------------------------------------------------------
  261.   # * Initialize TP
  262.   #--------------------------------------------------------------------------
  263.   def init_tp
  264.     if actor?
  265.       e = PAC::TP::AIF[self.id] || PAC::TP::ACTOR_INIT_FORMULA
  266.     else
  267.       e = PAC::TP::EIF[self.id] || PAC::TP::ENEMY_INIT_FORMULA
  268.     end
  269.     self.tp = eval(e) rescue (rand * 25)
  270.   end
  271. end
  272.  
  273. #==============================================================================
  274. # ** Window_Base
  275. #------------------------------------------------------------------------------
  276. #  This is a super class of all windows within the game.
  277. #==============================================================================
  278.  
  279. class Window_Base < Window
  280.   #--------------------------------------------------------------------------
  281.   # * Draw TP
  282.   #--------------------------------------------------------------------------
  283.   def draw_actor_tp(actor, x, y, width = 124)
  284.     draw_gauge(x, y, width, actor.tp_rate, tp_gauge_color1, tp_gauge_color2)
  285.     change_color(system_color)
  286.     draw_text(x, y, 30, line_height, Vocab::tp_a)
  287.     draw_current_and_max_values(x, y, width, actor.tp.to_i, actor.mtp,
  288.       tp_color(actor), normal_color)
  289.   end
  290. end
  291.  
  292. #==============================================================================
  293. # ** Game_Interpreter
  294. #------------------------------------------------------------------------------
  295. #  An interpreter for executing event commands. This class is used within the
  296. # Game_Map, Game_Troop, and Game_Event classes.
  297. #==============================================================================
  298.  
  299. class Game_Interpreter
  300.   #--------------------------------------------------------------------------
  301.   # * Alter TP limit for enemy or actor
  302.   #--------------------------------------------------------------------------
  303.   def change_tp_limit(id, limit, type = :actor)
  304.     if type == :actor || type == :a
  305.       $game_system.actor_tp[id] = [limit, 0].max
  306.     elsif type == :enemy || type == :e
  307.       $game_system.enemy_tp[id] = [limit, 0].max
  308.     end
  309.   end
  310. end
  311.  
  312. #===============================================================================
  313. #
  314. # END OF SCRIPT
  315. #
  316. #===============================================================================
RAW Paste Data
Pastebin PRO Summer Special!
Get 60% OFF on Pastebin PRO accounts!
Top