• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Copying Stat Changes

  • 220
    Posts
    14
    Years
    • Seen Nov 29, 2021
    So I've the idea for an ability where any stat changes an opponent makes also applies to the pokemon with the ability.

    Now I know I could trawl through every instances of a stat change, but is there an easier way, perhaps modifying whichever function lowers stats?
     
    Before any coding is to be done, consider the following scenarios (attacker being the Pokémon with this ability):
    • If the attacker (or an ally) causes the change in the opponent's stats (e.g. using Growl or Swagger), would the ability copy the reductions/increases?
    • The ability can also work against the attacker if for example the opponent uses Close Combat or Overheat and suffers the negative effects.
    • Some abilities can trigger a change in stats (e.g. Competitive, Defiant, Justified and Intimidate to name a few).
    • The opponent has Mold Breaker or Contrary; or the attacker (or an ally) uses Topsy-Turvy to invert all the opponent's stat changes. How would your ability work?
     
    So I've the idea for an ability where any stat changes an opponent makes also applies to the pokemon with the ability.

    Now I know I could trawl through every instances of a stat change, but is there an easier way, perhaps modifying whichever function lowers stats?

    Consider some moves you could copy or see what you can get out of that. It sounds to me like you want to make a passive-type Psych Up attack, and judging by past replies on this board it seems as though you also want it to negatively affect the Pokemon with the ability as well.

    Look through Psych Up's code and see what you can make out of that. I bet this is what you're looking for.
     
    Note that this code is untested.

    PokeBattle_BattlerEffects, line 817, starts the function pbReduceStatBasic.
    Code:
      def pbReduceStatBasic(stat,increment,attacker=nil,moldbreaker=false,ignoreContrary=false[COLOR="red"],ignoreroleplayer=false[/COLOR])
        if !moldbreaker # moldbreaker is true only when Roar forces out a Pokémon into Sticky Web
          if !attacker || attacker.index==self.index || !attacker.hasMoldBreaker
            if hasWorkingAbility(:CONTRARY) && !ignoreContrary
              return pbIncreaseStatBasic(stat,increment,attacker,moldbreaker,true)
            end
            increment*=2 if hasWorkingAbility(:SIMPLE)
          end
        end
        increment=[increment,6+@stages[stat]].min
        PBDebug.log("[Stat change] #{pbThis}'s #{PBStats.getName(stat)} fell by #{increment} stage(s) (was #{@stages[stat]}, now #{@stages[stat]-increment})")
        @stages[stat]-=increment
        [COLOR="Red"]if !ignoreroleplayer
          for i in 0...4
            if @battle.battlers[i] != self &&
               @battle.battlers[i].hasWorkingAbility(:ROLEPLAYER)
              @battle.battlers[i].pbReduceStatBasic(stat,increment,nil,false,false,true)
            end
          end
        end[/COLOR]
        return increment
      end

    This checks, every time you use the pbReduceStatBasic function, if any other Pokemon on the field have the ability (which I've called "Roleplayer"), and if they do, uses pbReduceStatBasic on them as well. The ignoreroleplayer attribute is added to prevent the function from infinitely calling itself in an endless loop, in the case of there being two Roleplayer Pokemon on the field at once.

    You want to add the red bits. You'll also want to something similar for the following functions:
    pbReduceStat(
    pbReduceStatWithCause(
    pbReduceAttackStatIntimidate(
    pbIncreaseStatBasic(
    pbIncreaseStat(
    pbIncreaseStatWithCause(
     
    Well ReduceStat, ReduceStatWithCause, and ReduceAttackStatIntimidate all seem to call upon ReduceStatBasic, so I may only have to modify two of those scripts. While try and then report back, thanks!

    EDIT: Good news and bad news! Good news is it works. Bad news is it doesn't do as I do: report back :P
     
    Last edited:
    Back
    Top