• 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.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • 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] How to change a battlers data mid-fight? v19.1

  • 6
    Posts
    3
    Years
    I'm trying to implement a custom ability that will cause a Pokémon to change into a completely different randomly generated Pokémon. For context, this Pokémon is only ever given to an NPC trainer. Example: The Pokémon comes out into battle turn 1, and the ability immediately selects a random Pokémon to transform into. The ability then functions similarly to imposter (reusing the respective Ability Handler), albeit without the 5 PP drawback and it copies the HP stat.

    This part of my script works fine, but the problem arises when the new Pokémon is switched out for whatever reason. This resets the Pokémon back to its original species, but I'd like for the Pokémon to be completely replaced by whichever randomly generated Pokémon is selected so that it can be switched out and retain all of the information for that randomly generated Pokémon.

    I'm assuming this is either because I reused some of the code for imposter and its coded to reset back to a ditto (or whatever its original species is) when its switched out, or the battle mechanics are set to function like that in general. Unfortunately, for some reason I haven't been able to locate where in the game this happens for the life of me. Does anyone know where/how to either
    A: Change the battle mechanics so that it won't reset the random battlers data back to its original data once it's switched out after it has transformed
    B: Completely replace all of the battlers data mid-fight so that the game doesn't keep the original species that it'll want to reset back to
    or perhaps even
    C: Some other viable solution I haven't considered yet

    I've been experimenting with this for hours now, and at this point I figure that I'm gonna hate myself if I don't just try posting this here. If something here doesn't make sense then feel free to let me know and I'll try to elaborate further. Any suggestions are appreciated.
     
    Hey, I'm not an expert on ruby and I have a few extra ruby plug-ins so take this with a grain of salt, but I came up with this code and I believe that it did what you were asking.
    if pbEnemyShouldWithdraw?(idxBattler)
    1.times don't { |i|
    pbResetData(idxBattler)
    }
    end
    $Trainer.party = $Trainer.party[idxBattler]
    end
     
    I'm trying to implement a custom ability that will cause a Pokémon to change into a completely different randomly generated Pokémon. For context, this Pokémon is only ever given to an NPC trainer. Example: The Pokémon comes out into battle turn 1, and the ability immediately selects a random Pokémon to transform into. The ability then functions similarly to imposter (reusing the respective Ability Handler), albeit without the 5 PP drawback and it copies the HP stat.

    This part of my script works fine, but the problem arises when the new Pokémon is switched out for whatever reason. This resets the Pokémon back to its original species, but I'd like for the Pokémon to be completely replaced by whichever randomly generated Pokémon is selected so that it can be switched out and retain all of the information for that randomly generated Pokémon.

    I'm assuming this is either because I reused some of the code for imposter and its coded to reset back to a ditto (or whatever its original species is) when its switched out, or the battle mechanics are set to function like that in general. Unfortunately, for some reason I haven't been able to locate where in the game this happens for the life of me. Does anyone know where/how to either
    A: Change the battle mechanics so that it won't reset the random battlers data back to its original data once it's switched out after it has transformed
    B: Completely replace all of the battlers data mid-fight so that the game doesn't keep the original species that it'll want to reset back to
    or perhaps even
    C: Some other viable solution I haven't considered yet

    I've been experimenting with this for hours now, and at this point I figure that I'm gonna hate myself if I don't just try posting this here. If something here doesn't make sense then feel free to let me know and I'll try to elaborate further. Any suggestions are appreciated.

    Actually a PokeBattler_Pokemon is not the same as a PokeBattle_Battler. The former is the Pokémon as it is in your team, and the latter is the Pokémon as it is in battle. Some attributes are synchronised between the Battler and the Pokémon (e.g. the status, the HP, the PP), but most attributes of the Battler are lost upon switching (e.g. stat boosts, any move effect, and in particular, Imposter...).

    SO, if you want to store the new Pokémon form, I suggest you add a specific attribute to PokeBattle_Pokemon (let's call this attribute @imitation; it should be an attr_accessor). It should be nil all the time, except when you send out the Pokémon with your custom ability. Then basically copy and adapt the code for Imposter (just readapt your code) so that it transforms your Pokémon to the one generated in the attribute @imitation. To access an attribute of PokeBattle_Pokemon from PokeBattle_Battler, use batter.pokemon.imitation, so the data is stored in the Pokémon, and not in the battler.
    You have two cases: if @imitation is nil, then choose a random Pokémon (as you wanted), and if @imitation is not nil, take the form of the imitation.
    Don't forget, at the end of the battle, to reset this attribute to nil, otherwise it will be stored forever.
     
    Back
    Top