FANDOM


Implementing Trick Room and Wonder Room
This tutorial is deprecated. It is no longer relevant to the latest version of Pokémon Essentials.

This tutorial was written by -Playerin-. Please give credit.

Click here for more tutorials!


This tutorial explains how to implement the effects of Trick Room and Wonder Room in Pokémon Essentials v13.

Trick Room

Declaring the Trick Room enumeration

First off, we need to define the enumeration for the Trick Room effect in PBEffects. In PBEffects, add something like this to the list of effects:

TrickRoom         = 102

The actual number shouldn't matter, so as long as it is not being used by another effect.

As Trick Room is a move that affects all Pokémon on the field, we must add the following under def initialize in PokeBattle_ActiveSide:

@effects[PBEffects::TrickRoom] = 0

Implementing Trick Room's effect on battle

Now, we can implement the effect that Trick Room has in battle. Find def pbPriority in PokeBattle_Battle. Right above the comment

# Calculate each Pokémon's speed

add this boolean variable:

trickroom=false

Now we can check to see if Trick Room is active. Right after

quickclaw[i]=false if ignorequickclaw

add this:

trickroom=true if @battlers[i].pbOwnSide.effects[PBEffects::TrickRoom]>0

Finally, we need to have Trick Room impact the turn order if it is active. Find the following piece of code

            elsif speeds[temp[i]]!=speeds[temp[i-1]]
              cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? -1 : 1 #Rank higher to higher-speed battler
            else
              cmp=0
            end

and replace it with this:

            elsif speeds[temp[i]]!=speeds[temp[i-1]]
              if trickroom
                cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? 1 : -1 #Rank lower to higher-speed battler if trick room active
              else
                cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? -1 : 1 #Rank higher to higher-speed battler
              end
            else
              cmp=0
            end

The Function Code

Next, we need to make the move Trick Room actually activate its effect instead of simply doing nothing. In PokeBattle_MoveEffects, find the following piece of code:

class PokeBattle_Move_11F < PokeBattle_UnimplementedMove
# Not implemented yet.
end

and replace it with this:

class PokeBattle_Move_11F < PokeBattle_Move
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    if attacker.pbOwnSide.effects[PBEffects::TrickRoom]>0 ||
       attacker.pbOpposingSide.effects[PBEffects::TrickRoom]>0
      attacker.pbOwnSide.effects[PBEffects::TrickRoom]=0
      attacker.pbOpposingSide.effects[PBEffects::TrickRoom]=0
      @battle.pbDisplay(_INTL("The twisted dimensions returned to normal!"))
    else
      pbShowAnimation(@id,attacker,opponent,hitnum,alltargets,showanimation)
      attacker.pbOwnSide.effects[PBEffects::TrickRoom]=5
      attacker.pbOpposingSide.effects[PBEffects::TrickRoom]=5
      @battle.pbDisplay(_INTL("{1} twisted the dimensions!",attacker.pbThis))
    end
    return 0
  end
end

Implementing the 5-turn limit

Finally, we need to make sure that Trick Room doesn't run indefinitely. In PokeBattle_Battle, find the following comment:

    # Trick Room - should go here

Right after this, add this piece of code:

    if sides[0].effects[PBEffects::TrickRoom]>0 ||
       sides[1].effects[PBEffects::TrickRoom]>0
      trickroom=[sides[0].effects[PBEffects::TrickRoom],
               sides[1].effects[PBEffects::TrickRoom]].max
      trickroom-=1
      sides[0].effects[PBEffects::TrickRoom] = trickroom
      sides[1].effects[PBEffects::TrickRoom] = trickroom
      if trickroom==0
        pbDisplay(_INTL("The twisted dimensions returned to normal."))
      end
    end

Congratulations, Trick Room now has an effect!

Wonder Room

Declaring the Wonder Room enumeration

Like Trick Room, we need to define an enumeration for the Wonder Room effect. In PBEffects, add something like this to the list of effects:

WonderRoom         = 103

Again, the actual number shouldn't matter so as long as it is not being used by another effect.

Since Wonder Room also affects all Pokémon on the field, add the following under def initialize in PokeBattle_ActiveSide:

@effects[PBEffects::WonderRoom] = 0

The Function Code

Now it's time to make the move Wonder Room activate its effect and switch the Defense and Sp. Defense stats of everyone on the field. In PokeBattle_MoveEffects, find the following piece of code:

class PokeBattle_Move_124 < PokeBattle_UnimplementedMove
# Not implemented yet.
end

and replace it with this:

class PokeBattle_Move_124 < PokeBattle_Move
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    if attacker.pbOwnSide.effects[PBEffects::WonderRoom]>0 ||
       attacker.pbOpposingSide.effects[PBEffects::WonderRoom]>0
      attacker.pbOwnSide.effects[PBEffects::WonderRoom]=0
      attacker.pbOpposingSide.effects[PBEffects::WonderRoom]=0
      @battle.pbDisplay(_INTL("The area returned to normal!"))
      for i in 0...4
        if @battle.battlers[i].effects[PBEffects::WonderRoom]
            @battle.battlers[i].effects[PBEffects::WonderRoom]=false
            s=@battle.battlers[i].defense
            @battle.battlers[i].defense=@battle.battlers[i].spdef
            @battle.battlers[i].spdef=s
        end
      end
    else
      pbShowAnimation(@id,attacker,opponent,hitnum,alltargets,showanimation)
      attacker.pbOwnSide.effects[PBEffects::WonderRoom]=5
      attacker.pbOpposingSide.effects[PBEffects::WonderRoom]=5
      @battle.pbDisplay(_INTL("It created a bizarre area in which the Defense and Sp. Def stats are swapped!"))
      for i in 0...4
        if !@battle.battlers[i].effects[PBEffects::WonderRoom]
            @battle.battlers[i].effects[PBEffects::WonderRoom]=true
            s=@battle.battlers[i].defense
            @battle.battlers[i].defense=@battle.battlers[i].spdef
            @battle.battlers[i].spdef=s
        end
      end
    end
    return 0
  end
end

Implementing the 5-turn limit

Again, like Trick Room, Wonder Room only lasts for 5 turns. In PokeBattle_Battle, find the following comment:

    # Wonder Room - should go here

Right after this, add this piece of code:

    if sides[0].effects[PBEffects::WonderRoom]>0 ||
       sides[1].effects[PBEffects::WonderRoom]>0
      wonderroom=[sides[0].effects[PBEffects::WonderRoom],
               sides[1].effects[PBEffects::WonderRoom]].max
      wonderroom-=1
      sides[0].effects[PBEffects::WonderRoom] = wonderroom
      sides[1].effects[PBEffects::WonderRoom] = wonderroom
      if wonderroom==0
        pbDisplay(_INTL("The area returned to normal."))
      end
    end

Applying the effects of Wonder Room to Incoming Pokémon

Finally, we need to make sure that Wonder Room will affect Pokémon sent out after it has been used. Find def pbInitEffects in PokeBattle_Battler. Right under:

@effects[PBEffects::WeightMultiplier] = 1.0

add this initialization for the Wonder Room effect on the battler.

    @effects[PBEffects::WonderRoom]       = false
    if self.pbOwnSide.effects[PBEffects::WonderRoom] > 0
        @effects[PBEffects::WonderRoom]   = true
        s=@defense
        @defense=@spdef
        @spdef=s
    end

Congratulations! Wonder Room should now function properly!

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.