PDA

View Full Version : [Essentials script] Pokémon Selection (similar to Stadium/Battle Tower)


FL
October 31st, 2012, 04:25 AM
#===============================================================================
# * Pokémon Selection - by FL (Credits will be apreciated)
#===============================================================================
#
# This script is for Pokémon Essentials. It makes a pokémon selection system
# similar to Stadium/Battle Tower, where you can choose a certain number and
# order of pokémon.
#
#===============================================================================
#
# To this script works, put it above main and use in script command
# 'PokemonSelection.choose(min, max, canCancel, acceptFainted)' where min and
# max are the minimum and maximum pokémon number selection (default values are
# 1 and 6), canCancel when true the player can cancel the selection (default
# is false) and acceptFainted that when true the player can choose fainted
# pokémon and eggs (default is false). This method return if a party is choosen.
#
# To restore the previous party, use 'PokemonSelection.restore'. This do nothing
# is there's no party to restore. Ths method returns if the party is restored.
#
# Between the two commands, don't allow the player to caught or deposit/withdraw
# any pokémon or the pokémon will be lost! However, you pokémon can gain
# exp/level, evolve, change hold item/moves normally. If you try to choose a
# new party before restore the old one, the game raises an error. This won't
# occurs if the previous selection is only an order change. ONLY in Debug mode
# you get the phrase "Generate Pokemon teams for this challenge?", always
# choose "No".
#
# 'PokemonSelection.hasValidTeam?(min, max, canCancel, acceptFainted)' returns
# if your team is valid. If you try to use a invalid team (like putting the
# minimum pokémon number as 3, but only having 2 pokémon), the selection is
# treats as canceled. If the canCancel=false, the game goes in an infinite loop.
#
# Example: To make a 3vs3 battle, use 'PokemonSelection.choose(3,3)' and, after
# the battle (regardless of result) use 'PokemonSelection.restore'. Only allows
# the player to go in the battle if 'PokemonSelection.hasValidTeam?(3,3)' is
# true, or set the minimum as 1.
#
# To perform only an order change, use
# 'PokemonSelection.choose($Trainer,party.size,$Trainer,party.size,true,true)'.
#
# If you take a look in PokemonChallengeRules applications in scripts you can
# customize some others choice conditions like have a certain level or ban
# certain pokémon.
#
#===============================================================================

module PokemonSelection
def self.rules(min=1, max=6, canCancel=false, acceptFainted=false)
ret=PokemonChallengeRules.new
ret.setLevelAdjustment(OpenLevelAdjustment.new(PBExperience::MAXLEVEL))
ret.addPokemonRule(AblePokemonRestriction.new) if !acceptFainted
ret.ruleset.setNumberRange(min,max)
return ret
end

def self.hasValidTeam?(min=1, max=6, canCancel=false, acceptFainted=false)
pbBattleChallenge.set("pokemonSelectionRules",7,self.rules(min,max))
ret=pbHasEligible?
pbBattleChallenge.pbCancel
return ret
end

def self.choose(min=1, max=6, canCancel=false, acceptFainted=false)
if $PokemonGlobal.pokemonSelectionOriginalParty
raise "Can't choose a new party until restore the old one"
end
validPartyChosen=false
pbBattleChallenge.set("pokemonSelectionRules",7,self.rules(min,max))
loop do
pbEntryScreen
validPartyChosen=(pbBattleChallenge.getParty!=nil)
break if(canCancel || validPartyChosen)
Kernel.pbMessage(_INTL("Choose a Pokémon."))
end
if validPartyChosen
# If the party size is the same, it is only an order change
if($Trainer.party.size != pbBattleChallenge.getParty.size)
$PokemonGlobal.pokemonSelectionOriginalParty=$Trainer.party
end
$Trainer.party=pbBattleChallenge.getParty
end
pbBattleChallenge.pbCancel
return validPartyChosen
end

def self.restore(*args)
hasSavedTeam=($PokemonGlobal.pokemonSelectionOriginalParty!=nil)
if hasSavedTeam
$Trainer.party=$PokemonGlobal.pokemonSelectionOriginalParty
$PokemonGlobal.pokemonSelectionOriginalParty=nil
end
return hasSavedTeam
end
end

class PokemonRuleSet # Redefined to fix a bug
def hasValidTeam?(team)
if !team || team.length<self.minTeamLength
return false
end
teamNumber=[self.maxLength,team.length].min
validPokemon=[]
for pokemon in team
if isPokemonValid?(pokemon)
validPokemon.push(pokemon)
end
end
#if validPokemon.length<teamNumber # original
if validPokemon.length<self.minLength # fixed
return false
end
if @teamRules.length>0
pbEachCombination(team,teamNumber){|comb|
if isValid?(comb)
return true
end
}
return false
end
return true
end
end

class BattleChallenge; def getParty; return @bc.party; end; end

class PokemonGlobalMetadata; attr_accessor :pokemonSelectionOriginalParty; end

UpliftKnight
October 31st, 2012, 07:15 PM
Thanks FL. its going to be useful for me.

ppooookkkkkkk
November 1st, 2012, 10:35 AM
Thank you for this (finally a great script for making the frontier)

FL
November 10th, 2012, 02:06 PM
I'm glad that people will use this, despite the big instructions.

UpliftKnight
November 21st, 2012, 04:43 AM
I tried to use this but when i try this script it directly goes in battle without selection.
Can you write a example script? with battle.

IceGod64
November 21st, 2012, 05:04 AM
I tried to use this but when i try this script it directly goes in battle without selection.
Can you write a example script? with battle.

Follow the instructions. Notice n the first post:

# To this script works, put it above main and use in script command # 'PokemonSelection.choose(min, max, canCancel, acceptFainted)'

UpliftKnight
November 21st, 2012, 05:56 AM
Follow the instructions. Notice n the first post:

I used the script command but still goes to the battle

FL
November 24th, 2012, 11:36 AM
I tried to use this but when i try this script it directly goes in battle without selection.
Can you write a example script? with battle.PokemonSelection.choose(3,3)
pbTrainerBattle(
PBTrainers::YOUNGSTER,"Ben",
_I("\bAww, I lost."))
PokemonSelection.restore

Nickalooose
December 1st, 2013, 12:51 PM
Wow, FL . nice script... However, It's always nice to see one of my features become less of a unique feature though lol.

It's great to see you're still giving to the community too.

dydd90
January 2nd, 2014, 10:36 AM
Thank you very much i like this and i will use it :)

RyanReffell
October 3rd, 2014, 05:31 AM
Little help with this...
Tried to follow instructions here but I'm getting a
'PokemonSelection' Line60:SyntaxError

I'm trying to set it up so that you can enter a 'Fighting Type' only contest, and I have put in all the species allowed to compete and placed it above Main in the scripts sections,
ADVICE PLEASE???

FL
October 4th, 2014, 07:57 AM
Little help with this...
Tried to follow instructions here but I'm getting a
'PokemonSelection' Line60:SyntaxError

I'm trying to set it up so that you can enter a 'Fighting Type' only contest, and I have put in all the species allowed to compete and placed it above Main in the scripts sections,
ADVICE PLEASE???Pokécommunity is breaking my scripts (http://www.pokecommunity.com/showthread.php?t=333023). How to solve this:
Click Thread Tools, and then Show Printable Version, and copy that instead.Or use the thread print url: http://www.pokecommunity.com/printthread.php?t=290931




How to limit selection by pokémon type

# This class uses a type array that only allows the pokémon as valid if it
# has one of these types when bannedTypes=false or the reverse
# when bannedTypes=true
class TypeRestriction
def initialize(types, bannedTypes=true)
@types=types
@bannedTypes = bannedTypes
end

def isValid?(pokemon)
ret=false
for singleType in @types
if pokemon.hasType?(singleType)
ret = true
break
end
end
ret = !ret if @bannedTypes
return ret
end
end

Copy this code after my script last line. After line 'ret.ruleset.setNumberRange(min,max)' add 'ret.addPokemonRule(TypeRestriction.new([:FIGHTING],false))'.

If you, instead of adding 'TypeRestriction.new([:FIGHTING],false))', you add 'TypeRestriction.new([:FIRE,:ICE],false))', only Fire and Ice pokémon would be allowed. If the call is 'TypeRestriction.new([:DRAGON,:FLYING],true))', Flying and Dragon pokémon will be banned.

RyanReffell
October 4th, 2014, 11:15 AM
Ah that's got rid of the error nicely! Thanks.
What script exactly would I need to use to open the battle now?

Tried the one suggested near the start of the thread but that's giving me a large error now in game

FL
October 8th, 2014, 04:34 PM
Ah that's got rid of the error nicely! Thanks.
What script exactly would I need to use to open the battle now?

Tried the one suggested near the start of the thread but that's giving me a large error now in gamePokemonSelection.choose(3,3)
pbTrainerBattle(
PBTrainers::YOUNGSTER,"Ben",
_I("\bAww, I lost."))
PokemonSelection.restoreUse extendtext.exe or, probably, the small script command window will mess the text.