Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Reload this Page [Essentials script] Pokémon Selection (similar to Stadium/Battle Tower)

Notices
For all updates, view the main page.

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.



Reply
 
Thread Tools
  #1    
Old October 31st, 2012 (04:25 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,482
Code:
#===============================================================================
# * 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
Attached Thumbnails
pokemonselectionscreen.png‎  
__________________
Reply With Quote
  #2    
Old October 31st, 2012 (07:15 PM).
UpliftKnight UpliftKnight is offline
 
Join Date: Oct 2012
Posts: 14
Thanks FL. its going to be useful for me.
Reply With Quote
  #3    
Old November 1st, 2012 (10:35 AM).
ppooookkkkkkk ppooookkkkkkk is offline
Banned
 
Join Date: May 2012
Location: Newbud town (Pokemon Morning/Night)
Age: 14
Gender: Male
Nature: Gentle
Posts: 229
Thank you for this (finally a great script for making the frontier)
Reply With Quote
  #4    
Old November 10th, 2012 (02:06 PM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,482
I'm glad that people will use this, despite the big instructions.
__________________
Reply With Quote
  #5    
Old November 21st, 2012 (04:43 AM).
UpliftKnight UpliftKnight is offline
 
Join Date: Oct 2012
Posts: 14
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.
Reply With Quote
  #6    
Old November 21st, 2012 (05:04 AM).
IceGod64's Avatar
IceGod64 IceGod64 is offline
My imagination.
 
Join Date: Oct 2008
Location: Castelia City
Age: 27
Gender: Male
Nature: Naive
Posts: 604
Quote originally posted by UpliftKnight:
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:

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

Reply With Quote
  #7    
Old November 21st, 2012 (05:56 AM).
UpliftKnight UpliftKnight is offline
 
Join Date: Oct 2012
Posts: 14
Quote originally posted by IceGod64:
Follow the instructions. Notice n the first post:
I used the script command but still goes to the battle
Reply With Quote
  #8    
Old November 24th, 2012 (11:36 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,482
Quote originally posted by UpliftKnight:
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.
Code:
PokemonSelection.choose(3,3)
pbTrainerBattle(
  PBTrainers::YOUNGSTER,"Ben",
  _I("\bAww, I lost."))
PokemonSelection.restore
__________________
Reply With Quote
  #9    
Old December 1st, 2013 (12:51 PM).
Nickalooose Nickalooose is offline
--------------------
 
Join Date: Mar 2008
Gender: Female
Posts: 1,161
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.
Reply With Quote
  #10    
Old January 2nd, 2014 (10:36 AM).
dydd90's Avatar
dydd90 dydd90 is offline
 
Join Date: Dec 2013
Location: Italy
Gender: Male
Posts: 181
Thank you very much i like this and i will use it
__________________
Reply With Quote
  #11    
Old October 3rd, 2014 (05:31 AM).
RyanReffell RyanReffell is offline
 
Join Date: May 2013
Gender: Male
Posts: 8
Little help with this...
Tried to follow instructions here but I'm getting a
'PokemonSelection' Line60yntaxError

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???
Reply With Quote
  #12    
Old October 4th, 2014 (07:57 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,482
Quote originally posted by RyanReffell:
Little help with this...
Tried to follow instructions here but I'm getting a
'PokemonSelection' Line60yntaxError

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. How to solve this:
Quote originally posted by mej71:
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

Code:
# 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.
__________________
Reply With Quote
  #13    
Old October 4th, 2014 (11:15 AM).
RyanReffell RyanReffell is offline
 
Join Date: May 2013
Gender: Male
Posts: 8
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
Reply With Quote
  #14    
Old October 8th, 2014 (04:34 PM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Posts: 1,482
Quote originally posted by RyanReffell:
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
Code:
PokemonSelection.choose(3,3)
pbTrainerBattle(
  PBTrainers::YOUNGSTER,"Ben",
  _I("\bAww, I lost."))
PokemonSelection.restore
Use extendtext.exe or, probably, the small script command window will mess the text.
__________________
Reply With Quote
Reply
Quick Reply

Sponsored Links

You may also like.. (Beta)
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are UTC -8. The time now is 03:14 AM.