TP Gain/Loss Manipulation by Certain Damage Element

Hi, I'm trying to customize the TP system as elemental meter to trigger super special skill's execution. This TP, starting at 0 every battle, only increases from elemental damage, in my case is FIRE, ICE, and THUNDER. This TP also decreases by elemental damage under certain conditions.

For instance:

Turn 0 - TP = 0

Turn 1 - Battler A gets hit by FireBall (FIRE damage), TP (red gauge) increases

Turn 2 - Battler A gets hit by IceArrow (ICE damage), TP (red gauge) decreases (if damage calculation exceeds amount of TP gained                           from FIRE damage last turn, TP (red gauge) becomes 0 and TP (blue gauge) increases in place of red gauge)

So, ICE and THUNDER damage decreases TP gained by FIRE damage, and vice versa with FIRE and ICE to THUNDER and FIRE and THUNDER to ICE.

I've tried looking into the codes and find some bits of useful methods I assume are related to TP and elemental damage

class Game_Battler < Game_BattlerBase def charge_tp_by_damage(damage_rate) self.tp += 50 * damage_rate * tcr end def item_element_rate(user, item) if item.damage.element_id < 0 user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements) else element_rate(item.damage.element_id) end endBut I don't know how to create and implement a new method or overriding one to manipulate TP in such a way. A solution I have in mind is to have 3 flags (true/false) for three elements and the if...else method such as

 

if fire is true && element is fire

    tp increases

else

    tp decreases

 

or sort of. My logic is kinda flawed... so please help me 😀 . Thank you.

 

EDIT:

Hmmm.. can I update some more, since I have sort of progress on tackling this issue and this question is related to the topic.

I'm using Yanfly Engine Ace v1.22 and now focusing on some specific methods that alter TP gauge's graphics (since TP gauge's color depends on elemental damage received by the battler)

 

Here is one method:

Code:
  #--------------------------------------------------------------------------  # overwrite method: draw_actor_tp  #--------------------------------------------------------------------------  def draw_actor_tp(actor, x, y, width = 124)    draw_gauge(x, y, width, actor.tp_rate, tp_gauge_color1, tp_gauge_color2)    change_color(system_color)    draw_text(x, y, 30, line_height, Vocab::tp_a)    change_color(tp_color(actor))    draw_text(x + width - 42, y, 42, line_height, actor.tp.to_i.group, 2)  end
draw_actor_tp(actor, x, y, width = 124) is called in this method:

#-------------------------------------------------------------------------- # overwrite method: draw_item #-------------------------------------------------------------------------- def draw_item(index) return if index.nil? clear_item(index) actor = battle_members[index] rect = item_rect(index) return if actor.nil? draw_actor_face(actor, rect.x+2, rect.y+2, actor.alive?) draw_actor_name(actor, rect.x, rect.y, rect.width-8) draw_actor_action(actor, rect.x, rect.y) draw_actor_icons(actor, rect.x, line_height*1, rect.width) gx = YEA::BATTLE::BATTLESTATUS_HPGAUGE_Y_PLUS contents.font.size = YEA::BATTLE::BATTLESTATUS_TEXT_FONT_SIZE draw_actor_hp(actor, rect.x+2, line_height*2+gx, rect.width-4) if draw_tp?(actor) && draw_mp?(actor) dw = rect.width/2-2 dw += 1 if $imported["YEA-CoreEngine"] && YEA::CORE::GAUGE_OUTLINE draw_actor_tp(actor, rect.x+2, line_height*3, dw) dw = rect.width - rect.width/2 - 2 draw_actor_mp(actor, rect.x+rect.width/2, line_height*3, dw) elsif draw_tp?(actor) && !draw_mp?(actor)---> draw_actor_tp(actor, rect.x+2, line_height*3, rect.width-4) else draw_actor_mp(actor, rect.x+2, line_height*3, rect.width-4) end endSo, I created a new method to alter TP gauge color with this.

#-------------------------------------------------------------------------- # new method: draw_elem_gauge #-------------------------------------------------------------------------- def draw_elem_gauge(actor,dx, dy, width, cy) change_color(system_color) if $game_variables[2] == 2 draw_gauge(dx, dy, width, actor.tp_rate, tp_gauge_color1, tp_gauge_color2) draw_text(dx+2, dy+cy, 30, line_height, "FIRE") elsif $game_variables[2] == 3 draw_gauge(dx, dy, width, actor.tp_rate, tp_gauge_color3, tp_gauge_color4) draw_text(dx+2, dy+cy, 30, line_height, "THDR") elsif $game_variables[2] == 4 draw_gauge(dx, dy, width, actor.tp_rate, tp_gauge_color5, tp_gauge_color6) draw_text(dx+2, dy+cy, 30, line_height, "ICE") end endAnd insert it into the script like this:

#-------------------------------------------------------------------------- # overwrite method: draw_actor_tp #-------------------------------------------------------------------------- def draw_actor_tp(actor, dx, dy, width = 124) cy = (Font.default_size - contents.font.size) / 2 + 1 #new method to draw TP gauge based on element draw_elem_gauge(actor, dx, dy, width,cy) #draw_text(dx+2, dy+cy, 30, line_height, Vocab::tp_a) change_color(tp_color(actor)) #draw_text(dx + width - 42, dy+cy, 42, line_height, actor.tp.to_i, 2) #disabled TP number display endAn annoying bug I find after multiple testing (I use Yanfly's Classical ATB Battle System) is this scenario:

Lets say at

Turn 4      - Battler A gets hit by FireBall (A's red gauge increases) << enemy turn

Turn 5      - Battler B gets hit by IceArrow (B's blue gauge increases) << enemy turn

Turn 6      - Battler A turn action (A's red gauge turns blue and its FIRE notification becomes ICE after done selecting whatever action I                              choose)

To be honest, I do not quite wholly understand the logic flow of Yanfly's Ace Battle Engine (how it updates every turn [especially ATB based turn] or the method sequence of which method is called first and so and so). This script is too long and becoming confusing the more you try to relate all the methods. So, can anyone please help me. I'm still trying to understand Ruby language. Hope I do not ask too much haha.
BUMP. 

Okay it seems I'm getting no replies, so maybe I change my question a bit more detailed and specific. This is sort of a small part of my solution I'm trying out for the issue addressed above.

1. How do you write a code line to initialize an array that has the same size of party members and stores 0 as default value?

2. Then how do you change value stored in that array by its index. Preferable method is like this:

    def name_of_method(index)

  #line code

  end

What I'm trying to achieve is to create an array similar to $game_party.battle_members which is a method that returns an array of actors but I don't really understand the Ruby array methods themselves such as array.select/array.collect, even after looking up in the web.

I appreciate any help and input.

P.S. If this post is getting into more script-support related, then I don't mind if it is being moved to Script Support Thread. Thank you

Original thread: https://forums.rpgmakerweb.com/threads/tp-gain-loss-manipulation-by-certain-damage-element.53617/