• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • 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.

Adding Illusion

1,224
Posts
10
Years
  • I have most of the ability in, but I need help changing the pokemon back once the illusion is broken.

    In PokeBattle_Move I have

    Code:
    if opponent.effects[PBEffects::Illusion]==true
          opponent.effects[PBEffects::Illusion]=false
          @battle.pbDisplayPaused(_INTL("{1}'s Illusion broke!",opponent.name))
             end
    right before Justified, but I can't figure out what to add into it (if it would even be the right place) to change the graphic and name back. Help would be appreciated. Once I get past this step, I'll do a bit more testing and then try to make a tutorial on how to add it.

    Edit: Also having trouble getting the right name called when switching pokemon. Will hopefully eventually fix everything :/
    Edit2: Fixed the name call, as well as the name displayed next to the hp bar. Only thing to do now is change graphic and name when it breaks, code for double battles, and I think there might be an exp gain bug.
     
    Last edited:

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    How were the sprites changed in the first place?
    Since you're the only one who knows the answer to this, just revert it back.
    You can't just go about making the Pokémon look like something else without saving it's original look... If we had all the code you made, we can help better.
     
    1,224
    Posts
    10
    Years
  • How were the sprites changed in the first place?
    Since you're the only one who knows the answer to this, just revert it back.
    You can't just go about making the Pokémon look like something else without saving it's original look... If we had all the code you made, we can help better.

    Under PokeBattle_Battle I changed the "initialize player in single battle" to

    Code:
    #====================================
    # Initialize player in single battles
    #====================================
          sendout=pbFindNextUnfainted(@party1,0)
          if sendout<0
            raise _INTL("Player has no unfainted Pokémon")
          end
          playerpoke=@party1[sendout]
          illusionpoke=pbFindLastUnfainted(@party1,0)
          illusionpoke2=@party1[illusionpoke]
            if isConst?(playerpoke.ability,PBAbilities,:ILLUSION)
               pbDisplayBrief(_INTL("Go! {1}!",illusionpoke2.name))
          else pbDisplayBrief(_INTL("Go! {1}!",playerpoke.name))
          end
          @battlers[0].pbInitialize(playerpoke,sendout,false)
          if isConst?(playerpoke.ability,PBAbilities,:ILLUSION)
           pbSendOut(0,illusionpoke2) 
           else
          pbSendOut(0,playerpoke)
         end
        end

    pbFindLastUnfainted is a method I made

    Code:
    def pbFindLastUnfainted(party,start,finish=-1)
        finish=party.length if finish<0
        for i in start...finish
        next if party[i]
          return i if party[i].hp>0  && !party[i].egg?
      end
      return -1
        end

    Under PokeBattle_ActualScene I changed the line


    to

    Code:
    if isConst?(@battler.ability,PBAbilities,:ILLUSION)
          if $Trainer.party.length==6
          pokename=$Trainer.party[5].name
        elsif $Trainer.party.length==5
          pokename=$Trainer.party[4].name
          elsif $Trainer.party.length==4
          pokename=$Trainer.party[3].name
          elsif $Trainer.party.length==3
          pokename=$Trainer.party[2].name
          elsif $Trainer.party.length==2
          pokename=$Trainer.party[1].name
          else 
          pokename=$Trainer.party[0].name
        end
        else
        [email protected]
        end

    And then a few edits to the text displayed when switching/sending out pokemon.
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    Causes an error for me... Did you edit anything else?

    EDIT: Nevermind... It does what it's supposed to do, albeit, messy and you had a slight problem with you display if's... The code doesn't change the Pokémon though.
     
    Last edited:
    1,224
    Posts
    10
    Years
  • I added it in PBEffects

    Code:
    Illusion          = 109

    Set it to initialize as false in PokeBattle_ActiveSlider

    Code:
    @effects[PBEffects::Illusion]     =false

    In PokeBattle_Battler I added this under CloudNine

    Code:
    if isConst?(ability,PBAbilities,:ILLUSION)&& onactive
           self.effects[PBEffects::Illusion]=true
           if $Trainer.party.length==6
                pokename=$Trainer.party[5].name
            elsif   $Trainer.party.length==5
                pokename=$Trainer.party[4].name
            elsif   $Trainer.party.length==4
                pokename=$Trainer.party[3].name
            elsif $Trainer.party.length==3
                pokename=$Trainer.party[2].name
            elsif $Trainer.party.length==2
                pokename=$Trainer.party[1].name
            else 
                pokename=$Trainer.party[0].name
          end
           @name=pokename
           pbUpdate(true)
           end

    In PokeBattle_Battle replace def pbMessagesOnReplace(index,newpoke) with

    Code:
    def pbMessagesOnReplace(index,newpoke)
        party=pbParty(index)
        if pbOwnedByPlayer?(index)
    #     if !party[newpoke]
    #       p [index,newpoke,party[newpoke],pbAllFainted?(party)]
    #       PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
    #       for i in 0...party.length
    #         PBDebug.log([i,party[i].hp].inspect)
    #       end
    #       raise BattleAbortedException.new
    #     end
          lastpoke=pbFindLastUnfainted(@party1,0)
          opposing=@battlers[index].pbOppositeOpposing
          if opposing.hp<=0 || opposing.hp==opposing.totalhp
            if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION)
              pbDisplayBrief(_INTL("Go! {1}!",party[lastpoke].name))
              else
            pbDisplayBrief(_INTL("Go! {1}!",party[newpoke].name))
            end
          elsif opposing.hp>=(opposing.totalhp/2)
            if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION)
              pbDisplayBrief(_INTL("Do it! {1}!",party[lastpoke].name))
              else
            pbDisplayBrief(_INTL("Do it! {1}!",party[newpoke].name))
            end
          elsif opposing.hp>=(opposing.totalhp/4)
            if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION)
               pbDisplayBrief(_INTL("Go for it, {1}!",party[lastpoke].name))
              else
            pbDisplayBrief(_INTL("Go for it, {1}!",party[newpoke].name))
            end
          else
            if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION)
               pbDisplayBrief(_INTL("Your foe's weak!\nGet 'em, {1}!",party[lastpoke].name))
              else
            pbDisplayBrief(_INTL("Your foe's weak!\nGet 'em, {1}!",party[newpoke].name))
          end
          end
        else
    #     if !party[newpoke]
    #       p [index,newpoke,party[newpoke],pbAllFainted?(party)]
    #       PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
    #       for i in 0...party.length
    #         PBDebug.log([i,party[i].hp].inspect)
    #       end
    #       raise BattleAbortedException.new
    #     end
          owner=pbGetOwner(index)
          if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION)
                  pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",owner.fullname,party[lastpoke].name))
             else
          pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",owner.fullname,party[newpoke].name))
        end
        end
      end


    And then the part in my original post. And I'm fairly certain that's it.
     
    1,224
    Posts
    10
    Years
  • Causes an error for me... Did you edit anything else?

    EDIT: Nevermind... It does what it's supposed to do, albeit, messy and you had a slight problem with you display if's... The code doesn't change the Pokémon though.

    It's not supposed to change the pokemon, just the graphic that appears. I apologize, I'm not a very neat coder.
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    EDIT: Broken Code lol... Fix is a few posts down.
     
    Last edited:

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    So I just got a PM off someone and they told me this doesn't work... So I tested it... It doesn't lol... I'll re-write it and it'll be fine lol.

    First things first, we need to re-write mej71's new script, pbFindLastUnfainted()...
    Code:
      def pbLastUnfainted
        ret=$Trainer.party.length-1
        if ret>0
          ret-=1 if $Trainer.party[ret].hp<=0 && $Trainer.party[ret].egg?
        end
        return ret
      end
    Then in PokeBattle_Battle, paste this:
    Code:
    #====================================
    # Initialize player in single battles
    #====================================
          sendout=pbFindNextUnfainted(@party1,0)
          if sendout<0
            raise _INTL("Player has no unfainted Pokémon")
          end
          playerpoke=@party1[sendout]
          @battlers[0].pbInitialize(playerpoke,sendout,false)
          if isConst?(playerpoke.ability,PBAbilities,:ILLUSION)
            @battlers[0].effects[PBEffects::Illusion]=true
            i=pbLastUnfainted
            playerpoke=@party1[i]
            playerpoke.name=playerpoke.name
          end
          pbDisplayBrief(_INTL("Go! {1}!",playerpoke.name))
          pbSendOut(0,playerpoke)
        end
    #==================
    # Initialize battle
    #==================
    Then in PokeBattle_Move, above ABSORBBULB, paste this:
    Code:
            if isConst?(opponent.ability,PBAbilities,:ILLUSION) && pbIsPhysical?(movetype) && opponent.effects[PBEffects::Illusion]==true
                opponent.effects[PBEffects::Illusion]=false
                @battle.scene.pbChangePokemon(opponent,$Trainer.party[0])
                @battle.pbDisplay(_INTL("{1}'s Illusion broke!",opponent.name))
            end
    Overwrite def pbDisplayUseMessage(attacker), with this:
    Code:
      def pbDisplayUseMessage(attacker)
      # Return values:
      # -1 if the attack should exit as a failure
      # 1 if the attack should exit as a success
      # 0 if the attack should proceed its effect
      # 2 if Bide is storing energy
      if attacker.effects[PBEffects::Illusion]==true
        i=pbLastUnfainted
        @battle.pbDisplayBrief(_INTL("{1} used\r\n{2}!",$Trainer.party[i].name,name))
      else
        @battle.pbDisplayBrief(_INTL("{1} used\r\n{2}!",attacker.pbThis,name))
      end
        return 0
      end
    In PokeBattle_ActualScene, find def refresh, around line 710, overwrite everything between, shadow=PokeBattle_SceneConstants::BOXTEXTSHADOWCOLOR and if @showhp, with:
    Code:
        if isConst?(@battler.ability,PBAbilities,:ILLUSION) && @battler.effects[PBEffects::Illusion]==true
          i=pbLastUnfainted
          pokename=$Trainer.party[i].name
        else
          [email protected]
        end
        if @battler.name.split('').last=="♂" || @battler.name.split('').last=="♀"
          [email protected][0..-2]
        end
        pbSetSystemFont(self.bitmap)
        textpos=[
           [pokename,@spritebaseX+8,6,false,base,shadow]
        ]
        genderX=self.bitmap.text_size(pokename).width
        genderX+=@spritebaseX+14
        if @battler.effects[PBEffects::Illusion]==true && $Trainer.party[i].gender==0
          textpos.push([_INTL("♂"),genderX,6,false,Color.new(48,96,216),shadow])
        elsif @battler.effects[PBEffects::Illusion]==true && $Trainer.party[i].gender==1
          textpos.push([_INTL("♀"),genderX,6,false,Color.new(248,88,40),shadow])
        elsif @battler.effects[PBEffects::Illusion]==false && @battler.gender==1 # Female
          textpos.push([_INTL("♀"),genderX,6,false,Color.new(248,88,40),shadow])
        elsif @battler.effects[PBEffects::Illusion]==false && @battler.gender==0# Male
          textpos.push([_INTL("♂"),genderX,6,false,Color.new(48,96,216),shadow])
        end
        pbDrawTextPositions(self.bitmap,textpos)
        pbSetSmallFont(self.bitmap)
        textpos=[
           [_INTL("Lv{1}",@battler.level),@spritebaseX+202,8,true,base,shadow]
        ]
    In PBEffects, add:
    Code:
    Illusion          = xxx
    Where xxx, is the next number in the sequence... In PokeBattle_ActiveSide, add:
    Code:
    @effects[PBEffects::Illusion]    = false
    That should work now... Let me know if it doesn't.
     
    1,224
    Posts
    10
    Years
  • First of all, thank you so much for helping me.

    A couple things:The pokemon with Illusion is not able to attack until it is broken(including the turn it is broken), and when it's broken the name doesn't change.
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    That's no problem, you're helping the community a bit... However, Bulbapedia doesn't say that though... And the video I saw also shown the Pokémon attacking just fine.

    Bulbapedia said:
    Illusion is broken—causing the user to appear as their true species—when the user is damaged directly by an attack or when Illusion is negated or replaced.

    I assume Illusion is broken via a physical attack (not a status or special attack or item).

    This is my resource and how/why I wrote it like that, if you want it to act the way you said, feel free to edit it.
     
    1,224
    Posts
    10
    Years
  • That's no problem, you're helping the community a bit... However, Bulbapedia doesn't say that though... And the video I saw also shown the Pokémon attacking just fine.



    I assume Illusion is broken via a physical attack (not a status or special attack or item).

    This is my resource and how/why I wrote it like that, if you want it to act the way you said, feel free to edit it.

    Sorry, I meant that Zoroark is supposed to be able to attack, but is not able with this script. And the name is supposed to change back when the illusion breaks, but doesn't with the script.
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    Anyone else having the same problem?
    It works my end, maybe I missed something, I don't think so though... Maybe you copied something wrong or you have something from a previous script in a wrong place... I'll check what I posted and see if it's what I got.
     

    ~JV~

    Dev of Pokémon Uranium
    684
    Posts
    16
    Years
  • Anyone else having the same problem?
    It works my end, maybe I missed something, I don't think so though... Maybe you copied something wrong or you have something from a previous script in a wrong place... I'll check what I posted and see if it's what I got.

    Working as intended here.
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    JV is right, it works as it's supposed to... You've got something you're not supposed to somewhere.
     
    1,224
    Posts
    10
    Years
  • I found what caused my name issue, but I literally find no more mentions of illusion that do not match up to what your code, yet I still cannot attack prior to Illusion being broken.
     

    ~JV~

    Dev of Pokémon Uranium
    684
    Posts
    16
    Years
  • I found what caused my name issue, but I literally find no more mentions of illusion that do not match up to what your code, yet I still cannot attack prior to Illusion being broken.

    Well, if I understand correctly what is your problem, my best guess would be that you put the Illusion breaking section in the wrong place in the editor.
     
    1,224
    Posts
    10
    Years
  • Well, if I understand correctly what is your problem, my best guess would be that you put the Illusion breaking section in the wrong place in the editor.

    I don't believe so, it's between Weak Armor and Absorb Bulb. That both makes logical sense and is where nickalooose said to. I've checked the codes and placements multiple times, there doesn't seem to be any disparity or anything apparent that would cause this problem. And it's only the Illusion effect that causes the problem
     

    ~JV~

    Dev of Pokémon Uranium
    684
    Posts
    16
    Years
  • I don't believe so, it's between Weak Armor and Absorb Bulb. That both makes logical sense and is where nickalooose said to. I've checked the codes and placements multiple times, there doesn't seem to be any disparity or anything apparent that would cause this problem. And it's only the Illusion effect that causes the problem

    Well, if it's not that then my next guess would be that you messed up on the def pbDisplayUseMessage(attacker) modification bit. Did you put the "return 0" after the end of the "if" section?
    If you put it before the end then the move usage will only proc when you don't have illusion.
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    The problem would be in the display message part... I've seen your recent scripts and you like to put the second part (the else part) on the same line as the else, check it.
     
    Back
    Top