Wonderful :)
So, you initialize the new attribute in class PokeBattle_Pokemon, like the previous ones:
Code:
attr_accessor :numPokemonsPutKO
and add some code to this: (this is an extension of the initialisation function I gave you in a previous post).
Code:
alias __darkraimaker__init initialize
def initialize(*args)
__darkraimaker__init(*args)
@totalDamageTaken = 0
@totalDamageDone = 0
@numPokemonsPutKO = 0
end
The function
pbFaint() "knows" only the fainting Pokémon, and not the Pokémon that made it faint.
My idea was to look for abilities or items that trigger when a Pokémon faints, and that has an effect on the Pokémon that killed it. For example: Moxie.
Moxie is defined as a Battle Handler (which is a convenient way to add effects to a specific script without changing anything in the functions that control battle):
Code:
BattleHandlers::UserAbilityEndOfMove.add(:MOXIE,
Battle Handlers are called in functions of the form trigger[Battle Handler Name]:
Code:
def self.triggerUserAbilityEndOfMove(ability,user,targets,move,battle)
This function is called only once in the code, in the function:
Code:
def pbEffectsAfterMove(user,targets,move,numHits)
As this is a big function, I suggest to make another function, for example written in the script that contains the initialize function I mentioned above.
So, find the lines:
Code:
# Consume user's Gem
if user.effects[PBEffects::GemConsumed]>0
# NOTE: The consume animation and message for Gems are shown immediately
# after the move's animation, but the item is only consumed now.
user.pbConsumeItem
end
and below, paste this:
Code:
# Register when a Pokemon faints:
pbRegisterFaintedPokemon(user,targets,move,@battle)
and in the separate script, paste this:
Code:
class PokeBattle_Battler
def pbRegisterFaintedPokemon(user,targets,move,battle)
targets.each { |b| user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted }
end
end
By the way, your total code should look like this:
Code:
# In a separate script:
class PokeBattle_Pokemon
attr_accessor :totalDamageTaken
attr_accessor :totalDamageDone
attr_accessor :numPokemonsPutKO
alias __darkraimaker__init initialize
def initialize(*args)
__darkraimaker__init(*args)
@totalDamageTaken = 0
@totalDamageDone = 0
@numPokemonsPutKO = 0
end
end
class PokeBattle_Battler
def pbRegisterFaintedPokemon(user,targets,move,battle)
targets.each { |b| user.pokemon.numPokemonsPutKO += 1 if b.damageState.fainted }
end
end
+ the small edits to this function:
Code:
def pbProcessMoveHit(move,user,targets,hitNum,skipAccuracyCheck)
which contain only:
Code:
b.pokemon.totalDamageTaken += b.damageState.hpLost
user.pokemon.totalDamageDone += b.damageState.hpLost