• Hi, Guest!
    Some images might be missing as we move away from using embedded images, sorry for the mess!
    From now on, you'll be required to use a third party to host images. You can learn how to add images here, and if your thread is missing images you can request them here.
    Do not use Discord to host any images you post, these links expire quickly!
Resource icon

Random_Pokémon 2017-08-13

Pokémon Essentials Version
v16.2 ➖
This script main purpose is to generate random Pokémon with the getRandomPokemon function. You can influence Species and moves with the appropriate white and blacklist. Random moves can be turned off. It's also possible to either set the level or have it generated randomly.

The function getRandomPokemon returns a PokeBattler_Pokemon ... so there is a function addPokemon that can add PokeBattler_Pokemon to your team/storage.

There are also the functions getAllPokemonList, filterUnevolved and filterType to help making whitelists and blacklists.

If you find a bug or feel like something is missing please write a comment.

For detailed description of the functions see docs:
  • getRandomPokemon(whitelist,blacklist,level,movewhitelist,moveblacklist)
    • Summary:
      • Returns a random Pokémon with random moves and level(optional)
    • Arguments:
      • whitelist:
        • An array of Pokémon or nil.
        • If an Array is given the script will choose a Pokémon out of the array.
        • If nil is given the script will choose out of all Pokémon.
        • Default: nil
      • blacklist:
        • An array of Pokémon or nil.
        • If an Array is given the script will not choose a Pokémon out of the array.
        • If nil is given the script will not blacklist any Pokémon.
        • Default: nil
      • level:
        • An Integer or nil
        • If an Integer is given the Pokémon will have that level.
        • If nil is given the Pokémon will have a random level between 0 and 100.
        • Default: nil
      • movewhitelist:
        • An array of Moves, false or nil.
        • If an Array is given the Pokémon will only have moves out of this Array.
        • If false is given the Pokémon will have it's natural moves(the ones a wild Pokémon on that level would have).
        • If nil is given the script will choose out of all Moves the Pokémon can learn by leveling up or tm.
        • Default: nil
      • moveblacklist:
        • An array of Moves or nil.
        • If an Array is given the Pokémon will not have a Moves out of the array.
        • If nil is given the script will not blacklist any Moves.
        • Default: nil
    • return value:
      • The generated Pokémon of the type PokeBattle_Pokemon
  • addPokemon(pokemon)
    • Summary:
      • Places the given Pokémon in the players team/storage. It does the same as pbAddPokemon. The difference it that it takes a PokeBattle_Pokemon as argument which is returned by getRandomPokemon.
    • Arguments:
      • pokemon:
        • A PokeBattle_Pokemon object
        • This is the Pokémon to be added.
    • return value:
      • none
  • getAllPokemonList
    • Summary:
      • Returns a list of all Pokémon defined in the PBS file pokemon.txt. You may want to use this method to generate a whitelist with all Pokémon.
    • Arguments:
      • none
    • return value:
      • A list of Integers that represent the dex number of all Pokémon.
  • filterUnevolved(pokemonList)
    • Summary:
      • Returns a list of all unevolved Pokeémon in pokemonList.
    • Arguments:
      • pokemonList:
        • An array of Integer or PBSpecies
        • An array of Pokémon. This is the array to be filtered.
    • return value:
      • A list of Integers that represent the dex number of the unevolved Pokémon.
  • filterType(pokemonList, type1, type2)
    • Summary:
      • Returns a list of all Pokémon in pokemonList of the given type(s).
    • Arguments:
      • pokemonList:
        • An array of Integer or PBSpecies
        • An array of Pokémon. This is the array to be filtered.
      • type1:
        • PBTypes
        • The type to filter for.
      • type2:
        • PBTypes, nil or false
        • When a type is given only Pokémon with the two given types are returned.
        • When nil is given any Pokémon with type1 as type are returned.
        • When false is fiven only Pokémon that are only type1 are returned.
    • return value:
      • An array of Integers that represent the dex number of the Pokémon of the given type(s).
  • getAllPossibleMoves(pokemon)
    • Summary:
      • This method returns a list of the ids of all natural and tm moves the Pokémon can learn without taking level into account.
    • Arguments:
      • pokemon:
        • PokeBattle_Pokemon
        • The Pokémon in question.
    • return value:
      • An array of Integers representing the ids of all moves that can be learned by the Pokémon.

This will add a level 5 unevolved pure grass type Pokémon that is not Celebi or Shaymin to the players team. The Pokémon will have it's natural moves.
Code:
whitelist = getAllPokemonList
whitelist = filterType(whitelist, PBTypes::GRASS,false)
whitelist = filterUnevolved(whitelist)
blacklist = [PBSpecies::CELEBI, PBSpecies::SHAYMIN]
poke = getRandomPokemon(whitelist,blacklist,5,false)
addPokemon(poke)

This will generate random a level 50 Pokémon with random moves out of all moves the Pokémon can learn(natural/tm) except the ones declared in the moveblacklist.
This was used in Pokemon Battle Island. Although there is a different whitelist/moveblacklist.

Code:
whitelist = [PBSpecies::ARCEUS, PBSpecies::BLAZIKEN, PBSpecies::DARKRAI,
		PBSpecies::DEOXYS, PBSpecies::DIALGA, PBSpecies::GENESECT,
		PBSpecies::GIRATINA, PBSpecies::GROUDON, PBSpecies::HOOH,
		PBSpecies::KYOGRE, PBSpecies::KYUREM, PBSpecies::LANDORUS,
		PBSpecies::LUGIA, PBSpecies::MANAPHY, PBSpecies::MEWTWO,
		PBSpecies::PALKIA, PBSpecies::RAYQUAZA, PBSpecies::RESHIRAM,
		PBSpecies::THUNDURUS, PBSpecies::TORNADUS, PBSpecies::ZEKROM]
moveblacklist = [PBMoves::EMBARGO, PBMoves::FLING, PBMoves::SPLASH,
		 PBMoves::STRUGGLE, PBMoves::HOWL, PBMoves::HARDEN,
 
poke = getRandomPokemon(whitelist,nil,50,nil,moveblacklist)

It's better to use this link to copy the script. Be sure to copy the RAW Paste Data.

Code:
#============================================================
#Random_Pokemon script by leilou
#
#This script is ment to help to create a random Pokémon in Pokémon Essentials
#
#Pokémon Essentials is created by Poccil, based on Flameguru's 
#Pokémon Starter Kit and managed and updated by Maruno
#
#I don't claim this script to be perfect. 
#Please report bugs at the resources thread on Relic Castle.
#=============================================================
#
#functions:
#
# getRandomPokemon(whitelist,blacklist,level,movewhitelist,moveblacklist)
#   Summary:
#	 Returns a random Pokémon with random moves and level(optional)
#   Arguments:
#	 whitelist:
#	   An array of Pokémon or nil. 
#	   If an Array is given the script will choose a Pokémon out of the array.
#	   If nil is given the script will choose out of all Pokémon.
#	   Default: nil
#	 blacklist:
#	   An array of Pokémon or nil. 
#	   If an Array is given the script will not choose a Pokémon out of the array.
#	   If nil is given the script will not blacklist any Pokémon.
#	   Default: nil
#	 level:
#	   An Integer or nil
#	   If an Integer is given the Pokémon will have that level.
#	   If nil is given the Pokémon will have a random level between 0 and 100.
#	   Default: nil
#	 movewhitelist:
#	   An array of Moves, false or nil. 
#	   If an Array is given the Pokémon will only have moves out of this Array.
#	   If false is given the Pokémon will have it's natural moves(the ones a
#		 wild Pokémon on that level would have).
#	   If nil is given the script will choose out of all Moves the Pokémon can
#		 learn by leveling up or tm.
#	   Default: nil
#	 moveblacklist:
#	   An array of Moves or nil. 
#	   If an Array is given the Pokémon will not have a Moves out of the array.
#	   If nil is given the script will not blacklist any Moves.
#	   Default: nil
#   return value:
#	 The generated Pokémon of the type PokeBattle_Pokemon
#
# addPokemon(pokemon)
#   Summary:
#	 Places the given Pokémon in the players team/storage. 
#	 It does the same as pbAddPokemon. The difference it that it takes
#	 a PokeBattle_Pokemon as argument which is returned by getRandomPokemon.
#   Arguments:
#	 pokemon:
#	   A PokeBattle_Pokemon object
#	   This is the Pokémon to be added.
#   return value:
#	   none
#
# getAllPokemonList
#   Summary:
#	 Returns a list of all Pokémon defined in the PBS file pokemon.txt
#	 You may want to use this method to generate a whitelist with all Pokémon.
#   Arguments: 
#	 none
#   return value:
#	 A list of Integers that represent the dex number of all Pokémon.
#
# filterUnevolved(pokemonList)
#   Summary:
#	 Returns a list of all unevolved Pokeémon in pokemonList.
#   Arguments:
#	 pokemonList:
#	   An array of Integer or PBSpecies
#	   An array of Pokémon. This is the array to be filtered.
#   return value:
#	 A list of Integers that represent the dex number of the unevolved Pokémon.
#
# filterType(pokemonList, type1, type2)
#   Summary:
#	 Returns a list of all Pokémon in pokemonList of the given type(s).
#   Arguments:
#	 pokemonList:
#	   An array of Integer or PBSpecies
#	   An array of Pokémon. This is the array to be filtered.
#	 type1:
#	   PBTypes
#	   The type to filter for.
#	 type2:
#	   PBTypes, nil or false
#		 When a type is given only Pokémon with the two given types are returned.
#		 When nil is given any Pokémon with type1 as type are returned.
#		 When false is fiven only Pokémon that are only type1 are returned.
#   return value:
#	 An array of Integers that represent the dex number of the Pokémon of the
#	 given type(s).
#
# getAllPossibleMoves(pokemon)
#   Summary:
#	 This method returns a list of the ids of all natural and tm moves the
#	 Pokémon can learn without taking level into account.
#   Arguments:
#	 pokemon:
#	   PokeBattle_Pokemon
#	   The Pokémon in question.
#   return value:
#	 An array of Integers representing the ids of all moves that can be learned
#	 by the Pokémon.
#
#=============================================================
 
def getRandomPokemon(whitelist = nil, blacklist = nil, level = nil, 
	  movewhitelist = nil, moveblacklist = nil)
  randomMoves = true
  if movewhitelist == false
	randomMoves = false
  end
  #make sure whitelist and blacklist are in the right format
  if whitelist.is_a?(Array)
	for i in 0 ... whitelist.length
	  if whitelist[i].is_a?(String) || whitelist[i].is_a?(Symbol)
		whitelist[i]=getID(PBSpecies,whitelist[i])
	  end
	  if whitelist[i].is_a?(Integer)
		const = getConstantName(PBSpecies,whitelist[i]) rescue whitelist[i] = nil
		if !hasConst?(PBSpecies,const) #the pokemon doesn't exist
		  whitelist[i] = nil
		end
	  else
		whitelist[i] = nil
	  end
	end
	whitelist.compact!
	if whitelist.length == 0
	  return nil #empty whitelist
	end
  else
	whitelist = nil
  end
  
  if !whitelist #no whitelist => choose from all pokemon
	whitelist = getAllPokemonList
  end 
  
  if blacklist.is_a?(Array)
	for i in 0 ... blacklist.length
	  if blacklist[i].is_a?(String) || blacklist[i].is_a?(Symbol)
		blacklist[i]=getID(PBSpecies,blacklist[i])
	  end
	  if blacklist[i].is_a?(Integer)
		const = getConstantName(PBSpecies,blacklist[i]) rescue blacklist[i] = nil
		if !hasConst?(PBSpecies,const) #the pokemon doesn't exist
		  blacklist[i] = nil
		end
	  else
		blacklist[i] = nil
	  end
	end
	blacklist.uniq! #remove all duplicates
	blacklist.compact!
	if blacklist.length == 0
	  blacklist = nil
	end
  else
	blacklist = nil
  end
  
  #sort blacklist out of whitelist
  if blacklist
	for i in 0 ... whitelist.length
	  if blacklist.include?(whitelist[i])
		whitelist[i] = nil
	  end
	end
	whitelist.compact!
	if whitelist.length == 0
	  return nil #all pkmn of whitelist are in blacklist
	end
  end
	 
  id = nil
  #choose pokemon species
  randNum = rand(whitelist.length-1)
  id = whitelist[randNum]
  
  
  #choose level if none is given
  if !(level && level.is_a?(Integer))
	level = rand(99) + 1
  end
  #create a pokemon with player as trainer and without moves
  pokemon=PokeBattle_Pokemon.new(id,level,$Trainer,false)
  
  #randomize moves(all natural and tm moves)
  if randomMoves
	#format move whitelist
	if movewhitelist && movewhitelist.is_a?(Array)
	  for i in 0 ... movewhitelist.length
		if movewhitelist[i].is_a?(String) || movewhitelist[i].is_a?(Symbol)
		  movewhitelist[i]=getID(PBMoves,movewhitelist[i])
		end
		if whitelist[i].is_a?(Integer)
		  const = getConstantName(PBMoves,movewhitelist[i]) rescue movewhitelist[i] = nil
		  if !hasConst?(PBMoves,const) #the pokemon doesn't exist
			movewhitelist[i] = nil
		  end
		else
		  movewhitelist[i] = nil
		end
	  end
	  movewhitelist.compact!
	else
	  movewhitelist = nil
	end
  
	#format move blacklist
	if moveblacklist && moveblacklist.is_a?(Array)
	  for i in 0 ... moveblacklist.length
		if moveblacklist[i].is_a?(String) || moveblacklist[i].is_a?(Symbol)
		  moveblacklist[i]=getID(PBMoves,moveblacklist[i])
		end
		if moveblacklist[i].is_a?(Integer)
		  const = getConstantName(PBMoves,moveblacklist[i]) rescue moveblacklist[i] = nil
		  if !hasConst?(PBMoves,const) #the pokemon doesn't exist
			moveblacklist[i] = nil
		  end
		else
		  moveblacklist[i] = nil
		end
	  end
	  moveblacklist.compact!
	else
	  moveblacklist = nil
	end
  
	#if there is no whitelist make all learnable attacks the whitelist
	if !movewhitelist
	  movewhitelist = getAllPossibleMoves(pokemon)
	end
	
	#sort out blacklist moves of whitelist
	if moveblacklist && movewhitelist
	  for i in 0 ... movewhitelist.length
		if moveblacklist.includes?(movewhitelist[i])
		  movewhitelist[i] = nil
		end
	  end
	  movewhitelist.compact!
	end
	pokemon.moves = [] #delete all moves
  
	4.times do
	  if movewhitelist.length == 0
		break
	  end
	  randNum = rand(movewhitelist.length-1)
	  pokemon.moves.push(PBMove.new(movewhitelist[randNum]))
	  movewhitelist.delete_at(randNum)
	end
  else #pokemon learns the moves it would naturally have on this level
	pokemon.resetMoves
  end
  
  return pokemon
end
 
def getAllPossibleMoves(pokemon)
  moves=[] #all learnable moves
  pbEachNaturalMove(pokemon){|move,level|
	 moves.push(move) if !moves.include?(move)
  }
  data = load_data("Data/tm.dat")
  for i in 0 ... data.length
	if pokemon.isCompatibleWithMove?(i)
	  moves.push(i) if !moves.include?(i)
	end
  end
  return moves
end
 
def addPokemon(pokemon)
  if pbBoxesFull?
	Kernel.pbMessage(_INTL("There's no more room for Pokémon!\1"))
	Kernel.pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
	return false
  end
  speciesname=PBSpecies.getName(pokemon.species)
  Kernel.pbMessage(_INTL("{1} obtained {2}!\\se[PokemonGet]\1",$Trainer.name,speciesname))
  pbNicknameAndStore(pokemon)
  pbSeenForm(pokemon)
end
  
#returns only the unevolved pokemon in the list
def filterUnevolved(pokemonList)
  #break if wrong input
  if !(pokemonList && pokemonList.is_a?(Array))
	return
  end
  
  for i in 0 ... pokemonList.length
	#make sure everything is formatted the right way
	if pokemonList[i].is_a?(String) || pokemonList[i].is_a?(Symbol)
	  pokemonList[i]=getID(PBSpecies,pokemonList[i])
	end
	if pokemonList[i].is_a?(Integer)
	  const = getConstantName(PBSpecies,pokemonList[i]) rescue pokemonList[i] = nil
	  if !hasConst?(PBSpecies,const) #the pokemon doesn't exist
		pokemonList[i] = nil
	  end
	  #check if pokemon has a prevolution
	  if pokemonList[i] != pbGetPreviousForm(pokemonList[i])
		pokemonList[i] = nil
	  end
	else
	  pokemonList[i] = nil
	end
  end
  pokemonList.compact!
  return pokemonList
end
  
def filterType(pokemonList, type1, type2=nil)
  #break if wrong input
  if !(pokemonList && pokemonList.is_a?(Array))
	return
  end
  
  dexdata=pbOpenDexData
  
  for i in 0 ... pokemonList.length
	#make sure everything is formatted the right way
	if pokemonList[i].is_a?(String) || pokemonList[i].is_a?(Symbol)
	  pokemonList[i]=getID(PBSpecies,pokemonList[i])
	end
	if pokemonList[i].is_a?(Integer)
	  const = getConstantName(PBSpecies,pokemonList[i]) rescue pokemonList[i] = nil
	  if !hasConst?(PBSpecies,const) #the pokemon doesn't exist
		pokemonList[i] = nil
	  end
	  #check if pokemon has the requested types
	  pbDexDataOffset(dexdata,pokemonList[i],8)
	  ptype1=dexdata.fgetb
	  pbDexDataOffset(dexdata,pokemonList[i],9)
	  ptype2=dexdata.fgetb
	  if !(type1==ptype1||type1==ptype2)
		pokemonList[i] = nil
		next
	  elsif type2 && !(type2==ptype1||type2==ptype2)
		pokemonList[i] = nil
		next
	  elsif (type2 == false) && (ptype1 != ptype2)
		pokemonList[i] = nil
		next
	  end
	else
	  pokemonList[i] = nil
	end
  end
  pokemonList.compact!
  dexdata.close
  return pokemonList
end
 
def getAllPokemonList
  pokemonList = []
  for i in 0..PBSpecies.maxValue
	for c in PBSpecies.constants
	  if PBSpecies.const_get(c.to_sym)==i
		pokemonList.push(i)
	  end
	end
  end
  return pokemonList
end
Credits
leilou

Pokémon Essentials:
Pokémon Essentials is created by Poccil, based on Flameguru's Pokémon Starter Kit and managed and updated by Maruno
  • Like
Reactions: Marina and xUMG
Author
aiyinsi
Downloads
1,012
Views
2,472
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from aiyinsi

Back
Top