TP gain on being hit

Status
Not open for further replies.

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
I know that there must be a formula somewhere in the default scripts which works out how much TP an actor gains when hit by the enemy.

I have 2 questions
First (obviously) can someone tell me where that particular formula is?
Second is it possible to give different amounts of TP gain to different actors? As far as I can see it is the same for everyone.

Thanks.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
For RMMV it would be
Game_Battler.prototype.gainTp = function(value) {
this._result.tpDamage = -value;
this.setTp(this.tp + value);
};. Maybe it's placed the same in VXAce.


Edit: VXAce:
#--------------------------------------------------------------------------
# * Charge TP by Damage Suffered
#--------------------------------------------------------------------------
def charge_tp_by_damage(damage_rate)
self.tp += 50 * damage_rate * tcr
end


in Game_Battler. So yes, it is possible to alter based on actor if you redefine it.
 
Last edited:
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Poryg So I can change that 50 in the formula to what I want and then change the TCR in the usual way to adapt the base rate to the individual actor. Correct?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
That is one solution.
Another solution is to recode it like this (I'm sorry I will not provide a working code, but an illustratory one instead, but I don't know how VXAce's Ruby works)

Code:
#--------------------------------------------------------------------------
# * Charge TP by Damage Suffered
#--------------------------------------------------------------------------
def charge_tp_by_damage(damage_rate)
if self.actorId == 1
self.tp += 50 * damage_rate * tcr + 50
else if self.actorId == 2
self.tp += 50 * damage_rate * tcr + 20
else
self.tp += 50 * damage_rate * tcr
end
What I attempted to do was to create a tree and influencing the value gained by a flat value in the end: Actor 1 gains 50 extra TP, actor 2 gains 20 extra TP and the rest gains normal TP. However, this code will probably not work due to not being formatted correctly.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Depending on how you want to adjust it for each actor, I'd consider using note tags to set a "factor" and then use that in the formula.

Do enemies use TP as well, or is it just actors?
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz Yes, enemies use it as well, but I could always change that if it caused big complications.
@Poryg Thanks for the suggestion.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
What kind of formula are you planning to use, and how will it differ for each individual? Give me some examples and I'll see if I can come up with something.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz Here's where things might get a bit complicated, and it sounds a bit vague because I needed to know what was possible before coming up with ways to use that possibility. However, just as examples,

Ideally, I would like to be able to determine different TP gain rates depending on the enemy. For example, ordinary enemies give whatever rate I set the TCR to for the particular actor. However, bosses could give a different rate, higher or lower.

Or an actor's gain could be dependent on either they've been hit by a physical skill or a magic skill.

I don't think I can manipulate TP gain via the damage formula, but I had wanted to give an enemy a skill which prevented TP gain if an actor was inflicted with a certain state.

I was looking to see how flexible the formula might be, but now that I've seen it, I don't think it will be able to do things like that.


EDIT
The other thing I meant to ask is - what is the "damage_rate"? The only instances of this precise term that I can find for this in the default scripts are the little section dealing with TP gain, I can't find where it is defined.
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
You couldn't find where it's defined, because it isn't. It's just a value that's passed into the method.

It is the amount of hp damage / maximum hp.

Similar to hp_rate, which is current_hp / maximum_hp.

Code:
class Game_Battler < Game_BattlerBase
  def execute_damage(user)
    on_damage(@result.hp_damage) if @result.hp_damage > 0
    <stuff>
  end

  def on_damage(value)
    <stuff>
    charge_tp_by_damage(value.to_f / mhp)
  end

  def charge_tp_by_damage(damage_rate)
    self.tp += 50 * damage_rate * tcr
  end
end
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz Hmm, so standard Kes (script idiot) question. Does this mean that effectively it can't be changed? It is what it is for everyone?

EDIT
I thought the bit of code you posted was to illustrate the answer about damage_rate, but when I look at it, I see it's not (the "stuff" was the giveaway). So what do I do with that code?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
The bit of code was just to answer the damage_rate question. I removed the other lines because they're irrelevant for that discussion. You don't "do" anything with it - it was just to show you that it's passed into the function, and how it's calculated before we get to that point.

I'm sure you can do what you want to do, but the bit that makes it difficult is that you want to refer to the attacker or the skill being used, and by the time we get down to this level of detail, those references have been left behind. All we really know about is the actor who's taking the damage. You would need to either pass that info down as well, which means modifying the chain of methods from the top down to this level, or to save those details in a variable so they could be referenced here. Either way, it's a bit more difficult than just referring to something on the actor itself. It's made more complicated in that, if we do change the methods to pass more info down, that could impact on any other scripts you have that might want to use or alias the same methods. I'd probably go with the variable approach rather than passing arguments down.

But I'd have to think about it some more before I could give you a solution.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz
If you have the time, could you show me an example of the use of variables for this so that I can understand better what you mean?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
variables as in Ruby variables, not $game_variables.

You would need to create a variable on the Game_Battler class to save the skill and/or the attacker. Then when you get to the calculate the damage, you can save the skill and/or attacker into those variables. That will make them available in the TP method. Then you can make use of notes or other information in the database.

I think you need to better define what you want to do with TP before going any further with how to do it.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Shaz Here is the thing that I have worked out most clearly in my head.

It would be interesting to have a "note" that you can place on certain monsters and this note changes the formula. For instances bosses allow for faster TP gains.
Doing it for skills would overcomplicate everything IMO.
The formula is this:
self.tp += 50 * damage_rate * tcr

So let it be an addition factor:
self.tp += 50 * damage_rate * tcr + note

where note is a real (1,2,3 etc.)
In this way if you want a boss to guarantee a +10TP on the default formula for each thing it does, you just do note = 10

I hope that makes sense.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Sounds good. I'll see what I can come up with after I get home from work.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
Thank you. With the joys of differing time zones I can sleep while you're working.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
okay, wish I could copy/paste this, but it's on my laptop not connected to the internet, and I've got the web page open on my work computer. Hopefully there won't be any typos.

Put <tp_add_factor: 20> into your enemy's note box, to get an extra 20TP from that enemy each time it attacks.

Code:
# TP Add Factor
# by Shaz
#
# Place <tp_add_factor: x> (where x is an integer) into an enemy's note tag.
# When a party member is attacked by that enemy, that number will be
# added to the resulting TP.

class Game_Battler < Game_BattlerBase
  alias shaz_tp_initialize initialize
  def initialize
    shaz_tp_initialize
    @tp_user = nil
  end

  alias shaz_tp_execute_damage execute_damage
  def execute_damage(user)
    @tp_user = user
    shaz_tp_execute_damage(user)
    @tp_user = nil
  end

  def charge_tp_by_damage(damage_rate)
    self.tp += 50 * damage_rate * tcr + (@tp_user ? @tp_user.tp_add_factor : 0)
  end
end

class Game_Actor < Game_Battler
  def tp_add_factor
    0
  end
end

class Game_Enemy < Game_Battler
  def tp_add_factor
    $data_enemies[@enemy_id].note =~ /<tp_add_factor:\s*(\d+)>/i ? $1.to_i : 0
  end
end
I tested and it seems to work okay. If you leave the note tag out, it'll just add 0.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
You are incredible! Thank you so much. I shan't be able to test it for a while as I'm getting ready to go to work. I'll edit this with the results when I do.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
How did you go?
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
I have just this minute finished testing, and it went perfectly. So you can chalk this up as another success.

Thank you very much, greatly appreciated.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,981
Members
137,563
Latest member
cexojow
Top