• 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.

Check whether a Pokémon or Move of a certain Type is in party

11
Posts
5
Years
  • Age 34
  • Seen Jul 3, 2020
Hi there, everyone!

I want to share with you some scripts that I made while working on my Kanto map that I think could be useful to other people when making their own games, since you can definitely find some nice and cool applications of these scripts in all sorts of situations that can happen during the progression of your game's story.
These scripts check the Type of your Pokémon in party, the Type of the Moves they currently know and whether a Move has an effect like thaws the user, is sound-based or has high crit chance, etc. That said, it's simple and seems it doesn't make anything special, so let me first tell you some examples that I had in mind when making these scripts:
- One use can be to give the player different ways to overcome a situation where they are stuck somewhere and they need a certain Type of Pokémon or Move in party in order to progress; imagine that in your game you want the player to get into an enemy base but there's a tight surveillance, so you want to give different ways of sneaking in, like trying to break a wall using a Fighting-type Pokémon or Move, or you can put some vines on the side of the building and if the player has a Grass-type Pokémon they can use that Pokémon's power to make the vines grow stronger and get long enough to be in reach of the character so they can start climbing safely;
- You can limit access to a certain area where you need a certain Type to unlock a door/path and find a secret room filled with treasures, items, rare Pokémon, special NPCs, etc;
- You can give the player some optional "utility" interactions like giving power to a device that can heal your party in an abandoned facility, or open a shortcut so the player doesn't need to go through tall grass every time they need to pass in that area;
- Force the player to have a certain Type to get access to an important building like Brock's Gym in Let's Go Pikachu/Eevee, otherwise they can't progress the story or will miss that optional area/dungeon;
- Make a water current that can't be Surfed on, so the player needs a Rock-type Move to slow down the current or an Ice-type Move to freeze the water and make an icy bridge.
The possibilities are huge, you can make everything you want, so now let's start to explain how the scripts work!

If you don't already have a script section where you store extra scripts like this one, do this: press F11 to open the Script Editor in RPG Maker XP, on the left scroll all the way down and right-click on "Main" at the bottom, then click on "Insert", type a name of your choice in the textbox below (I used "Additional Scripts"), then copy-paste the code below.

This is the code, I also made a pastebin link if you need it (raw text here).
Code:
#Checks whether a Pokémon in party has a certain Type
def pbHasPokemonType?(type)
  if type.is_a?(String) || type.is_a?(Symbol)
    type=getID(PBTypes,type)
  end
  for pokemon in $Trainer.party
    next if pokemon.isEgg?
    if pokemon.hasType?(type)
      pbSet(1,$Trainer.party.index(pokemon))
      pbSet(3,pokemon.name)
      return true
    end
  end
  pbSet(1,-1)
  pbSet(3,"")
  return false
end

#Checks whether the selected Pokémon knows a Move of a certain Type
#MUST BE USED after pbChoosePokemon or pbChooseNonEggPokemon or similar
def pbHasMoveType?(type)
  if type.is_a?(String) || type.is_a?(Symbol)
    type=getID(PBTypes,type)
  end
  pokemon = pbGetPokemon(1)
  for move in pokemon.moves
    if move.type == type && move.id != 0
      pbSet(2,pokemon.moves.index(move))
      pbSet(4,PBMoves.getName(move.id))
      return true
    end
  end
  pbSet(2,-1)
  pbSet(4,"")
  return false
end

#Checks whether a Pokémon in party knows a Move of a certain Type
def pbPartyHasMoveType?(type)
  if type.is_a?(String) || type.is_a?(Symbol)
    type=getID(PBTypes,type)
  end
  for pokemon in $Trainer.party
    next if pokemon.isEgg?
    for move in pokemon.moves
      if move.type == type && move.id != 0
        pbSet(1,$Trainer.party.index(pokemon))
        pbSet(2,pokemon.moves.index(move))
        pbSet(3,pokemon.name)
        pbSet(4,PBMoves.getName(move.id))
        return true
      end
    end
  end
  pbSet(1,-1)
  pbSet(2,-1)
  pbSet(3,"")
  pbSet(4,"")
  return false
end

#Checks whether a Pokémon in party has a certain Type or knows a Move
#of a certain Type
def pbPartyHasTypeOrMoveType?(type)
  if pbHasPokemonType?(type)
    ret = 0
  else
    if pbPartyHasMoveType?(type)
      ret = 1
    else
      ret = -1
    end
  end
  return ret
end

#Checks a Pokémon's Moves and stores their names in variables 30, 31, 32 and 33
#MUST BE USED after pbChoosePokemon or pbChooseNonEggPokemon or similar
def pbMoveNames
  pokemon = pbGetPokemon(1)
  i = 0
  for move in pokemon.moves
    pbSet((30 + i),(move.id != 0 ? PBMoves.getName(move.id) : ""))
    i += 1
  end
end

#Easier and shorter method to get infos of a Move
#MUST BE USED after pbChoosePokemon or pbChooseNonEggPokemon or similar
#AND MUST BE USED after pbChooseMove
def pbMoveInfo
  return PokeBattle_Move.new(nil,pbGetPokemon(1).moves[pbGet(2)])
end

How it works

Usually you should use a def in a Conditional Branch, select the "Script" option and replace "type" in parentheses with the name of the Type you want, all in capital letters and with ":" before the name.
Example: "pbHasMoveType?(:PSYCHIC)", event screenshot example.

1) The first def pbHasPokemonType?(type) is not actually mine, it's made by Rot8er_ConeX in this thread, I just added those pbSet so you are able to see the name of the Pokémon. What this script does is to look in your party for a Pokémon of the specified Type (either Type-1 or Type-2) and returns true if a Pokémon is found (only the first one found in your party's order, doesn't check whether the are more Pokémon of that Type), otherwise returns false. If true, the script stores in variable 1 the index of that Pokémon in your party and in variable 3 its name; if false, variable 1 is set to -1 and variable 3 becomes empty.

2) pbHasMoveType?(type) is used to check whether a selected Pokémon knows a Move of the specified Type. A Pokémon must be selected first, using pbChoosePokémon for example. Like the above def, it returns true if a Move of that Type is found, otherwise it returns false. If true, it stores in variable 2 the index of that Move, and in variable 4 the name of that Move; if false, variable 2 is set to -1 and variable 4 becomes empty. If the Pokémon knows two or more Moves of that Type, the script stops at the first it finds, so only the infos of the first Move are stored in variables 2 and 4.

3) pbPartyHasMoveType?(type) checks all the Moves your party knows and stops at the first Move of the specified Type that it finds. Unlike above, you don't need to use pbChoosePokemon because it automatically searches through the party. If a Move is found, it returns true and sets variables 1, 2, 3 and 4 to the index of the Pokémon, the index of the Move, the name of the Pokémon and the name of the Move respectively; if no Pokémon in your party knows a Move of that Type, it returns false and sets variables 1 and 2 to -1 and variables 3 and 4 become empty.

4) pbPartyHasTypeOrMoveType?(type) is a combination of the first and third def above (yes the name is long, sorry). First, the def pbHasPokemonType? is executed and if it returns true then this def returns 0, else if it returns false then pbPartyHasMoveType? is executed and if it returns true this def returns 1, otherwise this def returns -1. Sounds complicated, but basically I made it so that this def can give three different results so you'll know what variables will be changed.

5) pbMoveNames is a utility def that I added in case of necessity, it just stores the names of the Moves a Pokémon knows in variables 30, 31, 32 and 33. A Pokémon must be selected first with pbChoosePokémon or similar.

6) pbMoveInfo is a more convenient way to get infos of a Move instead of always typing the line it returns. To use it, you have to add a dot at the end and then use one of the def in the script section "PokeBattle_Move", under the "About the move" comment. For example, if you type "pbMoveInfo.canThawUser?" it will return true if the selected Move can thaw the user, otherwise returns false.

If you want to see some examples in action, I made a project with a tutorial map, nothing fancy, it's just to show you some basic applications. First, add some Pokémon to your party with the debug menu, then talk with the NPCs around and try to see all the different outcomes of their events.
In the upper half of the map, the first NPC on the left uses pbHasPokemonType?(:BUG); the second one uses pbHasMoveType?(:GROUND); the third one uses pbPartyHasMoveType?(:PSYCHIC); the fourth one uses pbPartyHasTypeOrMoveType?(:WATER)==0 and under "else" there's another Conditional Branch with pbPartyHasTypeOrMoveType?(:WATER)==1 since this def returns either -1, 0 or 1 unlike true or false for the other defs; the last one uses pbMoveInfo.canThawUser?.
The old man on the ground is sleeping, you can wake him up with a sound-based Move.
Next to the other old man, there are two types of rocks. The first one near him is a rock that can be broken simply by a Fighting-type Pokémon or Move, but here I was testing hasType?(type) which is a def already made by Maruno, it's part of Essentials, I just recently discovered it randomly so I put it in that event using pbGetPokemon(1).hasType?(:FIGHTING) to see if it worked, so there you have another way to check a Pokémon's Type; the second rock, up the stairs, blue in color, is a really tough one, so you specifically need a Fighting-type Pokémon, that knows a Fighting-type Move, which must be a damaging Move (i.e. either Physical or Special, not Status) and must have a minimum of 90 Power, and I could have also gone further by checking whether the Pokémon has a minimum number of Atk or SpAtk but it was too much as it is in my opinion, I was just testing if all of this could work together.
In the lower half of the map, on the left, I made some kind of (silly looking) ravine, the guard there will stop you because it's dangerous but if you have a Pokéon that knows a Rock-type Move it will let you make a bridge and pass. Of course you can do a better looking and longer bridge, don't use a single tile like I did! On the right there's a biker that needs some Electric power for his bike, go help him, you won't regret it!
Download link: https://mega.nz/#!cY1iyabK!VTRwIcOoKSKRw4gkzOYrxDYSPA79sbz9pMKpWc2DhpQ

The idea behind all this was that at first I just wanted to see if I was able to make this kind of scripts after seeing a similar feature while playing Pokémon Prism, the part where you need an Electric-type Pokémon in party to give power to a battery and light a dark cave, basically working like HM Flash, then I tried to expand from there and make some other couple of scripts and optimize things a little bit... and they work! Also, thanks a lot again to Rot8er_ConeX, with his script I understood how to do what I wanted to make, so big credits to him!

Thanks for checking my scripts, feel free to use them in your game and please show me your events when they're done! Probably you'll find other usage that I didn't think of, I definitely want to see them! (-:
 
Back
Top